feat: add prettyUrls option for clean directory URLs#499
Open
knoan wants to merge 1 commit intohonkit:masterfrom
Open
feat: add prettyUrls option for clean directory URLs#499knoan wants to merge 1 commit intohonkit:masterfrom
knoan wants to merge 1 commit intohonkit:masterfrom
Conversation
…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>
457293f to
01414c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prettyUrlsconfig option (book.json) that strips.htmlextensions from generated links, enabling clean URLs (e.g.,href="guide"instead ofhref="guide.html") for static hosting like GitHub Pagespage.html— only the URLs in links are affected. GitHub Pages natively servespage.htmlwhen/pageis requested, so no directory rewriting is neededoutput— because the legacy plugin API (decodeConfig) reserves and deletesvalues.outputfor deprecated output folder path compatibilityHow it works
Two URL rewriting rules in
fileToURL.ts, applied in order:directoryIndex(existing) —README.md→index.html→./andsubdir/README.md→subdir/index.html→subdir/. This rule is unchanged and fires first for anyindex.htmloutputprettyUrls(new) — all other.htmlURLs get the extension stripped:page.html→page,subdir/page.html→subdir/pageOutput files are unaffected —
fileToOutput.tsstill producespage.html. Only the link URLs in generated HTML change.URL mapping
prettyUrlsURLREADME.mdindex.html././(unchanged)page.mdpage.htmlpage.htmlpagesubdir/README.mdsubdir/index.htmlsubdir/subdir/(unchanged)subdir/page.mdsubdir/page.htmlsubdir/page.htmlsubdir/pageUsage
{ "prettyUrls": true }Test plan
fileToOutput(8 tests) — output filenames unchanged in both modesfileToURL(8 tests) — default mode produces.htmlURLs, prettyUrls mode produces extensionless URLs;directoryIndexconversion preserved in both modesprettyUrls: true, verifiesguide.htmlexists and links containhref="guide"(nothref="guide.html")Closes #496
🤖 Generated with Claude Code