Skip to content

Commit d090373

Browse files
committed
improve: Remove canonifyURLs, use absURL
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
1 parent 92ba9ef commit d090373

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

exampleSite/config/_default/config.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ title = "Hugo Xterm"
22
languageCode = "en-us"
33
baseurl = "https://manid2.github.io/hugo-xterm/"
44
paginate = 20
5-
canonifyurls = true
65

76
[module]
87
[[module.imports]]
@@ -35,7 +34,6 @@ canonifyurls = true
3534

3635
[languages.en.params.logo]
3736
logoText = "Home"
38-
logoHomeLink = "/"
3937

4038
[languages.en.menu]
4139
[[languages.en.menu.main]]

layouts/partials/footer.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
{{- /* site footer links */}}
5454
<nav class="navbar">
5555
<ul class="navbar__list">
56-
<li><a href="/posts/index.xml">RSS</a></li>
57-
<li><a href="/sitemap.xml">Sitemap</a></li>
56+
<li><a href="{{ absURL "posts/index.xml" }}">RSS</a></li>
57+
<li><a href="{{ absURL "sitemap.xml" }}">Sitemap</a></li>
5858
{{- $gitRepoUrl := "" -}}
5959
{{- if (isset site.Params "git_info") -}}
6060
{{- $git_host := site.Params.git_info.host -}}

layouts/partials/navbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{- $logoText := site.Params.Logo.logoText | default "Home" -}}
2-
{{- $logoLink := site.Params.Logo.logoHomeLink | default "/" -}}
2+
{{- $logoLink := site.Params.Logo.logoHomeLink | default "" -}}
33

44
{{- /* navbar */}}
55
<nav class="navbar">
66
<div class="navbar__first">
77
<ul class="navbar__list borders">
8-
<li><a href="{{ $logoLink }}">{{ $logoText }}</a></li>
8+
<li><a href="{{ absURL $logoLink }}">{{ $logoText }}</a></li>
99
<li>
1010
<button class="theme-toggle transparent">
1111
{{- partial "theme-icon.html" . -}}

0 commit comments

Comments
 (0)