✨ feat: add series functionality (#406)
Co-authored-by: welpo <welpo@users.noreply.github.com>
This commit is contained in:
@@ -180,6 +180,33 @@ Current section extra: {% if current_section %}{{ current_section.extra | json_e
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
{#- A page is part of a series if one of the sections above (whether it is transparent or not) has the `extra.series` parameter set to true. -#}
|
||||
{#- As a series might be a transparent section in order to mix up its articles with those of the section just above or the root, -#}
|
||||
{#- there is no other way but to compute the potential path of each ancestor section related to the page and look for the first one being a series. -#}
|
||||
{#- Using the `ancestors` field of a section is not possible because transparent sections are not present in this field. -#}
|
||||
{%- set current_path = [] -%}
|
||||
{%- set section_paths = [] -%}
|
||||
{%- for path in page.relative_path | split(pat="/") | slice(end=-1) -%}
|
||||
{%- set_global current_path = current_path | concat(with=path) -%}
|
||||
{%- set section_path = current_path | concat(with="_index.md") | join(sep="/") -%}
|
||||
{%- set_global section_paths = section_paths | concat(with=section_path) -%}
|
||||
{%- endfor -%}
|
||||
{#- The series the page is part of is the closest section flagged as a series, if any -#}
|
||||
{%- for section_path in section_paths | reverse -%}
|
||||
{%- set section_file_exists = load_data(path=section_path, required=false) -%}
|
||||
{%- if section_file_exists -%}
|
||||
{%- set loaded_section = get_section(path=section_path,lang=lang) -%}
|
||||
{%- if "series" in loaded_section.extra and loaded_section.extra.series -%}
|
||||
{%- set_global series_section = loaded_section -%}
|
||||
{%- set_global series_ordered_pages = loaded_section.pages -%}
|
||||
{%- if loaded_section.paginated | default(value=0) > 0 and loaded_section.paginate_reversed -%}
|
||||
{%- set_global series_ordered_pages = loaded_section.pages | reverse -%}
|
||||
{%- endif -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{% if page.extra.tldr %}
|
||||
<div class="admonition note">
|
||||
<div class="admonition-icon admonition-icon-note"></div>
|
||||
@@ -192,18 +219,48 @@ Current section extra: {% if current_section %}{{ current_section.extra | json_e
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Optional table of contents below the header #}
|
||||
{#- Optional table of contents below the header -#}
|
||||
{% if page.toc and macros_settings::evaluate_setting_priority(setting="toc", page=page, default_global_value=false) == "true" %}
|
||||
{{ macros_toc::toc(page=page, header=true, language_strings=language_strings) }}
|
||||
{% endif %}
|
||||
|
||||
<section class="body">
|
||||
{# The replace pattern is used to enable arbitrary locations for the Table of Contents #}
|
||||
{# This is Philipp Oppermann's workaround: https://github.com/getzola/zola/issues/584#issuecomment-474329637 #}
|
||||
{{ page.content | replace(from="<!-- toc -->", to=macros_toc::toc(page=page, header=false, language_strings=language_strings)) | safe }}
|
||||
{#- Replace series_intro placeholder -#}
|
||||
{%- set content_with_intro = page.content -%}
|
||||
{%- if "<!-- series_intro -->" in page.content -%}
|
||||
{%- set series_intro_html = macros_series_page::get_introduction(page=page, series_section=series_section, series_ordered_pages=series_ordered_pages, language_strings=language_strings) -%}
|
||||
{%- set content_with_intro = content_with_intro | replace(from="<!-- series_intro -->", to=series_intro_html) -%}
|
||||
{%- elif series_section -%}
|
||||
{%- set series_intro_html = macros_series_page::get_introduction(page=page, series_section=series_section, series_ordered_pages=series_ordered_pages, language_strings=language_strings) -%}
|
||||
{%- set content_with_intro = series_intro_html ~ content_with_intro -%}
|
||||
{%- endif -%}
|
||||
|
||||
{#- Handle series_outro placeholder -#}
|
||||
{%- set processed_content = content_with_intro -%}
|
||||
{%- if "<!-- series_outro -->" in content_with_intro -%}
|
||||
{%- set series_outro_html = macros_series_page::get_outro(page=page, series_section=series_section, series_ordered_pages=series_ordered_pages, language_strings=language_strings) -%}
|
||||
{%- set processed_content = processed_content | replace(from="<!-- series_outro -->", to=series_outro_html) -%}
|
||||
{%- elif series_section -%}
|
||||
{%- set series_outro_html = macros_series_page::get_outro(page=page, series_section=series_section, series_ordered_pages=series_ordered_pages, language_strings=language_strings) -%}
|
||||
{#- We want the outro at the end of the article, but before footnote definitions -#}
|
||||
{%- set footnotes_marker = '<hr><ol class="footnotes-list">' -%}
|
||||
{%- if footnotes_marker in content_with_intro -%}
|
||||
{%- set content_sections = processed_content | split(pat=footnotes_marker) -%}
|
||||
{%- set main_content = content_sections | first -%}
|
||||
{%- set footnotes_content = content_sections | slice(start=1) | join(sep=footnotes_marker) -%}
|
||||
{%- set processed_content = main_content ~ series_outro_html ~ footnotes_marker ~ footnotes_content -%}
|
||||
{%- else -%}
|
||||
{%- set processed_content = processed_content ~ series_outro_html -%}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
|
||||
{#- Replace TOC and render final content -#}
|
||||
{#- The replace pattern is used to enable arbitrary locations for the Table of Contents -#}
|
||||
{#- This is Philipp Oppermann's workaround: https://github.com/getzola/zola/issues/584#issuecomment-474329637 -#}
|
||||
{{ processed_content | replace(from="<!-- toc -->", to=macros_toc::toc(page=page, header=false, language_strings=language_strings)) | safe }}
|
||||
</section>
|
||||
|
||||
{# Check if comments are enabled, checking that they are not disabled on the specific page #}
|
||||
{#- Check if comments are enabled, checking that they are not disabled on the specific page -#}
|
||||
{% set systems = ["giscus", "utterances", "hyvortalk", "isso"] %}
|
||||
{% set enabled_systems = 0 %}
|
||||
{% set comment_system = "" %}
|
||||
@@ -219,11 +276,6 @@ Current section extra: {% if current_section %}{{ current_section.extra | json_e
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{# Ensure only one comment system is enabled #}
|
||||
{% if enabled_systems > 1 %}
|
||||
{{ throw(message="ERROR: Multiple comment systems have been enabled for the same page. Check your config.toml and individual page settings to ensure only one comment system is activated at a time.") }}
|
||||
{% endif %}
|
||||
|
||||
{% if macros_settings::evaluate_setting_priority(setting="show_previous_next_article_links", page=page, default_global_value=true) == "true" %}
|
||||
{%- if page.lower or page.higher -%}
|
||||
{% set next_label = macros_translate::translate(key="next", default="Next", language_strings=language_strings) %}
|
||||
@@ -271,7 +323,11 @@ Current section extra: {% if current_section %}{{ current_section.extra | json_e
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
|
||||
{# Comments #}
|
||||
{#- Comments -#}
|
||||
{#- Ensure only one comment system is enabled -#}
|
||||
{% if enabled_systems > 1 %}
|
||||
{{ throw(message="ERROR: Multiple comment systems have been enabled for the same page. Check your config.toml and individual page settings to ensure only one comment system is activated at a time.") }}
|
||||
{% endif %}
|
||||
{% if comment_system %}
|
||||
{% include "partials/comments.html" %}
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user