summaryrefslogtreecommitdiff
path: root/sysret.org/themes/tabi-lean/templates/macros/settings.html
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
committerAlejandro Soto <alejandro@34project.org>2025-09-13 15:01:06 -0600
commitf4fcda54638685899c730b3fa90a87d80d6dbef5 (patch)
tree0737e627cce304c3a9c4e757bc5f6571a7456091 /sysret.org/themes/tabi-lean/templates/macros/settings.html
parentd8b9cf1f61cc07d625f1c37ccc28adfd58918416 (diff)
parent2c13119932765c6d788f08fb53abc244407c0d80 (diff)
Merge commit '6a7d3111b31e73fc66af5360149d41f690fbcaa4'
Diffstat (limited to 'sysret.org/themes/tabi-lean/templates/macros/settings.html')
-rw-r--r--sysret.org/themes/tabi-lean/templates/macros/settings.html68
1 files changed, 68 insertions, 0 deletions
diff --git a/sysret.org/themes/tabi-lean/templates/macros/settings.html b/sysret.org/themes/tabi-lean/templates/macros/settings.html
new file mode 100644
index 0000000..d237d7a
--- /dev/null
+++ b/sysret.org/themes/tabi-lean/templates/macros/settings.html
@@ -0,0 +1,68 @@
+{#
+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, section="", default_global_value="") %}
+
+{%- if section -%}
+ {%- set current_section = section -%}
+{%- elif page -%}
+ {%- set current_section = "" -%}
+ {#- Retrieve last ancestor to determine current section, if applicable -#}
+ {%- if page.ancestors | length > 0 -%}
+ {%- set last_ancestor = page.ancestors | slice(start=-1) -%}
+ {%- set_global current_section = get_section(path=last_ancestor.0, metadata_only=true) -%}
+ {%- else -%}
+ {#- We're likely in a nested page. Try to find the parent page or nearest section. -#}
+ {%- set components = page.components -%}
+ {%- for i in range(start=1, end=components | length) -%}
+ {%- if lang == config.default_language -%}
+ {%- set potential_path = components | slice(end=components | length - i) | join(sep="/") -%}
+ {%- set potential_page = potential_path ~ "/index.md" -%}
+ {%- set potential_section = potential_path ~ "/_index.md" -%}
+ {%- else -%}
+ {%- set potential_path = components | slice(start=1, end=components | length - i) | join(sep="/") -%}
+ {%- set potential_page = potential_path ~ "/index." ~ lang ~ ".md" -%}
+ {%- set potential_section = potential_path ~ "/_index." ~ lang ~ ".md" -%}
+ {%- endif -%}
+ {#- Check for parent page first. -#}
+ {%- set page_data = load_data(path=potential_page, required=false) -%}
+ {%- if page_data -%}
+ {%- set_global current_section = get_page(path=potential_page) -%}
+ {%- break -%}
+ {%- endif -%}
+ {#- No parent page, check for section. -#}
+ {%- set section_data = load_data(path=potential_section, required=false) -%}
+ {%- if section_data -%}
+ {%- set_global current_section = get_section(path=potential_section, metadata_only=true) -%}
+ {%- break -%}
+ {%- endif -%}
+ {%- endfor -%}
+ {%- endif -%}
+{%- endif -%}
+
+{%- set priority_order = [
+ page.extra[setting] | default(value=""),
+ current_section.extra[setting] | default(value=""),
+ config.extra[setting] | default(value="")
+] -%}
+
+{%- set output = default_global_value -%}
+
+{%- for value in priority_order -%}
+ {%- if value != "" -%}
+ {%- set_global output = value -%}
+ {%- break -%}
+ {%- endif -%}
+{%- endfor -%}
+
+{{- output -}}
+
+{% endmacro %}