Skip to content

Commit

Permalink
improve: Remove canonifyURLs, use absURL
Browse files Browse the repository at this point in the history
Hugo configuration `canonifyURLs` is a brute force approach to search
for relative URLs with a leading slash and then prepend them with the
baseURL to create absolute URLs after the page is rendered. This
approach is slow and confusing and will be removed in future from Hugo.

Use `absURL` template function in theme layouts to replace
`canonifyURLs`. To support the base URLs with sub directories remove
leading slash in relative URLs.

Fixes: #1 | Blog Footer and header URL's don't seem to follow base path
  • Loading branch information
manid2 committed Aug 23, 2023
1 parent 92ba9ef commit d090373
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 0 additions & 2 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ title = "Hugo Xterm"
languageCode = "en-us"
baseurl = "https://manid2.github.io/hugo-xterm/"
paginate = 20
canonifyurls = true

[module]
[[module.imports]]
Expand Down Expand Up @@ -35,7 +34,6 @@ canonifyurls = true

[languages.en.params.logo]
logoText = "Home"
logoHomeLink = "/"

[languages.en.menu]
[[languages.en.menu.main]]
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
{{- /* site footer links */}}
<nav class="navbar">
<ul class="navbar__list">
<li><a href="/posts/index.xml">RSS</a></li>
<li><a href="/sitemap.xml">Sitemap</a></li>
<li><a href="{{ absURL "posts/index.xml" }}">RSS</a></li>
<li><a href="{{ absURL "sitemap.xml" }}">Sitemap</a></li>
{{- $gitRepoUrl := "" -}}
{{- if (isset site.Params "git_info") -}}
{{- $git_host := site.Params.git_info.host -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/navbar.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{- $logoText := site.Params.Logo.logoText | default "Home" -}}
{{- $logoLink := site.Params.Logo.logoHomeLink | default "/" -}}
{{- $logoLink := site.Params.Logo.logoHomeLink | default "" -}}

{{- /* navbar */}}
<nav class="navbar">
<div class="navbar__first">
<ul class="navbar__list borders">
<li><a href="{{ $logoLink }}">{{ $logoText }}</a></li>
<li><a href="{{ absURL $logoLink }}">{{ $logoText }}</a></li>
<li>
<button class="theme-toggle transparent">
{{- partial "theme-icon.html" . -}}
Expand Down

0 comments on commit d090373

Please sign in to comment.