mirror of
https://github.com/welpo/tabi.git
synced 2025-10-11 07:46:15 +02:00
✨ feat(settings): allow overriding settings following hierarchy
Hierarchy: page > section > config.
This commit is contained in:
parent
b58225a012
commit
4e1ad5232e
6 changed files with 147 additions and 64 deletions
44
config.toml
44
config.toml
|
@ -142,20 +142,6 @@ language_name.ca = "Català"
|
|||
language_name.en = "English"
|
||||
language_name.es = "Español"
|
||||
|
||||
# Remote repository for your Zola site.
|
||||
# Used for `show_remote_changes` and `show_remote_source` (see below).
|
||||
# Supports GitHub, GitLab, Gitea, and Codeberg.
|
||||
remote_repository_url = "https://github.com/welpo/tabi"
|
||||
# Set this to "auto" to try and auto-detect the platform based on the repository URL.
|
||||
# Accepted values are "github", "gitlab", "gitea", and "codeberg".
|
||||
remote_repository_git_platform = "auto" # Defaults to "auto".
|
||||
# Branch in the repo hosting the Zola site.
|
||||
remote_repository_branch = "main" # Defaults to "main".
|
||||
# Show a link to the commit history of updated posts, right next to the last updated date.
|
||||
show_remote_changes = true # Defaults to true.
|
||||
# Show a link to the repository of the site, right next to the "Powered by Zola & tabi" text.
|
||||
show_remote_source = true # Defaults to true.
|
||||
|
||||
# Enable JavaScript theme toggler to allow users to switch between dark/light mode.
|
||||
# Also enables automatic switching based on user's OS-level theme settings.
|
||||
# If disabled, your site will only use the theme specified in the `default_theme` variable.
|
||||
|
@ -182,19 +168,42 @@ skin = ""
|
|||
# You can load a stylesheet for a single post by adding it to the [extra] section of the post's front matter, following this same format.
|
||||
stylesheets = []
|
||||
|
||||
# Remote repository for your Zola site.
|
||||
# Used for `show_remote_changes` and `show_remote_source` (see below).
|
||||
# Supports GitHub, GitLab, Gitea, and Codeberg.
|
||||
remote_repository_url = "https://github.com/welpo/tabi"
|
||||
# Set this to "auto" to try and auto-detect the platform based on the repository URL.
|
||||
# Accepted values are "github", "gitlab", "gitea", and "codeberg".
|
||||
remote_repository_git_platform = "auto" # Defaults to "auto".
|
||||
# Branch in the repo hosting the Zola site.
|
||||
remote_repository_branch = "main" # Defaults to "main".
|
||||
# Show a link to the commit history of updated posts, right next to the last updated date.
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
show_remote_changes = true # Defaults to true.
|
||||
# Show a link to the repository of the site, right next to the "Powered by Zola & tabi" text.
|
||||
show_remote_source = true # Defaults to true.
|
||||
|
||||
# Add a "copy" button to codeblocks (loads ~700 bytes of JavaScript).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
copy_button = true
|
||||
|
||||
# Show the reading time of a page.
|
||||
# Can also be enabled or disabled on individual pages in the front matter's [extra].
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
show_reading_time = true
|
||||
|
||||
# Adds backlinks to footnotes (loads ~500 bytes of JavaScripts).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
footnote_backlinks = false
|
||||
|
||||
# Enable KaTeX for all posts.
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
katex = false
|
||||
|
||||
# Quick navigation buttons.
|
||||
# Adds "go up" and "go to comments" buttons on the bottom right (hidden for mobile).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
quick_navigation_buttons = false
|
||||
|
||||
# Date format used when listing posts (main page, /blog section, tag posts list…)
|
||||
# Default is "6th July 2049" in English and "%d %B %Y" in other languages.
|
||||
long_date_format = "%d %B %Y"
|
||||
|
@ -273,11 +282,6 @@ allowed_domains = [
|
|||
# Please see https://welpo.github.io/tabi/blog/custom-font-subset/ to learn how to create this file.
|
||||
custom_subset = true
|
||||
|
||||
# Quick navigation buttons.
|
||||
# Adds "go up" and "go to comments" buttons on the bottom right (hidden for mobile).
|
||||
# Can also be enabled on individual posts in the front matter's [extra].
|
||||
quick_navigation_buttons = false
|
||||
|
||||
# giscus support for comments. https://giscus.app
|
||||
# Setup instructions: https://welpo.github.io/tabi/blog/comments/#setup
|
||||
[extra.giscus]
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
{% import "macros/paginate.html" as macros_paginate %}
|
||||
{% import "macros/rel_attributes.html" as macros_rel_attributes %}
|
||||
{% import "macros/set_title.html" as macros_set_title %}
|
||||
{% import "macros/settings.html" as macros_settings %}
|
||||
{% import "macros/table_of_contents.html" as macros_toc %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
@ -27,23 +28,6 @@
|
|||
Nothing here?!
|
||||
{% endblock main_content %}
|
||||
</div>
|
||||
{% include "partials/footer.html" %}
|
||||
|
||||
{# Add KaTeX functionality (loads CSS and JS) #}
|
||||
{%- if config.extra.katex and config.extra.katex == true or page.extra.katex and page.extra.katex == true -%}
|
||||
<link rel="stylesheet" href="{{ get_url(path='katex.min.css', trailing_slash=false) | safe }}">
|
||||
<script defer src="{{ get_url(path='js/katex.min.js', trailing_slash=false) | safe }}"></script>
|
||||
{%- endif -%}
|
||||
|
||||
{# Add copy button to codeblocks #}
|
||||
{%- if config.extra.copy_button and config.extra.copy_button == true or page.extra.copy_button and page.extra.copy_button == true -%}
|
||||
<script defer src="{{ get_url(path='js/copyCodeToClipboard.min.js', trailing_slash=false) | safe }}"/></script>
|
||||
{%- endif -%}
|
||||
|
||||
{# Add backlinks to footnotes #}
|
||||
{%- if config.extra.footnote_backlinks and config.extra.footnote_backlinks == true or page.extra.footnote_backlinks and page.extra.footnote_backlinks == true -%}
|
||||
<script defer src="{{ get_url(path='js/footnoteBacklinks.min.js', trailing_slash=false | safe )}}"/></script>
|
||||
{%- endif -%}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -10,6 +10,42 @@
|
|||
{%- set blank_target = "" -%}
|
||||
{%- endif -%}
|
||||
|
||||
{# Debugging #}
|
||||
{# {% set last_ancestor = page.ancestors | slice(start=-1) %}
|
||||
{% set current_section = get_section(path=last_ancestor.0) %}
|
||||
|
||||
{% set settings_to_test = [
|
||||
"footnote_backlinks",
|
||||
"katex",
|
||||
"quick_navigation_buttons",
|
||||
"show_reading_time",
|
||||
"show_remote_changes"
|
||||
] %}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>setting</th>
|
||||
<th>page</th>
|
||||
<th>section</th>
|
||||
<th>config</th>
|
||||
<th>macro output</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for setting in settings_to_test %}
|
||||
<tr>
|
||||
<td><code>{{ setting }}</code></td>
|
||||
<td>{{ page.extra[setting] | default(value="⬛") }}</td>
|
||||
<td>{{ current_section.extra[setting] | default(value="⬛") }}</td>
|
||||
<td>{{ config.extra[setting] | default(value="⬛") }}</td>
|
||||
<td>{{ macros_settings::evaluate_setting_priority(setting=setting, page=page) }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table> #}
|
||||
{# End debugging #}
|
||||
|
||||
<main>
|
||||
<article>
|
||||
<div class="article-title">
|
||||
|
@ -26,7 +62,7 @@
|
|||
{% endif %}
|
||||
|
||||
{# page settings override config settings #}
|
||||
{% if page.extra.show_reading_time | default(value="") == true or page.extra.show_reading_time | default(value="") != false and config.extra.show_reading_time | default(value=true) %}
|
||||
{% if macros_settings::evaluate_setting_priority(setting="show_reading_time", page=page, default_global_value=true) == "true" %}
|
||||
{{ separator }} <li title="{{ page.word_count }} {%- if lang != config.default_language %} {{ trans(key="words" | safe, lang=lang) }} {% else %} words {% endif %}">{{ page.reading_time }}{%- if lang != config.default_language %} {{ trans(key="min_read" | safe, lang=lang) }} {% else %} min read {% endif %}</li>
|
||||
{% endif %}
|
||||
|
||||
|
@ -44,8 +80,7 @@
|
|||
{% if page.updated %}
|
||||
</ul><ul class="meta last-updated"><li>{%- if lang != config.default_language %} {{ trans(key="last_updated_on" | safe, lang=lang) }} {% else %} Last updated on {% endif %} {{ macros_format_date::format_date(date=page.updated, short=true) }}</li>
|
||||
{# Show link to remote changes if enabled #}
|
||||
{% set show_remote_changes = config.extra.show_remote_changes | default(value=true) %}
|
||||
{% if config.extra.remote_repository_url and show_remote_changes %}
|
||||
{% if config.extra.remote_repository_url and macros_settings::evaluate_setting_priority(setting="show_remote_changes", page=page, default_global_value=true) == "true" %}
|
||||
<li> {{ separator }} <a href="{{ macros_create_history_url::create_history_url(relative_path=page.relative_path) }}" {{ blank_target }} rel="{{ rel_attributes }}">{%- if lang != config.default_language -%}{{ trans(key="see_changes" | safe, lang=lang) }}{% else %}See changes{%- endif -%}<small> ↗</small></a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -110,7 +145,8 @@
|
|||
</article>
|
||||
</main>
|
||||
|
||||
{% if config.extra.quick_navigation_buttons or page.extra.quick_navigation_buttons %}
|
||||
{# Quick navigation buttons #}
|
||||
{% if macros_settings::evaluate_setting_priority(setting="quick_navigation_buttons", page=page, default_global_value=false) == "true" %}
|
||||
<div id="button-container">
|
||||
{# Button to go show a floating Table of Contents #}
|
||||
{% if page.toc %}
|
||||
|
@ -140,4 +176,20 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Add KaTeX functionality #}
|
||||
{%- if macros_settings::evaluate_setting_priority(setting="katex", page=page, default_global_value=false) == "true" -%}
|
||||
<link rel="stylesheet" href="{{ get_url(path='katex.min.css', trailing_slash=false) | safe }}">
|
||||
<script defer src="{{ get_url(path='js/katex.min.js', trailing_slash=false) | safe }}"></script>
|
||||
{%- endif -%}
|
||||
|
||||
{# Add copy button to code blocks #}
|
||||
{%- if macros_settings::evaluate_setting_priority(setting="copy_button", page=page, default_global_value=true) == "true" -%}
|
||||
<script defer src="{{ get_url(path='js/copyCodeToClipboard.min.js', trailing_slash=false) | safe }}"/></script>
|
||||
{%- endif -%}
|
||||
|
||||
{# Add backlinks to footnotes #}
|
||||
{%- if macros_settings::evaluate_setting_priority(setting="footnote_backlinks", page=page, default_global_value=false) == "true" -%}
|
||||
<script defer src="{{ get_url(path='js/footnoteBacklinks.min.js', trailing_slash=false | safe )}}"/></script>
|
||||
{%- endif -%}
|
||||
|
||||
{% endmacro content %}
|
||||
|
|
40
templates/macros/settings.html
Normal file
40
templates/macros/settings.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
{#
|
||||
Evaluates the priority of a particular setting across different scopes.
|
||||
|
||||
The priority is as follows: page > section > config.
|
||||
|
||||
Parameters:
|
||||
- setting: The name of the setting to evaluate.
|
||||
- page: The page object containing settings.
|
||||
- default_global_value: The setting's default value.
|
||||
#}
|
||||
|
||||
{% macro evaluate_setting_priority(setting, page) %}
|
||||
|
||||
{#- Retrieve last ancestor to determine current section, if applicable -#}
|
||||
{%- if page -%}
|
||||
{%- set last_ancestor = page.ancestors | slice(start=-1) %}
|
||||
{%- set current_section = get_section(path=last_ancestor.0) %}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set priority_order = [
|
||||
page.extra[setting] | default(value=""),
|
||||
current_section.extra[setting] | default(value=""),
|
||||
config.extra[setting] | default(value=default_global_value)
|
||||
] -%}
|
||||
|
||||
{%- set output = "false" -%}
|
||||
|
||||
{%- for value in priority_order -%}
|
||||
{%- if value == true -%}
|
||||
{%- set_global output = "true" -%}
|
||||
{%- break -%}
|
||||
{%- elif value == false -%}
|
||||
{%- set_global output = "false" -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{{- output -}}
|
||||
|
||||
{% endmacro %}
|
|
@ -85,9 +85,8 @@
|
|||
{%- endif -%}
|
||||
<a rel="{{ rel_attributes }}" {{ blank_target }} href="https://github.com/welpo/tabi">tabi</a>
|
||||
|
||||
{# Shows link to remote repository if repository is set and `show_remote_source` is not false #}
|
||||
{% set show_source = config.extra.show_remote_source | default(value=true) %}
|
||||
{%- if config.extra.remote_repository_url and show_source -%}
|
||||
{# Shows link to remote repository #}
|
||||
{%- if config.extra.remote_repository_url and config.extra.show_remote_source | default(value=true) -%}
|
||||
{{ separator }}
|
||||
<a rel="{{ rel_attributes }}" {{ blank_target }} href="{{ config.extra.remote_repository_url }}">
|
||||
{%- if lang != config.default_language -%}
|
||||
|
|
44
theme.toml
44
theme.toml
|
@ -27,20 +27,6 @@ homepage = "https://osc.garden"
|
|||
# language_name.en = "English"
|
||||
# language_name.es = "Español"
|
||||
|
||||
# Remote repository for your Zola site.
|
||||
# Used for `show_remote_changes` and `show_remote_source` (see below).
|
||||
# Supports GitHub, GitLab, Gitea, and Codeberg.
|
||||
# remote_repository_url = "https://github.com/welpo/tabi"
|
||||
# Set this to "auto" to try and auto-detect the platform based on the repository URL.
|
||||
# Accepted values are "github", "gitlab", "gitea", and "codeberg".
|
||||
remote_repository_git_platform = "auto" # Defaults to "auto".
|
||||
# Branch in the repo hosting the Zola site.
|
||||
remote_repository_branch = "main" # Defaults to "main".
|
||||
# Show a link to the commit history of updated posts, right next to the last updated date.
|
||||
show_remote_changes = true # Defaults to true.
|
||||
# Show a link to the repository of the site, right next to the "Powered by Zola & tabi" text.
|
||||
show_remote_source = true # Defaults to true.
|
||||
|
||||
# Enable JavaScript theme toggler to allow users to switch between dark/light mode.
|
||||
# Also enables automatic switching based on user's OS-level theme settings.
|
||||
# If disabled, your site will only use the theme specified in the `default_theme` variable.
|
||||
|
@ -67,19 +53,42 @@ skin = ""
|
|||
# You can load a stylesheet for a single post by adding it to the [extra] section of the post's front matter, following this same format.
|
||||
stylesheets = []
|
||||
|
||||
# Remote repository for your Zola site.
|
||||
# Used for `show_remote_changes` and `show_remote_source` (see below).
|
||||
# Supports GitHub, GitLab, Gitea, and Codeberg.
|
||||
# remote_repository_url = "https://github.com/welpo/tabi"
|
||||
# Set this to "auto" to try and auto-detect the platform based on the repository URL.
|
||||
# Accepted values are "github", "gitlab", "gitea", and "codeberg".
|
||||
remote_repository_git_platform = "auto" # Defaults to "auto".
|
||||
# Branch in the repo hosting the Zola site.
|
||||
remote_repository_branch = "main" # Defaults to "main".
|
||||
# Show a link to the commit history of updated posts, right next to the last updated date.
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
show_remote_changes = true # Defaults to true.
|
||||
# Show a link to the repository of the site, right next to the "Powered by Zola & tabi" text.
|
||||
show_remote_source = true # Defaults to true.
|
||||
|
||||
# Add a "copy" button to codeblocks (loads ~700 bytes of JavaScript).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
copy_button = true
|
||||
|
||||
# Show the reading time of a page.
|
||||
# Can also be enabled or disabled on individual pages in the front matter's [extra].
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
show_reading_time = true
|
||||
|
||||
# Adds backlinks to footnotes (loads ~500 bytes of JavaScripts).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
footnote_backlinks = false
|
||||
|
||||
# Enable KaTeX for all posts.
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
katex = false
|
||||
|
||||
# Quick navigation buttons.
|
||||
# Adds "go up" and "go to comments" buttons on the bottom right (hidden for mobile).
|
||||
# Can be set at page or section levels, following the hierarchy: page > section > config. See: https://github.com/welpo/tabi/pull/128
|
||||
quick_navigation_buttons = false
|
||||
|
||||
# Date format used when listing posts (main page, /blog section, tag posts list…)
|
||||
# Default is "6th July 2049" in English and "%d %B %Y" in other languages.
|
||||
# long_date_format = "%d %B %Y"
|
||||
|
@ -158,11 +167,6 @@ allowed_domains = [
|
|||
# Please see https://welpo.github.io/tabi/blog/custom-font-subset/ to learn how to create this file.
|
||||
# custom_subset = true
|
||||
|
||||
# Quick navigation buttons.
|
||||
# Adds "go up" and "go to comments" buttons on the bottom right (hidden for mobile).
|
||||
# Can also be enabled on individual posts in the front matter's [extra].
|
||||
# quick_navigation_buttons = true
|
||||
|
||||
# giscus support for comments. https://giscus.app
|
||||
# Setup instructions: https://welpo.github.io/tabi/blog/comments/#setup
|
||||
[extra.giscus]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue