diff --git a/AGENTS.md b/AGENTS.md index 007ade9..cbefc1e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -196,8 +196,10 @@ developers, not for us. Every comment ships: keep it short, plain and true. or description too long for its image, or with a character its fonts can't draw, such as an arrow or an emoji. In dev, open an image's URL to see it. -- `pageHead` also gives each page its canonical URL, with the trailing slash - the host serves pages at, and its structured data. `robots.txt` and +- Pages prerender to flat files (`docs/installation.html`), which + Cloudflare Pages serves at `/docs/installation`, the URL every link uses; + the URL with a trailing slash redirects there. `pageHead` also gives each + page its canonical URL and its structured data. `robots.txt` and `sitemap.xml` are routes too, and the sitemap lists the home page and the current line's pages. Full URLs use `SITE_URL`: the live site, or a Cloudflare preview's own address (`site/src/lib/site.ts`). diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c5784b..25a9426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ - The docs site has a `sitemap.xml` and a `robots.txt`, and each page describes itself to search engines with structured data: the home page as the site, and each docs page as an article with its place in the docs. +- Docs pages are served at the URLs the site links to, without a trailing + slash, so following a link no longer redirects. A URL with a trailing + slash still works: it redirects to the one without. ## 0.1.0-rc.3 diff --git a/site/src/lib/shared.ts b/site/src/lib/shared.ts index 036b505..99865c0 100644 --- a/site/src/lib/shared.ts +++ b/site/src/lib/shared.ts @@ -36,12 +36,12 @@ export const SITE_URL = typeof __SITE_URL__ === "string" ? __SITE_URL__ : PRODUCTION_URL; /** - * A page's full URL, as the host serves it. Every page is prerendered to a - * folder's `index.html`, so its URL ends in a slash, and the URL without one - * redirects there. + * A page's full URL, as the host serves it: `/docs/installation`, the URL + * every link uses. The same URL with a trailing slash redirects there (see + * `vite.config.ts`). */ export function pageUrl(path: string): string { - return SITE_URL + (path.endsWith("/") ? path : `${path}/`); + return SITE_URL + path; } /** diff --git a/site/vite.config.ts b/site/vite.config.ts index ab6dd65..c889fe1 100644 --- a/site/vite.config.ts +++ b/site/vite.config.ts @@ -80,8 +80,18 @@ export default defineConfig({ fumadocsMdx(), tailwindcss(), tanstackStart({ - // Static files only: every page is prerendered to HTML at build time. - prerender: { enabled: true, crawlLinks: true }, + // Static files only: every page is prerendered to HTML at build time, + // as `docs/installation.html` rather than `docs/installation/index.html`. + // Cloudflare Pages serves the file at `/docs/installation`, the URL + // every link uses; a folder's `index.html` would redirect it to a URL + // with a trailing slash. + prerender: { + enabled: true, + crawlLinks: true, + autoSubfolderIndex: false, + // A link to a heading on another page is that page again. + filter: ({ path }) => !path.includes("#"), + }, // Routes no page links to, so the crawler doesn't find them. pages: [ ...docsPages, @@ -91,7 +101,7 @@ export default defineConfig({ { path: "/robots.txt" }, { path: "/sitemap.xml" }, // Written to `404.html` at the output's root. - { path: "/404", prerender: { autoSubfolderIndex: false } }, + { path: "/404" }, { path: HOME_IMAGE_PATH, prerender: imagePrerender }, { path: TOUCH_ICON_PATH, prerender: imagePrerender }, ],