[Docs] Fix 404 asset base path for previews#1066
Open
CodexRaunak wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds a script block to layouts/partials/head.html for 404 pages to dynamically set the <base> tag's href attribute when in a PR preview environment. The reviewer suggested updating the JavaScript variable declarations from var to const to align with modern standards and improve block-scoping.
Contributor
|
🚀 Preview deployment: https://layer5io.github.io/docs/pr-preview/pr-1066/
|
1 task
Contributor
|
Hey @CodexRaunak! |
b5b840f to
a10df8e
Compare
Signed-off-by: Raunak Madan <madanraunak24@gmail.com>
a10df8e to
3b14dee
Compare
Signed-off-by: Raunak Madan <madanraunak24@gmail.com>
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.
Root cause: Relative URL = true, this makes the site assets, paths, relative to the current page location, I originally added this to make the assets/paths resolve correctly when deployed under a sub path like pr-previews.
But that's was a symptom level fix, accumulating more technical debt than solving the problem. It resolves correctly for pages except 404 as GitHub Pages serves one 404.html from many URL depths, causing the browser to resolve those relative asset URLs against arbitrary missing paths.
Proposed Fix: For a stronger architecture, relative URLs are set to false, so that Hugo generates URLs as per the site base URL rather than rewriting every URL relative to the current page, as it's fragile as it's correctness depends on the depth of the current URL depth not being served from the site base.
Changes made:
Used relURL for shared assets in templates. This ensures asset paths are generated relative to the configured baseURL.
Used Hugo ref helper for Markdown links (inter page links) eg: removing the hardcoded paths from /concepts/architecture/index.md to {{< ref "concepts/architecture/index.md" >}}. It make the paths resolve correctly when site is served under different baseURLs.
Updated image references to use:
images/instead of hardcoded root-based paths.
Restructured the docs
Previously, many page-specific assets were stored in section-level images/ directories, creating an implicit relationship between content and assets. This made pages harder to move and maintain because asset ownership was not represented in the filesystem.
The restructure converts content to consistent page bundles and colocates assets with the pages that own them.
Ownership Model:
Pages without local resources should remain standalone Markdown files.
Pages with local resources should use page bundles:
page/
├── index.md
└── images/
└── image-name.png
Section-level shared assets belong in the section’s
images/folder.