From acdc71b34f88d35f473f957c3c0230571dabc5c4 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 18 Aug 2020 23:38:19 +0100 Subject: [PATCH] Add language changing button --- _data/languages.yml | 3 + _layouts/base.html | 24 ++++++++ _layouts/default.html | 137 +++++++++++++++++++----------------------- _sass/_main.scss | 18 ++++++ languages.html | 24 ++++++++ static/languages.svg | 1 + 6 files changed, 131 insertions(+), 76 deletions(-) create mode 100644 _layouts/base.html create mode 100644 languages.html create mode 100644 static/languages.svg diff --git a/_data/languages.yml b/_data/languages.yml index 99124e3..ea5b9c9 100644 --- a/_data/languages.yml +++ b/_data/languages.yml @@ -1,6 +1,9 @@ +# cta = call to action (used when prompting user their language is available) + - code: en name: English (UK) cta: This book is available in English + - code: it name: Italiano cta: Questo libro รจ disponibile in italiano diff --git a/_layouts/base.html b/_layouts/base.html new file mode 100644 index 0000000..6e02eee --- /dev/null +++ b/_layouts/base.html @@ -0,0 +1,24 @@ +--- +layout: compress +--- + + + + + {% if page.homepage %}{% else %}{{ page.title }} - {% endif %}Minetest Modding Book + + + + + + + + + + + +
+ {{ content }} +
+ + diff --git a/_layouts/default.html b/_layouts/default.html index 635f2ee..83222ae 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -1,90 +1,75 @@ --- -layout: compress +layout: base --- - - - - {% if page.homepage %}{% else %}{{ page.title }} - {% endif %}Minetest Modding Book - - - - - - +{% assign pathsplit = page.path | split: '/' %} - - - - - {% assign pathsplit = page.path | split: '/' %} +{% assign language = pathsplit[0] %} - {% assign language = pathsplit[0] %} +{% if language == "_it" %} + {% assign language = "it" %} + {% assign links = site.it | sort: "idx" %} +{% else %} + {% assign language = "en" %} + {% assign links = site.en | sort: "idx" %} +{% endif %} - {% if language == "_it" %} - {% assign language = "it" %} - {% assign links = site.it | sort: "idx" %} - {% else %} - {% assign language = "en" %} - {% assign links = site.en | sort: "idx" %} - {% endif %} +{% assign num = 0 %} - {% assign num = 0 %} + +
+
+ + Choose a language + {{ language }} + -
-
- {% if page.no_header %}{% else %}

{{ page.title }}

{% endif %} - {{ content }} -
+ {% if page.no_header %}{% else %}

{{ page.title }}

{% endif %} + {{ content }} +
+ {% for link in links %} + {% if link.title == page.title %} + {% unless forloop.first %} + {% assign prev = tmpprev %} + {% endunless %} + {% unless forloop.last %} + {% assign next = links[forloop.index] %} + {% endunless %} + {% endif %} + {% assign tmpprev = link %} + {% endfor %} - {% for link in links %} - {% if link.title == page.title %} - {% unless forloop.first %} - {% assign prev = tmpprev %} - {% endunless %} - {% unless forloop.last %} - {% assign next = links[forloop.index] %} - {% endunless %} - {% endif %} - {% assign tmpprev = link %} - {% endfor %} + - - -
- © 2014-20 | - Helpful? Consider - donating - to support my work. -
- -
- - - - + + diff --git a/_sass/_main.scss b/_sass/_main.scss index a01248b..d800709 100644 --- a/_sass/_main.scss +++ b/_sass/_main.scss @@ -83,6 +83,24 @@ article { // text-align: justify; } +.language-switcher { + display: flex; + align-items: center; + float: right; + color: black; + text-decoration: none; + padding-top: 0.3rem; + + img, span { + display: inline-block; + } + + img { + height: 1.2em; + padding-right: 0.3em; + } +} + footer { margin: 0 0 20px 0; padding: 1em 1.5em; diff --git a/languages.html b/languages.html new file mode 100644 index 0000000..949b052 --- /dev/null +++ b/languages.html @@ -0,0 +1,24 @@ +--- +title: Languages +layout: base +root: . +--- + +
+
+

Minetest Modding Book

+ +

Choose a Language

+ +
    + {% for lang in site.data.languages %} +
  • {{ lang.name }}
  • + {% endfor %} +
+ +
+ +
+ © 2014-20 +
+
diff --git a/static/languages.svg b/static/languages.svg new file mode 100644 index 0000000..88d3bc6 --- /dev/null +++ b/static/languages.svg @@ -0,0 +1 @@ + \ No newline at end of file