From ea76eb1dbc0b8d9527c782bdd37543c41eff9fe8 Mon Sep 17 00:00:00 2001 From: manager Date: Tue, 13 Oct 2026 11:37:08 +0000 Subject: [PATCH] feat(ai-atlas): Story and Ladder get their own addresses /ai-atlas stays on the map; /ai-atlas/story and /ai-atlas/ladder open the Atlas on that reading, prerendered in every locale with their own canonical URL. Tabs navigate between the three pages; old #article and #ladder links land on the new pages. The guide push revalidates all three. The Terminal's frame, which passes no navigation, keeps switching in place. Co-Authored-By: Claude Opus 5.5 --- src/pages/ai-atlas.tsx | 54 ++++++++++++++++++++++++++++----- src/pages/ai-atlas/[tab].tsx | 31 +++++++++++++++++++ src/pages/api/ai-atlas/guide.ts | 8 ++++- 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/pages/ai-atlas/[tab].tsx diff --git a/src/pages/ai-atlas.tsx b/src/pages/ai-atlas.tsx index 57ea1af6..165ee181 100644 --- a/src/pages/ai-atlas.tsx +++ b/src/pages/ai-atlas.tsx @@ -1,4 +1,5 @@ import type { GetStaticProps } from 'next'; +import { useRouter } from 'next/router'; import React, { useEffect, useLayoutEffect, @@ -868,6 +869,14 @@ type ViewMode = 'environment' | 'security'; /* The header tabs: the map, and the two readings that sit beside it. */ type Tab = 'atlas' | 'article' | 'ladder'; const READING_TABS: Tab[] = ['article', 'ladder']; +/* Each reading has its own address on keepsimple.io: /ai-atlas/story and + /ai-atlas/ladder. The map stays at /ai-atlas. */ +export const TAB_SLUGS: Record = { + article: 'story', + ladder: 'ladder', +}; +export const tabPath = (tab: Tab) => + tab === 'atlas' ? '/ai-atlas' : '/ai-atlas/' + TAB_SLUGS[tab]; const readings = readingsData as Readings; function DoctrinePanel({ t }: { t: T }) { @@ -1262,6 +1271,11 @@ export function AiAtlasApp({ initialGuide = null, initialView = 'environment', initialFocus = null, + initialTab = 'atlas', + /* On keepsimple.io a tab is its own page and this navigates to it. Without + it (the Terminal's frame) the tabs switch in place and the hash holds + the tab. */ + onTabChange = null, }: any = {}) { const [data] = useState(() => initialGuide ? adaptGuide(initialGuide) : null, @@ -1272,7 +1286,7 @@ export function AiAtlasApp({ const [hoverNode, setHoverNode] = useState(null); const [linkHoverNode, setLinkHoverNode] = useState(null); const [viewMode, setViewMode] = useState(initialView); - const [tab, setTab] = useState('atlas'); + const [tab, setTab] = useState(initialTab); const tabPending = useRef(false); const changeTab = (next: Tab) => { if (next === tab || tabPending.current) return; @@ -1281,6 +1295,10 @@ export function AiAtlasApp({ stage?.classList.add('is-leaving'); setTimeout( () => { + if (onTabChange) { + onTabChange(next); + return; + } setTab(next); setFocusedNode(null); stage?.classList.remove('is-leaving'); @@ -1321,10 +1339,16 @@ export function AiAtlasApp({ const sync = () => { const hash = window.location.hash.replace(/^#/, '').toLowerCase(); if ((READING_TABS as string[]).includes(hash)) { - setTab(hash as Tab); - setFocusedNode(null); + /* An old #article / #ladder link opens the reading's own page. */ + if (onTabChange) onTabChange(hash as Tab, true); + else { + setTab(hash as Tab); + setFocusedNode(null); + } return; } + /* A reading page has no map state to restore from the hash. */ + if (onTabChange && initialTab !== 'atlas') return; setTab('atlas'); if (hash === 'security') { setViewMode('security'); @@ -1350,13 +1374,15 @@ export function AiAtlasApp({ useEffect(() => { if (typeof window === 'undefined') return; let desired = ''; - if (tab !== 'atlas') desired = '#' + tab; + if (tab !== 'atlas') desired = onTabChange ? '' : '#' + tab; else if (viewMode === 'security') desired = '#security'; else if (focusedNode) desired = '#' + focusedNode; const current = window.location.hash; if (current !== desired) { const url = window.location.pathname + window.location.search + desired; - window.history.replaceState(null, '', url); + /* Keep the router's own entry state, so Back between the tab pages + still navigates. */ + window.history.replaceState(window.history.state, '', url); } }, [tab, viewMode, focusedNode]); @@ -2182,7 +2208,16 @@ export function AiAtlasApp({ ); } -export default function AiAtlasPage({ guide }: { guide: any }) { +export default function AiAtlasPage({ + guide, + tab = 'atlas', +}: { + guide: any; + tab?: Tab; +}) { + const router = useRouter(); + const goTo = (next: Tab, replace?: boolean) => + replace ? router.replace(tabPath(next)) : router.push(tabPath(next)); /* Words pushed with the guide replace the built-in ones, SEO included. */ const words = { ...copy, ...PAGE_TEXT_DEFAULTS, ...(guide?.copy || {}) }; return ( @@ -2212,7 +2247,12 @@ export default function AiAtlasPage({ guide }: { guide: any }) { }} />
- +
); diff --git a/src/pages/ai-atlas/[tab].tsx b/src/pages/ai-atlas/[tab].tsx new file mode 100644 index 00000000..85788072 --- /dev/null +++ b/src/pages/ai-atlas/[tab].tsx @@ -0,0 +1,31 @@ +import type { GetStaticPaths, GetStaticProps } from 'next'; + +import AiAtlasPage, { + getStaticProps as atlasStaticProps, + TAB_SLUGS, +} from '../ai-atlas'; + +/* /ai-atlas/story and /ai-atlas/ladder: the Atlas page opened on one of its + readings. Same guide, same words, its own address. */ +const TAB_BY_SLUG: Record = Object.fromEntries( + Object.entries(TAB_SLUGS).map(([tab, slug]) => [slug, tab]), +); + +export const getStaticPaths: GetStaticPaths = async ({ locales = [] }) => ({ + paths: Object.values(TAB_SLUGS).flatMap(tab => + (locales.length ? locales : [undefined]).map(locale => ({ + params: { tab }, + locale, + })), + ), + fallback: false, +}); + +export const getStaticProps: GetStaticProps = async context => { + const tab = TAB_BY_SLUG[String(context.params?.tab)]; + if (!tab) return { notFound: true }; + const atlas: any = await atlasStaticProps(context); + return { ...atlas, props: { ...atlas.props, tab } }; +}; + +export default AiAtlasPage; diff --git a/src/pages/api/ai-atlas/guide.ts b/src/pages/api/ai-atlas/guide.ts index ed42e0ec..a651bc91 100644 --- a/src/pages/api/ai-atlas/guide.ts +++ b/src/pages/api/ai-atlas/guide.ts @@ -23,7 +23,13 @@ import { stripGuide } from '@lib/aiAtlas/stripGuide'; export const config = { api: { bodyParser: { sizeLimit: '1mb' } } }; -const PAGES = ['/ai-atlas', '/ru/ai-atlas', '/hy/ai-atlas']; +/* The map and its two readings (/ai-atlas/story, /ai-atlas/ladder), in + every locale: they share the pushed words. */ +const PAGES = ['', '/ru', '/hy'].flatMap(prefix => + ['/ai-atlas', '/ai-atlas/story', '/ai-atlas/ladder'].map( + path => prefix + path, + ), +); const digest = (value: string) => createHash('sha256').update(value).digest();