Introducing a new way to review your PRs.

Read the announcement

calicastle / cali.so

Personal website for Cali Castle

View on GitHub

21 documents · Updated Sep 21, 2026

docs / localization-navigation-and-discovery

Localization, navigation, and discovery

The public site presents the same content in Chinese and English while keeping each language on a clear, stable URL. Its route helpers, shared navigation, page metadata, feeds, sitemap, robots policy, and link preview services work together so people can move through the site and search engines can find the right public pages.

Locale model

Locale-aware routes

The site uses Chinese as the default locale and English as an explicit /en route prefix. A route such as /blog/example therefore has an English counterpart at /en/blog/example. The route model treats the path as the source of truth for public pages. It preserves query strings and fragments when a user changes language, and it rejects unsafe path forms before building a local destination (lib/locale-route.ts• L1-86).

The same unprefixed content path maps to both sides of a locale pair. This lets page links, metadata, feeds, and the sitemap refer to one shared content identity while still sending visitors to language-specific pages.

flowchart LR
  Path[Public path] --> Detect{English prefix?}
  Detect -->|No| Zh[Chinese route]
  Detect -->|Yes| En[English route]
  Zh --> Pair[Locale route pair]
  En --> Pair
  Pair --> Links[Localized links and metadata]

References: lib/locale-route.ts• L1-86 lib/locale-metadata.ts• L26-39

Locale selection

The public URL selects the active language for each page. Shared controls use that locale to render labels and to build links for the current content path. The navigation dock and footer both keep users inside the same language while linking to the main site sections (lib/locale-client.ts• L11-32, components/dock.tsx• L173-239, components/site-footer.tsx• L76-109).

The site can suggest a different language after it compares the browser language list with the current route. A user can accept the suggestion or stay on the current language. The choice is remembered in browser storage, but public routes do not silently change from that preference; the user must choose the switch. The preference also supports the isolated admin surface, where an in-place language change is allowed (components/locale-suggestion.tsx• L41-99, components/locale-restorer.tsx• L7-31).

References: lib/locale-client.ts• L13-32 components/locale-suggestion.tsx• L62-99 components/locale-restorer.tsx• L7-31

Public site navigation

The public navigation provides stable entry points to Home, Writing, Photos, Projects, and AMA. The dock marks the active section from the unlocalized route, so its state remains correct for both /blog and /en/blog. Home cards and the footer use the same route mapping, which keeps links language-aware instead of mixing Chinese and English destinations (components/dock.tsx• L176-239, components/nav-cards.tsx• L10-45, components/site-footer.tsx• L76-109).

Article links add a visual route transition when a normal primary-pointer click moves from a post list to a post. Modified clicks, keyboard activation, and unsupported transition cases keep normal browser navigation. This makes the effect a presentation layer rather than a requirement for reaching the page (components/post-transition-link.tsx• L21-57).

References: components/dock.tsx• L176-239 components/nav-cards.tsx• L10-45 components/site-footer.tsx• L76-109 components/post-transition-link.tsx• L21-57

Links written in public content are split into two paths. Relative links are localized to the current page. External links stay external and open in a new tab with a safe referrer policy. This keeps content navigation in the selected language without changing the meaning of third-party URLs (components/…/mdx-components.tsx• L59-75, components/external-link.tsx• L46-60).

References: components/…/mdx-components.tsx• L59-75 components/external-link.tsx• L46-60

Page metadata

Canonical locale pairs

Each public page describes its Chinese and English versions as one alternate pair. The page declares its own canonical URL, then exposes zh-CN, en, and x-default alternates. Search engines can therefore connect the two language pages instead of treating them as unrelated copies (lib/locale-metadata.ts• L26-39, lib/locale-metadata.ts• L42-87).

Titles, descriptions, Open Graph data, and Twitter card data use the copy for the active locale. Social images also carry the locale and the page path, so a shared link can produce a preview in the language of its target (lib/locale-metadata.ts• L18-23, lib/locale-metadata.ts• L49-86, app/…/page.tsx• L5-15, app/…/page.tsx• L5-15).

References: lib/locale-metadata.ts• L18-23 lib/locale-metadata.ts• L26-87 app/…/page.tsx• L5-15 app/…/page.tsx• L5-15

Social image routes

The /og route turns a valid locale and public content path into a cached social image. It supports the home page, public section pages, published posts, archived newsletters, and Cali Baby pages. Unknown paths or invalid locale values return no image rather than creating metadata for an unrecognized public route (app/…/route.ts• L16-26, app/…/route.ts• L36-72).

References: app/…/route.ts• L16-26 app/…/route.ts• L28-72 lib/locale-metadata.ts• L18-23

Discovery surfaces

RSS feeds

The site publishes one RSS feed per language. /feed.xml lists Chinese post URLs, while /feed.en.xml lists the English post URLs under /en/blog. Both feeds use the published post set and include titles, descriptions, dates, and cover images when available. The feed output is cached because content comes from the repository and changes with deployment (lib/feeds.ts• L6-62, app/…/route.ts• L5-17, app/…/route.ts• L5-15).

References: lib/feeds.ts• L6-62 app/…/route.ts• L5-17 app/…/route.ts• L5-15

Sitemap

The sitemap is the search-engine index of public content. It emits both members of every locale pair for the home page, section pages, the published post list, and archived newsletters. Each entry carries the same language alternates as page metadata. Cali Baby support, privacy, and terms pages remain public but are not included in this site sitemap (app/sitemap.ts• L7-31).

References: app/sitemap.ts• L7-31 lib/locale-metadata.ts• L26-39

Robots policy

The robots route allows crawling of the public site and points crawlers to /sitemap.xml. It blocks admin pages and APIs, confirmation links, and AMA management links. These paths may contain owner controls, action tokens, or private capability URLs, so they are not search destinations (app/robots.ts• L5-22).

