More things

This commit is contained in:
2026-10-01 02:29:21 +02:00
parent e1df4d3ae1
commit 13b659662e
54 changed files with 4409 additions and 911 deletions

View File

@@ -3,15 +3,21 @@
An article route is a page of the open book drawn by ArticleBookStack —
pages laid out side by side, older ones parked with their spines showing —
while the article edit page and the new-article page remain plain,
full-height pages. An article lives at /wiki/<slug>; one of its language
versions at /wiki/<lang>/<slug>, e.g. /wiki/fr/bayes-theorem. */
full-height pages. Every language version of an article has an address of
its own — /wiki/<lang>/<identity>, English no different from the rest, so
/wiki/en/bayes-theorem and /wiki/fr/bayes-theorem sit side by side. The one
short form, /wiki/<slug> (what a wiki link to [[Bayes Theorem]] writes, and
what an old bookmark holds), names no language: the open-article middleware
reads which document the slug speaks and turns the address into that
version's own. */
const READER_PATH = /^\/wiki\/([^/]+?)\/?$/
const VERSION_READER_PATH = /^\/wiki\/([a-z]{2})\/([^/]+?)\/?$/
const WIKI_SUB_PATH = /^\/wiki\/[^/]+\/[^/]+/
/** What a reader address names: the article's identity, and which language
* version the address asks for (null for the article's own version). */
* version the address asks for (null for the short form, which asks for
* whichever version the slug itself speaks). */
export interface ReaderLocation {
identity: string
lang: string | null
@@ -37,12 +43,15 @@ export function wikiSlugFromPath(path: string): string | null {
}
/**
* The address of one language version: the canonical document lives at the
* article's own URL, translations at /wiki/<lang>/<identity>.
* The address one language version lives at: /wiki/<lang>/<identity>, the
* article's identity being the canonical version's slug — so every version of
* one article shares the last part of its address and differs only by the
* language in front. Documents carry their own stored slug, which no address
* needs: the wiki finds a version by (identity, language).
*/
export function versionHref(identity: string, version: { language?: string; slug: string }): string {
if (version.slug === identity) return `/wiki/${encodeURIComponent(identity)}`
return `/wiki/${encodeURIComponent(version.language ?? 'en')}/${encodeURIComponent(identity)}`
export function versionHref(identity: string, language?: string): string {
const code = language?.trim().toLowerCase() || DEFAULT_LANGUAGE
return `/wiki/${encodeURIComponent(code)}/${encodeURIComponent(identity)}`
}
/**