// Entry point of the "this site has moved" page (see index.html). // // The Reachy Mini website now lives at pollen-robotics.com. This Space no // longer renders the old site: whatever route or hash a visitor arrives // with, they get the single moved page from index.html, and this script // points its button at the matching page of the new site. // // The former React site is gone from this repo. The Express API in server/ // is untouched: other clients (desktop app, pollen-robotics.com, ...) still // call it on this Space's host. const NEW_SITE_ORIGIN = 'https://pollen-robotics.com'; const HOME = { path: '/reachy-mini/', label: 'Go to the new site' }; // First path segment of the old route -> matching page on the new site. // Anything not listed here goes to the new home page. const PAGES = new Map([ ['getting-started', { path: '/reachy-mini/getting-started/', label: 'Continue to Getting started' }], ['download', { path: '/reachy-mini/download/', label: 'Continue to Download' }], ['apps', { path: '/reachy-mini/apps/', label: 'Continue to Apps' }], // Shortcut that redirects to the store. The store refuses to be framed, // so it must only ever be opened as a top-level page. ['buy', { path: '/reachy-mini/buy/', label: 'Continue to the store' }], ]); // "#/Download?scrollTo=release-notes", "#download", "/download/" -> "download" function firstSegment(value) { const match = /^[#/]*([^/?#&]*)/.exec(value || ''); return match ? match[1].toLowerCase() : ''; } /** * Pick the page of the new site that matches where the visitor wanted to go. * * huggingface.co forwards the hash of the Space page URL to this frame * (huggingface.co/spaces/...#/getting-started), so the hash comes first. * The path covers direct links such as *.hf.space/download. */ function resolveDestination({ hash, pathname }) { const page = PAGES.get(firstSegment(hash)) || PAGES.get(firstSegment(pathname)) || HOME; const url = NEW_SITE_ORIGIN + page.path; return { url, label: page.label, // Readable form shown under the button: no scheme, no trailing slash. display: url.replace(/^https?:\/\//, '').replace(/\/$/, ''), }; } function isFramed() { try { return window.self !== window.top; } catch { // Reading window.top can throw in some sandboxes: only a frame gets there. return true; } } function render() { const destination = resolveDestination(window.location); // On huggingface.co this page runs in a sandboxed iframe that is not // allowed to navigate the browser tab (no `allow-top-navigation`), so the // link has to open a new tab. Do not switch it to `_top`: Chrome silently // ignores such a link inside the Space frame. const link = document.getElementById('moved-link'); if (link) link.href = destination.url; const label = document.getElementById('moved-label'); if (label) label.textContent = destination.label; const display = document.getElementById('moved-destination'); if (display) display.textContent = destination.display; return destination; } const destination = render(); window.addEventListener('hashchange', render); // Opened directly (*.hf.space in its own tab): nothing stops us from // navigating, so go straight to the new site. The page stays visible as // the fallback. Add `?noredirect` to the URL to look at the page itself. const stay = new URLSearchParams(window.location.search).has('noredirect'); if (!isFramed() && !stay) { window.location.replace(destination.url); }