Generalize translation menus

This commit is contained in:
C. Lente 2023-02-10 16:31:47 -03:00
parent a8c0f3734f
commit 17caeb985f
No known key found for this signature in database
GPG Key ID: B0B503C26E05781B
3 changed files with 25 additions and 9 deletions

View File

@ -3,6 +3,7 @@ title: "Guia da sintaxe markdown"
date: "2020-01-03"
description: "Sample article showcasing basic Markdown syntax and formatting for HTML elements."
tags: ["markdown", "syntax"]
slug: "sintaxe-markdown"
---
For a quick cheatsheet, check out https://simplemde.com/markdown-guide.

View File

@ -0,0 +1,7 @@
---
title: "This File Was Not Translated"
date: "2023-02-03"
description: "An untranslated file"
---
Lorem ipsum.

View File

@ -1,15 +1,23 @@
{{ range .Site.Menus.main.ByWeight }}
<a href="{{ .URL | absLangURL }}">{{ .Name }}</a>
<a href="{{ absLangURL .URL }}">{{ .Name }}</a>
{{ end }}
<a href='mailto:{{ .Site.Params.email }}?subject={{ i18n "email-subject" }}"{{ .Page.Title | default .Site.Title }}"'>Email</a>
<a href='mailto:{{ .Site.Params.email }}?subject={{ i18n "email-subject" }}"{{ default .Site.Title .Page.Title }}"'>Email</a>
<a href="/index.xml">RSS</a>
{{ $pageLang := .Page.Lang }}
{{ if .IsTranslated }}
{{ range .Translations }}
{{ if ne $pageLang .Lang }}
<a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a>
<!-- Convert this page's translations into a dict -->
{{ $translations := dict }}
{{ range .Translations }}
{{ $translations = merge $translations (dict .Language.Lang .) }}
{{ end }}
<!-- Create a link to every translation -->
{{ range where .Site.Languages "Lang" "!=" .Page.Lang }}
{{ with (index $translations .Lang) }}
<a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a>
{{ else }}
<!-- The complicated setup was necessary to make a grayed out link -->
{{ if not .Params.hideUntranslated }}
<a class="disabled" href="">{{ .LanguageName }}</a>
{{ end }}
{{ end }}
{{ else if not .Site.Params.hideUntranslated }}
<a class="disabled" href="">{{ .Language.LanguageName }}</a>
{{ end }}