X Tutup
Skip to content

feat: add prettyUrls option for clean directory URLs#499

Open
knoan wants to merge 1 commit intohonkit:masterfrom
knoan:feature/496-pretty-urls
Open

feat: add prettyUrls option for clean directory URLs#499
knoan wants to merge 1 commit intohonkit:masterfrom
knoan:feature/496-pretty-urls

Conversation

@knoan
Copy link

@knoan knoan commented Feb 25, 2026

Summary

  • Add prettyUrls config option (book.json) that strips .html extensions from generated links, enabling clean URLs (e.g., href="guide" instead of href="guide.html") for static hosting like GitHub Pages
  • Output files remain as page.html — only the URLs in links are affected. GitHub Pages natively serves page.html when /page is requested, so no directory rewriting is needed
  • Root-level boolean config key — not nested under output — because the legacy plugin API (decodeConfig) reserves and deletes values.output for deprecated output folder path compatibility

How it works

Two URL rewriting rules in fileToURL.ts, applied in order:

  1. directoryIndex (existing)README.mdindex.html./ and subdir/README.mdsubdir/index.htmlsubdir/. This rule is unchanged and fires first for any index.html output
  2. prettyUrls (new) — all other .html URLs get the extension stripped: page.htmlpage, subdir/page.htmlsubdir/page

Output files are unaffected — fileToOutput.ts still produces page.html. Only the link URLs in generated HTML change.

URL mapping

Source file Output file Default URL prettyUrls URL
README.md index.html ./ ./ (unchanged)
page.md page.html page.html page
subdir/README.md subdir/index.html subdir/ subdir/ (unchanged)
subdir/page.md subdir/page.html subdir/page.html subdir/page

Usage

{
  "prettyUrls": true
}

Test plan

  • Unit tests for fileToOutput (8 tests) — output filenames unchanged in both modes
  • Unit tests for fileToURL (8 tests) — default mode produces .html URLs, prettyUrls mode produces extensionless URLs; directoryIndex conversion preserved in both modes
  • Integration snapshot test — builds a fixture book with prettyUrls: true, verifies guide.html exists and links contain href="guide" (not href="guide.html")
  • Full test suite passes (259 tests)

Closes #496

🤖 Generated with Claude Code

@knoan knoan marked this pull request as draft February 25, 2026 10:08
…it#496)

When `prettyUrls` is enabled in book.json, generated links use
extensionless URLs (e.g., href="guide" instead of href="guide.html").
Output files remain as .html — GitHub Pages natively serves page.html
when /page is requested.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@knoan knoan force-pushed the feature/496-pretty-urls branch from 457293f to 01414c2 Compare February 25, 2026 10:29
@knoan knoan marked this pull request as ready for review February 25, 2026 10:30
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.

feat: support clean URLs without .html extension

1 participant

X Tutup