fix: emit per-page canonical URLs and absolute URLs in sitemap and feeds - #683
Open
Akshats-git wants to merge 3 commits into
Open
fix: emit per-page canonical URLs and absolute URLs in sitemap and feeds#683Akshats-git wants to merge 3 commits into
Akshats-git wants to merge 3 commits into
Conversation
Internal links and asset references used .Permalink, which resolves against baseurl. That is fine while baseurl is "/", but it would turn every in-site link absolute once baseurl points at the production domain, sending preview and local builds back to the live site. Use RelPermalink, relref and relURL for same-site references. The rendered output is unchanged under the current configuration. Signed-off-by: Akshat <akshatgupta099@gmail.com>
baseurl was "/", so Hugo wrote relative URLs into sitemap.xml, the RSS feeds and og:url. The sitemap protocol requires an absolute URL in <loc>, and relative links in RSS are unusable in feed readers. Point baseurl at https://www.flatcar.org/ and disable canonifyurls so that in-content links stay relative to the site root. The serve target builds to disk before serving locally, so it now passes its own base URL. Signed-off-by: Akshat <akshatgupta099@gmail.com>
The canonical tag was hardcoded to https://flatcar-linux.org/, a domain that now redirects to www.flatcar.org. Every page declared itself a duplicate of that homepage. The meta description was hardcoded too, discarding the description front matter that most docs pages already set. Derive the canonical tag from the page permalink, with a canonical front matter key for pages that need to point elsewhere. Build the description from the page description, tagline or summary, collapsing the whitespace that multi-line YAML values carry, and reuse it for og:description. The social card and post images now go through absURL instead of assembling the base URL by hand. Signed-off-by: Akshat <akshatgupta099@gmail.com>
Akshats-git
force-pushed
the
fix/canonical-and-absolute-urls
branch
from
August 16, 2026 09:44
1141163 to
5163792
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.
Fixes flatcar/Flatcar#2367
What was wrong
Every page emitted the same canonical tag:
It was hardcoded in
head.html. The domain redirects to www.flatcar.org, and it points at the homepage, so all 230 pages claimed to be duplicates of one page.baseurlwas also set to/. Hugo therefore wrote relative URLs intositemap.xml, the RSS feeds andog:url. The sitemap protocol requires absolute URLs in<loc>, so none of the 230 entries were valid. RSS links were dead in feed readers.The meta description was hardcoded to "Flatcar Linux" on every page, even though 81 docs pages already set a
descriptionin their front matter.What changed
Three commits:
RelPermalink,relrefandrelURL. This is a no-op today, but it stops every in-site link from turning absolute in the next commit. Preview builds keep working.baseurlis set tohttps://www.flatcar.org/andcanonifyurlsis disabled.make servepasses its own base URL since it builds to disk.canonicalfront matter key is available for pages that need to point elsewhere. The meta description falls back through description, tagline, summary and site description.Testing
Built with Hugo Extended 0.163.3 from
.env. I builtmainin a worktree and diffed all 1020 output files.href, asset URL or page body changed.atom:linkand item links are absolute.-b https://preview-123.example.net/to confirm previews stay self-contained. Canonical and sitemap follow the override while nav and CSS stay root relative.pagefindindexes 154 pages and 10317 words, same as before.