Skip to content

Internal links (customMenus, project cards) don't respect baseURL when it has a subpath #1208

Description

@yinchi

Expected Behavior

Internal links (e.g. a customMenus entry pointing to an internal page, or a
project card's .url pointing to an internal post) should resolve correctly
under any configured baseURL, including one with a subpath — e.g. a GitHub
Pages project site like https://user.github.io/repo/.

Current Behavior

These links are rendered as a raw, unprocessed href="{{ .url }}" with no
baseURL handling, so they only produce a correct path when baseURL has no
subpath. On a subpath deployment the link is missing the subpath entirely and
points to the wrong location — e.g. /posts instead of /repo/posts.

Two confirmed instances:

  • customMenus entries (navbar.html, footer.html)
  • Project card links/buttons (cards/project.html, .url) — the theme's own
    exampleSite already demonstrates an internal-path use case for this field
    (the "Rich Content" project in data/en/sections/projects.yaml), so this
    isn't hypothetical.

Possible Solution

Distinguish internal (no http:///https:// prefix) from external URLs, and
resolve internal ones by joining them onto site.BaseURL | relLangURL (the
same pattern already used ad hoc for the blog/notes nav links).

Steps to Reproduce

  1. In exampleSite, note the "Rich Content" project card in
    data/en/sections/projects.yaml, which uses an internal url
    (/posts/category/sub-category/rich-content/).
  2. Build with a subpath baseURL:
    hugo --gc --minify --baseURL "https://example.com/subpath/"
  3. Inspect the rendered href for that project card.
  4. Observe it renders as /posts/category/sub-category/rich-content — missing
    the /subpath prefix — while other internal links on the same page (e.g.
    section anchors, the post's own card elsewhere via .RelPermalink) are
    correctly prefixed with /subpath.

Screenshots

N/A — this is a server-rendered HTML output issue (wrong href value), not a
visual/layout bug.

Browsers Affected

N/A — the bug is in Hugo's build-time template rendering, not
browser-specific.

Detailed Description

Several href attributes in the theme are set directly from a data field
({{ .url }}) without passing through any Hugo URL-resolution function
(relLangURL, absLangURL, RelPermalink, etc.). This only happens to
produce a correct URL when baseURL has no subpath — on a project site or any
other non-root deployment, the link is simply wrong.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions