Skip to content

Render default 404 pages correctly in docs - #1479

Open
AdrianDAlessandro wants to merge 2 commits into
mainfrom
render-404-docs
Open

Render default 404 pages correctly in docs#1479
AdrianDAlessandro wants to merge 2 commits into
mainfrom
render-404-docs

Conversation

@AdrianDAlessandro

Copy link
Copy Markdown
Collaborator

Description

This PR should fix the fact the 404 pages are not displaying at all now (and were not rendering properly before). It will use

It's hard to test locally, the best approach I found was to do the following (order is important!):

  1. mdbook serve -o
  2. just build-docs all_with_old
  3. Change line 7 in book/404.html to <base href="/"> (it is how it is to be compatible with the GitHub Pages deployment)
  4. Navigate to a bad path (ie http://localhost:3000/dev/bad-path/bad.html)

Fixes #1390

Type of change

  • Bug fix (non-breaking change to fix an issue)
  • New feature (non-breaking change to add functionality)
  • Refactoring (non-breaking, non-functional change to improve maintainability)
  • Optimization (non-breaking change to speed up the code)
  • Breaking change (whatever its nature)
  • Documentation (improve or add documentation)

Key checklist

  • All tests pass: $ cargo test
  • The documentation builds and looks OK: $ cargo doc
  • Update release notes for the latest release if this PR adds a new feature or fixes a bug
    present in the previous release

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.78%. Comparing base (bdc4a1a) to head (8d8f234).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1479      +/-   ##
==========================================
- Coverage   89.78%   89.78%   -0.01%     
==========================================
  Files          60       60              
  Lines        8439     8445       +6     
  Branches     8439     8445       +6     
==========================================
+ Hits         7577     7582       +5     
  Misses        545      545              
- Partials      317      318       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the documentation build “move dev docs into book/dev” step to also generate a root-level book/404.html derived from book/dev/404.html, rewriting paths so the 404 page can load its assets correctly when served from GitHub Pages project URLs (fixing #1390).

Changes:

  • Added write_root_404() to post-process book/dev/404.html into book/404.html.
  • Rewrites <base href> and asset href/src paths to ensure CSS/JS resolve correctly from the root 404 page.
  • Hooks the new 404 generation into the existing move_to_dev() docs build flow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/move_dev_docs.py

def write_root_404(bookdir: Path) -> None:
"""Generate book/404.html from book/dev/404.html with corrected asset paths."""
content = (bookdir / "dev" / "404.html").read_text(encoding="utf-8")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary

Comment thread docs/move_dev_docs.py
Comment on lines +30 to +33
content = content.replace(
'const path_to_root = "";', 'const path_to_root = "dev/";'
)
content = content.replace('var pathToRoot = "";', 'var pathToRoot = "dev/";')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure if the 404 pages break again, we can fix them later.

Comment thread docs/move_dev_docs.py Outdated
Comment thread docs/move_dev_docs.py
Comment on lines +61 to +62
# Create a fix for the 404 routing
write_root_404(bookdir)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are related to the documentation pages, not the tool itself. probably not necessary

Comment thread docs/move_dev_docs.py
Comment on lines +23 to +27
content = re.sub(
r'((?:href|src)=")((?!(?:https?:|//|#|/)))',
r"\1dev/\2",
content,
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what this means tbh

Comment thread docs/move_dev_docs.py
"""Generate book/404.html from book/dev/404.html with corrected asset paths."""
content = (bookdir / "dev" / "404.html").read_text(encoding="utf-8")

# Replace base href with the GitHub Pages project root

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Replace base href with the GitHub Pages project root
# Replace base href with the repository root

I guess technically it's the repository root, which the GH pages uses in the URL.

And so the repository would need to be cloned into a "MUSE2" directory for this to work locally, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's kind of the other way around. The GitHub pages project adds this extra "MUSE2/" path, which is not known at build time. To make this work locally, you'd need to put everything inside the bookdir another layer deeper, under a 'MUSE2' folder.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, of course. Fair enough!

@tsmbland tsmbland left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily understand what this is doing, but I followed the instructions to reproduce and it worked, so all good

@dc2917 dc2917 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems logical to me, and seems to be working too. Just wondering if the project root can be bookdir.parent or something.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.

Docs 404 page not displaying properly

4 participants