mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-30 03:03:09 +00:00
theme: announce translations as alternate links #422
This commit is contained in:
parent
8e7bbf473e
commit
8882e2eff3
4 changed files with 45 additions and 24 deletions
|
@ -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']
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -4,20 +4,24 @@
|
|||
{{- range .Data.Pages }}
|
||||
{{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) }}
|
||||
<url>
|
||||
<loc>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</loc>{{ if not .Lastmod.IsZero }}
|
||||
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
|
||||
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
|
||||
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="{{ .Lang }}"
|
||||
href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}"
|
||||
/>{{ end }}
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="{{ .Lang }}"
|
||||
href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}"
|
||||
/>{{ end }}
|
||||
<loc>{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}</loc>
|
||||
{{- if not .Lastmod.IsZero }}
|
||||
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>
|
||||
{{- end }}
|
||||
{{- with .Sitemap.ChangeFreq }}
|
||||
<changefreq>{{ . }}</changefreq>
|
||||
{{- end }}
|
||||
{{- if ge .Sitemap.Priority 0.0 }}
|
||||
<priority>{{ .Sitemap.Priority }}</priority>
|
||||
{{- end }}
|
||||
{{- if .IsTranslated }}
|
||||
{{- range $index, $trans := .AllTranslations }}
|
||||
{{- if eq $index 0 }}
|
||||
<xhtml:link rel="alternate" hreflang="x-default" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||
{{- end }}
|
||||
<xhtml:link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true) }}" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
</url>
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
|
|
|
@ -17,25 +17,35 @@
|
|||
{{- $title = printf "%s%s" $title .Site.Title }}
|
||||
<title>{{ $title }}</title>
|
||||
|
||||
{{- if .IsTranslated -}}
|
||||
{{- range $index, $trans := .AllTranslations }}
|
||||
{{- if eq $index 0 }}
|
||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="x-default">
|
||||
{{- end }}
|
||||
<link href="{{ partial "relLangPrettyUglyURL.hugo" (dict "to" . "abs" true "basename" $basename) }}" rel="alternate" hreflang="{{ .Language.Lang }}">
|
||||
{{- 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" . }}
|
||||
|
|
Loading…
Reference in a new issue