theme: generate correct links if theme served from subdirectory #120

This commit is contained in:
Sören Weber 2021-10-17 23:03:41 +02:00
parent 3e62e54554
commit d673b2c240
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
5 changed files with 27 additions and 15 deletions

View file

@ -1,4 +1,5 @@
baseURL = "https://example.com"
canonifyURLs = true
languageCode = "en"
defaultContentLanguage = "en"
@ -40,7 +41,7 @@ relativeURLs = true
title = "Documentation for Hugo Relearn Theme"
weight = 1
languageName = "English"
landingPageURL = "/en"
landingPageURL = "/"
landingPageName = "<i class='fas fa-home'></i> Home"
[[Languages.en.menu.shortcuts]]
@ -56,7 +57,7 @@ relativeURLs = true
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-fw fa-camera'></i> Showcases"
url = "showcase"
url = "/showcase/"
weight = 11
[[Languages.en.menu.shortcuts]]
@ -67,14 +68,14 @@ relativeURLs = true
[[Languages.en.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bullhorn'></i> Credits"
url = "/credits"
url = "/credits/"
weight = 30
[Languages.pir]
title = "Documentat'n fer Cap'n Hugo Relearrrn Theme"
weight = 1
languageName = "Arrr! Pirrrates"
landingPageURL = "/pir"
landingPageURL = "/pir/"
landingPageName = "<i class='fas fa-home'></i> Arrr! Home"
[[Languages.pir.menu.shortcuts]]
@ -90,7 +91,7 @@ relativeURLs = true
[[Languages.pir.menu.shortcuts]]
name = "<i class='fas fa-fw fa-camera'></i> Showcases"
url = "showcase"
url = "/showcase/"
weight = 11
[[Languages.pir.menu.shortcuts]]
@ -101,5 +102,5 @@ relativeURLs = true
[[Languages.pir.menu.shortcuts]]
name = "<i class='fas fa-fw fa-bullhorn'></i> Crrredits"
url = "/credits"
url = "/credits/"
weight = 30

View file

@ -66,6 +66,17 @@ Note that some of these parameters are explained in details in other sections of
titleSeparator = "-"
```
## A word on running your site in a subfolder
The theme runs best if your site is installed in the root of your webserver. If your site is served from a subfolder, eg. `https://example.com/mysite/`, you have to set the following lines to your `config.toml`
````toml
baseURL = "https://example.com/mysite/"
canonifyURLs = true
````
Without `canonifyURLs=true` URLs in sublemental pages (like `sitemap.xml`, `rss.xml`) will be generated falsly while your HTML files will still work. See https://github.com/gohugoio/hugo/issues/5226.
## Activate search
If not already present, add the follow lines in the same `config.toml` file.
@ -101,12 +112,12 @@ appearance, you will have to configure two parameters for the defined languages:
[Lanugages]
[Lanugages.en]
...
landingPageURL = "/en"
landingPageURL = "/"
landingPageName = "<i class='fas fa-home'></i> Home"
...
[Lanugages.pir]
...
landingPageURL = "/pir"
landingPageURL = "/pir/"
landingPageName = "<i class='fas fa-home'></i> Arrr! Homme"
...
```

View file

@ -1 +1,2 @@
<link rel="shortcut icon" href="/images/logo.svg" />
{{- $assetBusting := not .Site.Params.disableAssetsBusting -}}
<link rel="shortcut icon" href="{{"images/logo.svg" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"/>

View file

@ -55,18 +55,17 @@
<a class="padding">
<i class="fas fa-language fa-fw"></i>
<div class="select-style">
<select id="select-language" onchange="location = this.value;">
<select id="select-language" onchange="location = baseUri + this.value;">
{{- $siteLanguages := .Site.Languages }}
{{- $pageLang := .Page.Lang }}
{{- range .Page.AllTranslations }}
{{- $translation := . }}
{{- range $siteLanguages }}
{{- if eq $translation.Lang .Lang }}
{{- $selected := false }}
{{- if eq $pageLang .Lang }}
<option id="{{ $translation.Language }}" value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option>
<option id="{{ $translation.Language }}" value="{{ $translation.RelPermalink }}" selected>{{ .LanguageName }}</option>
{{- else }}
<option id="{{ $translation.Language }}" value="{{ $translation.Permalink }}">{{ .LanguageName }}</option>
<option id="{{ $translation.Language }}" value="{{ $translation.RelPermalink }}">{{ .LanguageName }}</option>
{{- end }}
{{- end }}
{{- end }}

View file

@ -4,14 +4,14 @@
{{- else }}
{{- range .AlternativeOutputFormats }}
{{- if ne .Name "JSON" }}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | relURL }}" title="{{ $.Site.Title | safeHTML }}" />
{{- end }}
{{- end }}
{{- end }}
{{- if and (ne .Site.Params.disableSeoHiddenPages true) (ne .Site.Params.disableSearchHiddenPages true) }}
{{- range .AlternativeOutputFormats }}
{{- if eq .Name "JSON" }}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | relURL }}" title="{{ $.Site.Title | safeHTML }}" />
{{- end }}
{{- end }}
{{- end }}