-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: allow translated drafts (#282)
Co-authored-by: welpo <[email protected]>
- Loading branch information
Showing
1 changed file
with
20 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,29 @@ | ||
{%- if section.relative_path -%} | ||
{%- set base_path = section.relative_path-%} | ||
{%- elif page.relative_path -%} | ||
{%- set base_path = page.relative_path -%} | ||
{%- if section.translations -%} | ||
{%- set current_translations = section.translations -%} | ||
{%- elif page.translations -%} | ||
{%- set current_translations = page.translations -%} | ||
{%- endif -%} | ||
{%- if base_path -%} | ||
{# Get the base filename by stripping out any language code and '.md' suffix #} | ||
{%- set base_filename = base_path | replace(from=".md", to="") | replace(from="." ~ lang, to="") -%} | ||
{# Loop through all available languages in config #} | ||
{%- for lcode, ldetails in config.languages -%} | ||
{%- set translated_filename = base_filename -%} | ||
|
||
{# If the language is not the default language, append the language code to the base filename #} | ||
{%- if lcode != config.default_language -%} | ||
{%- set translated_filename = base_filename ~ "." ~ lcode -%} | ||
{%- endif -%} | ||
{%- set translated_filename = translated_filename ~ ".md" -%} | ||
{%- if current_translations -%} | ||
|
||
{# Check if the translated page or section exists #} | ||
{%- set translation_exists = load_data(path=translated_filename, required=false) -%} | ||
{%- for translation in current_translations -%} | ||
{%- set lcode = translation.lang | default(value = config.default_language) -%} | ||
|
||
{# Get the page #} | ||
{%- if translation_exists -%} | ||
{%- if page.relative_path -%} | ||
{%- set translated_page = get_page(path=translated_filename, metadata_only=true) -%} | ||
{%- else -%} | ||
{%- set translated_page = get_section(path=translated_filename, metadata_only=true) -%} | ||
{%- endif -%} | ||
{#- Dynamically load the language strings for each language -#} | ||
{%- set other_language_strings = load_data(path="i18n/" ~ lcode ~ ".toml", required=false) -%} | ||
{%- if not other_language_strings -%} | ||
{%- set other_language_strings = load_data(path="themes/tabi/i18n/" ~ lcode ~ ".toml", required=false) -%} | ||
{%- endif -%} | ||
<meta property="og:locale:alternate" content="{{ macros_translate::translate(key="date_locale", default="en_GB", language_strings=other_language_strings) }}" /> | ||
|
||
{# Create the og:locale and hreflang tags if the translated page exists #} | ||
{%- if translated_page -%} | ||
|
||
{#- Dynamically load the language strings for each language -#} | ||
{%- set other_language_strings = load_data(path="i18n/" ~ lcode ~ ".toml", required=false) -%} | ||
{%- if not other_language_strings -%} | ||
{%- set other_language_strings = load_data(path="themes/tabi/i18n/" ~ lcode ~ ".toml", required=false) -%} | ||
{%- endif -%} | ||
<meta property="og:locale:alternate" content="{{ macros_translate::translate(key="date_locale", default="en_GB", language_strings=other_language_strings) }}" /> | ||
|
||
{# Construct href for hreflang #} | ||
{%- set href = translated_page.permalink | default(value=translated_page.url) -%} | ||
{%- if lcode == config.default_language -%} | ||
{%- set href = href | replace(from='/' ~ lang ~ '/', to = '/') -%} | ||
{%- else -%} | ||
{%- set href = href | replace(from='/' ~ lang ~ '/', to='/' ~ lcode ~ '/') -%} | ||
{%- endif -%} | ||
<link rel="alternate" hreflang="{{ lcode }}" href="{{ href | safe }}" /> | ||
{# Construct href for hreflang #} | ||
{%- set href = translation.permalink -%} | ||
{%- if lcode == config.default_language -%} | ||
{%- set href = href | replace(from='/' ~ lang ~ '/', to = '/') -%} | ||
{%- else -%} | ||
{%- set href = href | replace(from='/' ~ lang ~ '/', to='/' ~ lcode ~ '/') -%} | ||
{%- endif -%} | ||
<link rel="alternate" hreflang="{{ lcode }}" href="{{ href | safe }}" /> | ||
{%- endfor -%} | ||
|
||
{%- endif -%} |