From 548aecf9e307d10dca0f1b7e44ffdd04b9d5d87b Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Thu, 25 Jun 2020 16:10:24 +0200 Subject: [PATCH] Feat: toctree based on categories --- pelicanconf.py | 8 +++++- theme/templates/base.html | 3 ++ theme/templates/partial/toctree.html | 41 ++++++++++------------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/pelicanconf.py b/pelicanconf.py index dc351b1..40b578b 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -48,6 +48,9 @@ PLUGINS = [ PATH_METADATA = '(?P.*)\..*' ARTICLE_URL = ARTICLE_SAVE_AS = PAGE_URL = PAGE_SAVE_AS = '{path_no_ext}.html' +# USE_FOLDER_AS_CATEGORY = True +# DEFAULT_CATEGORY = "Autre" + # Readers READERS = {"html": None} # Everythings in french @@ -63,10 +66,13 @@ LOCALE = ("fr", "fr_FR.utf8") THEME = "./theme/" USE_GOOGLE_FONTS = False -DISPLAY_PAGES_ON_SIDE = False +# Main menu on the top MAIN_MENU = True DISPLAY_CATEGORIES_ON_MENU = False + +# Sidebar +DISPLAY_PAGES_ON_SIDE = False TOCTREE = True #SITELOGO = "" diff --git a/theme/templates/base.html b/theme/templates/base.html index 6277912..3561d12 100644 --- a/theme/templates/base.html +++ b/theme/templates/base.html @@ -86,7 +86,9 @@
diff --git a/theme/templates/partial/toctree.html b/theme/templates/partial/toctree.html index 297a0c4..a516fab 100644 --- a/theme/templates/partial/toctree.html +++ b/theme/templates/partial/toctree.html @@ -1,34 +1,21 @@ -{% macro toc(root) %}
    - {% for child in root.children %} - {% if child == article or child in article.parents%} -
  • {{ child.title }} - {% if child.children %} -
      - {% for c in child.children %} - {% if c == article %} -
    • {{ c.title }}
    • - {% else %} -
    • {{ c.title }}
    • - {% endif %} - {% endfor %} -
    - {% endif %} + {% for cat, articles in categories|sort %} + {% if article and article.category == cat %} +
  • {{ cat | capitalize }} +
      + {% for art in articles | sort(attribute="date") %} + {% if article == art %} +
    • {{ art.title }}
    • {% else %} -
    • {{ child.title }}
    • +
    • {{ art.title }}
    • {% endif %} - + {% endfor %} +
    +
  • + {% else %} +
  • {{ cat | capitalize }} + {% endif %} {% endfor %}
-{% endmacro %} -{% if 'pelican-page-hierarchy' in PLUGINS and TOCTREE %} - {% if article and article.parents %} - {{ toc(article.parents[0]) }} - {% elif article and not article.parent %} - {{ toc(article) }} - {% else %} -

Le menu s'est perdu

- {% endif %} -{% endif %}