References: app/robots.ts• L5-22

Machine-readable site index

The /llms.txt route provides a compact Markdown index for machine readers. It links to both language versions of the main public sections, published writing, archived newsletters, Cali Baby information, the feeds, and the sitemap. A response header advertises this document from other routes (app/…/route.ts• L31-171, app/…/route.ts• L181-184, next.config.ts• L82-90).

The discovery surfaces share the same published content and route rules. This keeps a post visible in the sitemap, feeds, and machine-readable index only when it is part of the public publication set (lib/public-content-routes.ts• L1-28).

References: app/…/route.ts• L31-171 app/…/route.ts• L181-184 next.config.ts• L82-90 lib/public-content-routes.ts• L1-28

External preview cards

External links in published writing can show a small preview card with the target domain, title, description, favicon, and optional image. The card uses a build-time snapshot, so opening a card does not wait for a third-party metadata request. If preview data or an image is missing, the link remains usable as a normal external anchor (lib/link-previews.ts• L10-40, components/external-link.tsx• L18-96).

References: lib/link-previews.ts• L10-40 components/external-link.tsx• L18-96

The snapshot is refreshed from links found in both localized post sources. Failed refreshes keep an existing entry or store only the domain, which lets content builds continue when a third-party site is unavailable (scripts/refresh-link-previews.mjs• L1-3, scripts/refresh-link-previews.mjs• L17-61).

References: scripts/refresh-link-previews.mjs• L1-3 scripts/refresh-link-previews.mjs• L17-61

Favicons and Open Graph images can be served through the first-party /link-media route. Only known origins or exact snapshot targets can use this proxy. The route accepts image responses within a size limit and caches successful media for repeat views. Missing or failed media returns a short-lived 404 so an optional preview cannot turn into a page error (lib/link-media.ts• L4-50, app/…/route.ts• L9-18, app/…/route.ts• L46-89).

References: lib/link-media.ts• L4-50 app/…/route.ts• L9-89

Public route boundaries

Published route allowlist

Public post and newsletter URLs are not accepted solely because their paths look valid. The site checks post slugs and archived newsletter IDs against an explicit publication set. A missing entry is rewritten to a 404, while the same rule feeds the sitemap and RSS generation. This keeps stale or unpublished content out of both page delivery and discovery (proxy.ts• L10-24, proxy.ts• L49-82, lib/public-content-routes.ts• L1-28).

References: lib/public-content-routes.ts• L1-28 proxy.ts• L10-24 proxy.ts• L49-82

Legacy public URLs are handled through a checked-in manifest. Preserved URLs can redirect or rewrite to their current destination, while the manifest remains the route contract for the site cutover (next.config.ts• L10-23, next.config.ts• L127-131).

References: next.config.ts• L10-23 next.config.ts• L127-131

Public and private surfaces

The public route family includes localized content and product pages. Admin routes and token-bearing flows sit outside that family. Robots rules limit crawler access to those private surfaces, while the request proxy also protects admin pages and rejects unavailable or missing content (app/robots.ts• L7-20, proxy.ts• L26-71).

References: app/robots.ts• L7-20 proxy.ts• L26-71

Change checklist

When these files or sections are changed, remember to consider these:

  • When adding or retiring a public post or newsletter, update the publication source used by the proxy, feeds, sitemap, and /llms.txt together.
  • When adding a public route, define both locale URLs and its canonical language alternates. Check whether it belongs in the sitemap and social-image route.
  • When changing a localized path, check internal MDX links, dock and footer links, locale switching, feed URLs, legacy redirects, and the robots exclusions.
  • When changing external-link metadata, keep the build-time snapshot and the allowlist for /link-media aligned.
  • When changing private or token-bearing routes, review both crawler rules and request-time route protection.

Important failure modes

TriggerConsequenceGuard
A published post slug is missing from the publication setThe page returns a 404 and the post is absent from feeds and the sitemapKeep the explicit publication set aligned with published content (lib/public-content-routes.ts• L1-28)
A locale path is built from an unsafe or malformed pathnameThe locale switch is rejected instead of creating an unsafe local URLValidate and normalize paths through the locale route helpers (lib/locale-route.ts• L14-55)
A public page has no matching alternate pairSearch engines can index the wrong language as the main pageBuild canonical and language links from one shared route pair (lib/locale-metadata.ts• L26-39)
A third-party preview or image service failsThe article link remains usable and the preview degrades or returns a short-lived 404Use snapshot data, plain anchors, and cached optional media (lib/link-previews.ts• L15-25, app/…/route.ts• L70-77)
A private capability path is left crawlableSearch engines may discover an admin or token-bearing URLKeep robots exclusions and proxy route boundaries in sync (app/robots.ts• L7-20, proxy.ts• L26-43)

Key files

FileWhy to read it
lib/locale-route.tsDefines the Chinese default path model and the /en counterpart.
lib/locale-metadata.tsConnects canonical URLs, language alternates, and social image targets.
components/dock.tsxShows how the main public navigation follows the active locale and section.
components/locale-suggestion.tsxExplains browser-language suggestions and explicit user switching.
lib/feeds.tsDefines the language-specific RSS view of published writing.
app/sitemap.tsDefines the search-engine list of public locale pairs.
app/robots.tsDefines which public and private route families crawlers may access.
app/…/route.tsDefines which public routes can receive social images.
lib/link-previews.ts and app/…/route.tsExplain the optional, cached experience for external link previews.
proxy.ts and lib/public-content-routes.tsDefine the boundary between published public URLs and missing or private routes.
Published content deliveryProvides the related view of how published content reaches public pages.