Skip to content

fix: emit per-page canonical URLs and absolute URLs in sitemap and feeds - #683

Open
Akshats-git wants to merge 3 commits into
flatcar:mainfrom
Akshats-git:fix/canonical-and-absolute-urls
Open

fix: emit per-page canonical URLs and absolute URLs in sitemap and feeds#683
Akshats-git wants to merge 3 commits into
flatcar:mainfrom
Akshats-git:fix/canonical-and-absolute-urls

Conversation

@Akshats-git

Copy link
Copy Markdown

Fixes flatcar/Flatcar#2367

What was wrong

Every page emitted the same canonical tag:

<link rel="canonical" href="https://flatcar-linux.org/" />

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.

baseurl was also set to /. Hugo therefore wrote relative URLs into sitemap.xml, the RSS feeds and og: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 description in their front matter.

What changed

Three commits:

  1. Internal links and assets now use RelPermalink, relref and relURL. This is a no-op today, but it stops every in-site link from turning absolute in the next commit. Preview builds keep working.
  2. baseurl is set to https://www.flatcar.org/ and canonifyurls is disabled. make serve passes its own base URL since it builds to disk.
  3. The canonical tag comes from the page permalink. A canonical front 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 built main in a worktree and diffed all 1020 output files.

  • Same file inventory, same 319 pages, same pre-existing warnings.
  • The only changes are the four metadata tags, plus 368 alias redirect stubs that now carry absolute canonicals. No internal href, asset URL or page body changed.
  • Sitemap went from 0/230 to 230/230 absolute. RSS channel, atom:link and item links are absolute.
  • Built with -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.
  • pagefind indexes 154 pages and 10317 words, same as before.
  • Each commit builds on its own.

Copilot AI lite review requested due to automatic review settings August 15, 2026 15:05
@Akshats-git
Akshats-git requested a review from a team as a code owner August 15, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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
Akshats-git force-pushed the fix/canonical-and-absolute-urls branch from 1141163 to 5163792 Compare August 16, 2026 09:44
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.

bug: canonical tag points to old domain homepage on every page

2 participants