Moved language and features to theme configuration

This commit is contained in:
squidfunk 2017-10-31 18:51:54 +01:00 committed by Martin Donath
parent a5d90ea2a9
commit 5fbba74c80
7 changed files with 29 additions and 30 deletions

View File

@ -1,4 +1,5 @@
{% import "partials/language.html" as lang with context %} {% import "partials/language.html" as lang with context %}
{% set feature = config.theme.feature %}
{% set palette = config.theme.palette %} {% set palette = config.theme.palette %}
{% set font = config.theme.font %} {% set font = config.theme.font %}
<!DOCTYPE html> <!DOCTYPE html>
@ -104,7 +105,6 @@
{% include "partials/header.html" %} {% include "partials/header.html" %}
{% endblock %} {% endblock %}
<div class="md-container"> <div class="md-container">
{% set feature = config.extra.get("feature", {}) %}
{% if feature.tabs %} {% if feature.tabs %}
{% include "partials/tabs.html" %} {% include "partials/tabs.html" %}
{% endif %} {% endif %}

View File

@ -16,6 +16,12 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
# Language for theme localization # Language for theme localization
language: en language: en
# Feature flags for functionality that alters behavior significantly, and thus
# may be a matter of taste
feature:
# Another layer on top of the main navigation for larger screens in the form
# of tabs, especially useful for larger documentation projects
tabs: false
# Sets the primary and accent color palettes as defined in the Material Design # Sets the primary and accent color palettes as defined in the Material Design
# documentation - possible values can be looked up in the getting started guide # documentation - possible values can be looked up in the getting started guide
palette: palette:

View File

@ -1,11 +1,4 @@
{% set languages = "en" %} {% import "partials/language/" + config.theme.language + ".html" as lang %}
{% if config and config.theme %}
{% set languages = config.theme.language | default("en") %}
{% endif %}
{% if languages is string %}
{% set languages = languages.split(",") | map("trim") %}
{% endif %}
{% import "partials/language/" + (languages | first) + ".html" as lang %}
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"search.languages": languages | join(", ") "search.languages": (config.extra.search | default({})).language | default("")
}[key] or lang.t(key) }}{% endmacro %} }[key] or lang.t(key) }}{% endmacro %}

View File

@ -37,22 +37,23 @@ theme:
custom_dir: material custom_dir: material
# Same values as in mkdocs_theme.yml # Same values as in mkdocs_theme.yml
language: kr language: en
feature:
tabs: false
palette:
primary:
accent:
font: font:
text: Roboto text: Roboto
code: Roboto Mono code: Roboto Mono
palette:
primary:
accent: blue
plugins: #plugins: []
- search: null
# Options # Options
extra: extra:
language: en language: en
feature: search:
tabs: false languages: en, de, fr
social: social:
- type: globe - type: globe
link: http://struct.cc link: http://struct.cc

View File

@ -23,6 +23,7 @@
{% import "partials/language.html" as lang with context %} {% import "partials/language.html" as lang with context %}
<!-- Theme options --> <!-- Theme options -->
{% set feature = config.theme.feature %}
{% set palette = config.theme.palette %} {% set palette = config.theme.palette %}
{% set font = config.theme.font %} {% set font = config.theme.font %}
@ -200,7 +201,6 @@
<!-- Container, necessary for web-application context --> <!-- Container, necessary for web-application context -->
<div class="md-container"> <div class="md-container">
{% set feature = config.extra.get("feature", {}) %}
<!-- Tabs with outline --> <!-- Tabs with outline -->
{% if feature.tabs %} {% if feature.tabs %}

View File

@ -21,6 +21,14 @@
# Language for theme localization # Language for theme localization
language: en language: en
# Feature flags for functionality that alters behavior significantly, and thus
# may be a matter of taste
feature:
# Another layer on top of the main navigation for larger screens in the form
# of tabs, especially useful for larger documentation projects
tabs: false
# Sets the primary and accent color palettes as defined in the Material Design # Sets the primary and accent color palettes as defined in the Material Design
# documentation - possible values can be looked up in the getting started guide # documentation - possible values can be looked up in the getting started guide
palette: palette:

View File

@ -20,19 +20,10 @@
IN THE SOFTWARE. IN THE SOFTWARE.
--> -->
<!-- Normalize language configuration -->
{% set languages = "en" %}
{% if config and config.theme %}
{% set languages = config.theme.language | default("en") %}
{% endif %}
{% if languages is string %}
{% set languages = languages.split(",") | map("trim") %}
{% endif %}
<!-- Import translations for given language --> <!-- Import translations for given language -->
{% import "partials/language/" + (languages | first) + ".html" as lang %} {% import "partials/language/" + config.theme.language + ".html" as lang %}
<!-- Re-export translations --> <!-- Re-export translations -->
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"search.languages": languages | join(", ") "search.languages": (config.extra.search | default({})).language | default("")
}[key] or lang.t(key) }}{% endmacro %} }[key] or lang.t(key) }}{% endmacro %}