Skip to content

Commit

Permalink
Add hreflang Tag to Translation Link example
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangChengLin committed Jan 10, 2024
1 parent 2d2a821 commit 9a64d95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
15 changes: 8 additions & 7 deletions content/en/methods/page/AllTranslations.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ And this template:
{{ with .AllTranslations }}
<ul>
{{ range . }}
{{ $lang := .Language.LanguageName}}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }} ({{ $lang }})</a></li>
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
{{ end }}
</ul>
{{ end }}
Expand All @@ -74,17 +75,17 @@ Hugo will render this list on the "Book 1" page of each site:

```html
<ul>
<li><a href="/books/book-1/">Book 1 (English)</a></li>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/">Book 1 (Français)</a></li>
<li><a href="/books/book-1/" hreflang="en-US">Book 1 (English)</a></li>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/" hreflang="fr-FR">Book 1 (Français)</a></li>
</ul>
```

On the "Book 2" page of the English and German sites, Hugo will render this:

```html
<ul>
<li><a href="/books/book-1/">Book 1 (English)</a></li>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
<li><a href="/books/book-1/" hreflang="en-US">Book 1 (English)</a></li>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
</ul>
```
11 changes: 6 additions & 5 deletions content/en/methods/page/Translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ And this template:
{{ with .Translations }}
<ul>
{{ range . }}
{{ $lang := .Language.LanguageName}}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }} ({{ $lang }})</a></li>
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
{{ end }}
</ul>
{{ end }}
Expand All @@ -74,15 +75,15 @@ Hugo will render this list on the "Book 1" page of the English site:

```html
<ul>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/">Book 1 (Français)</a></li>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/" hreflang="fr-FR">Book 1 (Français)</a></li>
</ul>
```

Hugo will render this list on the "Book 2" page of the English site:

```html
<ul>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
</ul>
```

0 comments on commit 9a64d95

Please sign in to comment.