Skip to content

[Docs] Fix 404 asset base path for previews#1066

Open
CodexRaunak wants to merge 3 commits into
layer5io:masterfrom
CodexRaunak:fix-404-preview-base-path
Open

[Docs] Fix 404 asset base path for previews#1066
CodexRaunak wants to merge 3 commits into
layer5io:masterfrom
CodexRaunak:fix-404-preview-base-path

Conversation

@CodexRaunak
Copy link
Copy Markdown
Contributor

@CodexRaunak CodexRaunak commented May 29, 2026

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread layouts/partials/head.html Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

🚀 Preview deployment: https://layer5io.github.io/docs/pr-preview/pr-1066/

Note: Preview may take a moment (GitHub Pages deployment in progress). Please wait and refresh. Track deployment here

miacycle

This comment was marked as duplicate.

@Bhumikagarggg
Copy link
Copy Markdown
Contributor

Hey @CodexRaunak!
You can close this PR. I’ve made the correct changes and verified them locally for this issue in PR #1077.

@CodexRaunak CodexRaunak force-pushed the fix-404-preview-base-path branch from b5b840f to a10df8e Compare June 7, 2026 01:35
Signed-off-by: Raunak Madan <madanraunak24@gmail.com>
@CodexRaunak CodexRaunak force-pushed the fix-404-preview-base-path branch from a10df8e to 3b14dee Compare June 7, 2026 05:57
Signed-off-by: Raunak Madan <madanraunak24@gmail.com>
@CodexRaunak CodexRaunak requested a review from Bhumikagarggg June 7, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants