From 8882e2eff3264babdbe43639b2c2b496397fb56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 25 Jan 2023 12:41:02 +0100 Subject: [PATCH] theme: announce translations as alternate links #422 --- exampleSite/config.toml | 2 ++ exampleSite/content/cont/i18n/_index.en.md | 5 ++++ layouts/_default/sitemap.xml | 32 ++++++++++++---------- layouts/partials/header.html | 30 +++++++++++++------- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 10e74cd2f8..d11f0b2414 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -27,6 +27,8 @@ theme = "hugo-theme-relearn" # the main language of this site; also an automatic pirrrate translation is # available in this showcase languageCode = "en" +# make sure your defaultContentLanguage is the first one in the [Languages] +# array below, as the theme needs to make assumptions on it defaultContentLanguage = "en" # if you want to get rrrid o' ourrr pirrrates nonsense uncomment th' next line # disableLanguages = ['pir'] diff --git a/exampleSite/content/cont/i18n/_index.en.md b/exampleSite/content/cont/i18n/_index.en.md index 0733d5f307..26fecfbd21 100644 --- a/exampleSite/content/cont/i18n/_index.en.md +++ b/exampleSite/content/cont/i18n/_index.en.md @@ -20,6 +20,11 @@ After learning [how Hugo handle multilingual websites](https://gohugo.io/content For example with current English and Piratized English website. +{{% notice note %}} +Make sure your default language is defined as the first one in the `[Languages]` array, as the theme needs to make assumptions on it +{{% /notice %}} + + ```toml # English is the default language defaultContentLanguage = "en" diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml index baa5200570..1f79020b6e 100644 --- a/layouts/_default/sitemap.xml +++ b/layouts/_default/sitemap.xml @@ -4,20 +4,24 @@ {{- range .Data.Pages }} {{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) }} - {{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}{{ if not .Lastmod.IsZero }} - {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} - {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} - {{ .Sitemap.Priority }}{{ end }}{{ if .IsTranslated }}{{ range .Translations }} - {{ end }} - {{ end }} + {{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }} + {{- if not .Lastmod.IsZero }} + {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }} + {{- end }} + {{- with .Sitemap.ChangeFreq }} + {{ . }} + {{- end }} + {{- if ge .Sitemap.Priority 0.0 }} + {{ .Sitemap.Priority }} + {{- end }} + {{- if .IsTranslated }} + {{- range $index, $trans := .AllTranslations }} + {{- if eq $index 0 }} + + {{- end }} + + {{- end }} + {{- end }} {{- end -}} {{- end }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index e4f188b4f8..b52e88ca13 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -17,25 +17,35 @@ {{- $title = printf "%s%s" $title .Site.Title }} {{ $title }} + {{- if .IsTranslated -}} + {{- range $index, $trans := .AllTranslations }} + {{- if eq $index 0 }} + + {{- end }} + + {{- end }} + {{- end }} + {{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }} {{- else }} - {{- range .AlternativeOutputFormats }} - {{- if eq .Rel "canonical" }} + {{- range .AlternativeOutputFormats }} + {{- if eq .Rel "canonical" }} {{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }} - {{- else if eq $outputFormat "searchpage" }} - {{- else if eq .Name "SEARCHPAGE" }} - {{- else if and (ne .Name "JSON") (ne .Name "SEARCH") }} + {{- else if eq $outputFormat "searchpage" }} + {{- else if eq .Name "SEARCHPAGE" }} + {{- else if and (ne .Name "JSON") (ne .Name "SEARCH") }} {{ (printf $link (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }} - {{- end }} {{- end }} + {{- end }} {{- end }} + {{- if and (ne .Site.Params.disableSeoHiddenPages true) (ne .Site.Params.disableSearchHiddenPages true) }} - {{- range .AlternativeOutputFormats }} - {{- if eq .Name "SEARCHPAGE" }} - {{- else if eq .Name "JSON" }} + {{- range .AlternativeOutputFormats }} + {{- if eq .Name "SEARCHPAGE" }} + {{- else if eq .Name "JSON" }} {{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($title | htmlEscape)) | safeHTML }} - {{- end }} {{- end }} + {{- end }} {{- end }} {{- partialCached "favicon.html" . }}