Skip to content

feat: add $build.trailingSlash option - #87

Merged
lukeed merged 6 commits into
mainfrom
feat/trailing-slash
Oct 26, 2026
Merged

lukeed merged 6 commits into
mainfrom
feat/trailing-slash

Conversation

@lukeed

@lukeed lukeed commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Some sites want page URLs without a trailing slash. With $build.trailingSlash: false, each page is an .html file of its path, so hosts serve it at that URL.

Changes

  • $build.trailingSlash, true by default, so existing sites do not change. With false:

    File URL path Output
    content/index.md / public/index.html
    content/about.md /about public/about.html
    content/blog/index.md /blog public/blog.html
    content/blog/post.md /blog/post public/blog/post.html

    A custom url: /people/ drops its slash and writes people.html. url: /404.html still writes that file. $page.path, $page.url, $pages, sitemaps, and feeds follow.

  • Dev redirects, both ways. A page URL with the other trailing slash gets a 302 to the path of its file, with its query. The server picks the redirect from the file that exists, so it needs no config. Before, dev served /a from a/index.html with no redirect, so relative URLs resolved differently than on a host.

  • Fix: Markdown copies of dotted paths. /releases/v1.1.0 gave v1.1.md; it now gives v1.1.0.md. withExtension replaces only an .html extension.

  • Fix: client links to dotted pages. The client took /v1.1.0 for a file and left the link to the browser. An extension now counts as a file type only when it has a letter.

  • Docs: "Without trailing slashes" in Content, with the Firebase settings and how relative URLs resolve; "Trailing slashes" in Dev server.

Test plan

  • bun run build, bun test, bunx tsc -p ., bunx tsc -p build, bun docs build
  • New tests fail without the change: the flat build, both dev redirects with a query and under a subfolder, url.ext of a dotted path, and the client check of a dotted path
  • By hand, the docs site with trailingSlash: false: every page is a flat file, canonical URLs and llms.txt links have no slash, both redirects work, and client navigation stays in one document, back included, with no failed request
  • By hand, the docs site as it is: /config redirects to /config/, and Markdown copies load

Some hosts and sites want page URLs without a trailing slash. With
$build.trailingSlash: false, each page is an .html file of its path.
Dev served /a from a/index.html with no redirect, so relative URLs
resolved differently than on a host. A request with the other trailing
slash now redirects to the path of the page file.
A page path with no trailing slash, such as /releases/v1.1.0, lost its
last dot part in its Markdown copy: v1.1.md.
The client took /v1.1.0 for a file, and left the link to the browser.
Resolves the $build conflicts with outdir: both options stay, in the
types and in the config docs.
@lukeed
lukeed merged commit 95d35c4 into main Oct 26, 2026
4 checks passed
@lukeed
lukeed deleted the feat/trailing-slash branch October 26, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant