Skip to content
Reconstruction of the automatic URL corrections happening inside HREF (and SRC) attributes and not some others when rendering HTML using HUGO. Created as an illustration for my post at the HUGO support forum.
HTML CSS
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
archetypes
content
i18n
layouts
static/css
README.md
config.yaml

README.md

Mysterious HREF (and SRC) corrector in Hugo

This is a reconstruction of the automatic URL corrections happening inside HREF (and SRC) attributes and not some others while rendering static website using HUGO.

Created as an illustration for my post on the HUGO support forum.

Details

The behavior I call mysterious (didn't find it described in the HUGO Docs) is:

I'm inserting similar URLs in a few HTML attributes - using a variable containing a string created earlier, representing an URL of a page resource. That URL is relative to the site's base URL: "/comics/comics-1/img/image1-featured-thumb.jpg" (was created using the relURL function).

After rendering the HTML the attributes designed for URLs got their values corrected to URLs that are relative to the page's (comics-1) path:

  • href="../../comics/comics-1/img/image1-featured.jpg"
  • src="../../comics/comics-1/img/image1-featured-thumb.jpg"

while the same URL was left unchanged in other (custom) attributes:

  • data-thumb="/comics/comics-1/img/image1-featured-thumb.jpg"

And this happens by default - without any CanonifyURLs or similar turned on in the config.

I miss this described somewhere so I can understand what's going on and take it into account when creating my templates.

You can’t perform that action at this time.