From 864a89104bd444fbebb9dcbe3ed853c28f8b21e7 Mon Sep 17 00:00:00 2001 From: Jieiku Date: Tue, 20 Sep 2022 17:34:19 -0700 Subject: Fix index generation when all pages in a section are drafts, closes #93 --- templates/macros/create_stork_toml.html | 5 +++-- templates/macros/create_tinysearch_json.html | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'templates/macros') diff --git a/templates/macros/create_stork_toml.html b/templates/macros/create_stork_toml.html index 642b3f9..f754e2e 100644 --- a/templates/macros/create_stork_toml.html +++ b/templates/macros/create_stork_toml.html @@ -2,13 +2,14 @@ {%- set section = get_section(path=section) -%} {%- for post in section.pages -%} {%- if not post.draft %} {path = {{ '.' ~ post.path ~ 'index.html' | json_encode | safe }}, url = {{ post.permalink | json_encode | safe }}, title = {{ post.title | striptags | json_encode | safe }}} +{%- set found = true -%} {%- if not loop.last -%}, {% endif -%} {%- endif -%} {%- endfor -%} -{%- if section.subsections -%}, +{%- if found -%}{%- if section.subsections -%}, {% for subsection in section.subsections -%} {{ self::from_section(section=subsection) }} {%- endfor -%} -{%- endif -%} +{%- endif -%}{%- endif -%} {%- endmacro from_section -%} \ No newline at end of file diff --git a/templates/macros/create_tinysearch_json.html b/templates/macros/create_tinysearch_json.html index f45ed42..a28d9dc 100644 --- a/templates/macros/create_tinysearch_json.html +++ b/templates/macros/create_tinysearch_json.html @@ -2,6 +2,7 @@ {%- set section = get_section(path=section) -%} {%- for post in section.pages -%} {%- if not post.draft -%} +{%- set found = true -%} { "title": {{ post.title | striptags | json_encode | safe }}, "url": {{ post.permalink | json_encode | safe }}, @@ -17,10 +18,10 @@ {%- if not loop.last -%},{%- endif %} {%- endif -%} {%- endfor -%} -{%- if section.subsections -%} +{%- if found -%}{%- if section.subsections -%} , {%- for subsection in section.subsections -%} {{ self::from_section(section=subsection) }} {%- endfor -%} -{%- endif -%} +{%- endif -%}{%- endif -%} {%- endmacro from_section -%} \ No newline at end of file -- cgit v1.3.1