feat(settings): allow overriding settings following hierarchy

Hierarchy: page > section > config.
This commit is contained in:
welpo 2023-09-01 02:00:45 +02:00
parent b58225a012
commit 4e1ad5232e
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
6 changed files with 147 additions and 64 deletions

View 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 %}