diff --git a/sass/duniter.sass b/sass/duniter.sass index 63014285c350622fa99812f231f8fa9fd6451f95..c89f05826999c1876d2995d79828012bfc704f96 100644 --- a/sass/duniter.sass +++ b/sass/duniter.sass @@ -38,7 +38,7 @@ a:hover .toc background: #f7f7f7 - padding: 0 2em 2em 2em + padding: 0 2em 0em 2em border-left: 5px solid #41B3FF display: inline-block ol.h2 @@ -48,4 +48,8 @@ a:hover ol.h4 list-style-type: lower-alpha ol.h5 - list-style-type: circle \ No newline at end of file + list-style-type: circle + +img.icon + height: 1em + margin-bottom: 0.2em \ No newline at end of file diff --git a/templates/macros.html b/templates/macros.html index c471ff5d60d979126b155a57fe802c3d88c36460..de6e4f68920092cb3fd4a0680baa8bdb9cbe71b1 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -1,4 +1,6 @@ -{# === KATEX ===#} +{# ============= #} +{# === KATEX === #} +{# ============= #} {% macro katex() %} <link rel="stylesheet" href="/katex/katex.css"> <script defer src="/katex/katex.js"></script> @@ -15,7 +17,54 @@ </script> {% endmacro katex %} + +{# =========================== #} {# === resize static image === #} +{# =========================== #} {% macro resize_static(path, width=160, height=160, op="fit_height") %} {{ resize_image(path="../static" ~ path, width=width, height=height, op=op) }} -{% endmacro resize_static %} \ No newline at end of file +{% endmacro resize_static %} + + +{# ========================= #} +{# === table of contents === #} +{# ========================= #} +{% macro toc(toc, level, depth) %} +{%- if level == 1 %} +<div class="toc"> +<h3>Table des matières</h3> +{%- endif %} +{%- if level != 1 %} +<ol class="h{{ level }}"> +{%- endif %} +{%- for h in toc %} + {%- if level != 1 %} + <li> + <a href="{{ h.permalink | safe }}">{{ h.title }}</a> + {%- endif %} + {% if h.children and level <= depth -%} + {{ self::toc(toc=h.children, level=level+1, depth=depth, heading=false) }} + {%- endif %} + {%- if level != 1 %} + </li> + {%- endif %} + {%- endfor %} +{%- if level != 1 %} +</ol> +{%- endif %} +{%- if level == 1 %} +</div> +{%- endif %} +{%- endmacro %} + + +{# =================== #} +{# === replace toc === #} +{# =================== #} +{% macro replace_toc(resource) %} + {%- set content = resource.content %} + {%- if content is containing("[TOC]") %} + {%- set content = content | replace(from="[TOC]", to=self::toc(toc=resource.toc, level=1, depth=resource.extra.toc_depth | default(value=6))) %} + {%- endif -%} + {{ content | safe }} +{%- endmacro %} diff --git a/templates/nav.html b/templates/nav.html index a20e7add1303c4544ade160dc54217c0106a5008..d8a41a58b78b9394311998c80c00a726cd7473ee 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -2,11 +2,11 @@ <a href="/" class="w3-bar-item w3-button w3-mobile {% if current_path %}{% if current_path == "/" %}active{% endif %}{% endif %}"><img src="/img/duniter.png" width="32px"/> Duniter</a> {% set index = get_section(path="_index.md") %} - {% for page in index.pages %} - {% if not page.extra.hide %} - <a href="{{ page.permalink }}" class="w3-bar-item w3-button w3-mobile - {% if current_path %}{% if current_path == page.path %}active{% endif %}{% endif %}"> - {{page.title}} + {% for p in index.pages %} + {% if not p.extra.hide %} + <a href="{{ p.permalink }}" class="w3-bar-item w3-button w3-mobile + {% if current_path %}{% if current_path == p.path %}active{% endif %}{% endif %}"> + {{p.title}} </a> {% endif %} {% endfor %} @@ -17,7 +17,7 @@ <div class="w3-dropdown-content w3-bar-block w3-dark-grey"> <a href="/about/" class="w3-bar-item w3-button w3-mobile">À propos</a> <a href="https://git.duniter.org/" class="w3-bar-item w3-button w3-mobile"><i class="fa fa-gitlab"></i> GitLab</a> - <a href="https://forum.duniter.org/" class="w3-bar-item w3-button w3-mobile"><i class="fa fa-discourse"></i> Forum</a> + <a href="https://forum.duniter.org/" class="w3-bar-item w3-button w3-mobile"><img class="icon" src="https://simpleicons.org/icons/discourse.svg"/> Forum</a> </div> </div> diff --git a/templates/page.html b/templates/page.html index cd49946123090e1fe4b6f0a4289fb6095fb9731b..eb4786ed6d029d45370b6102b8549a37ecf150d2 100644 --- a/templates/page.html +++ b/templates/page.html @@ -11,12 +11,6 @@ {% block content %} <main class="page w3-container w3-content w3-padding-64"> - - {% if not page.extra.toc %} - {% set toc = page.toc %} - {% include "toc.html" %} - {% endif %} - - {{ page.content | safe }} + {{ macros::replace_toc(resource=page) | safe }} </main> {% endblock content %} diff --git a/templates/section.html b/templates/section.html index a275488fe51f4d277eddc1c9ed7174f8f0d313a6..299afe21a0b680d56c8881a81db03825d9fedde2 100644 --- a/templates/section.html +++ b/templates/section.html @@ -2,16 +2,12 @@ {% block content %} <main class="w3-container w3-margin-mobile"> + {# ===== content ===== #} <div class="page w3-container w3-content w3-padding-64"> - - {% if not section.extra.toc %} - {% set toc = section.toc %} - {% include "toc.html" %} - {% endif %} - - {{ section.content | safe }} + {{ macros::replace_toc(resource=section) | safe }} </div> + {# ===== child pages and sections ===== #} {% if not section.extra.list_pages %} <hr> <h2>PAGES</h2> @@ -31,3 +27,6 @@ </main> {% endblock content %} + + +{{ macros::format_content(resource=section) }} \ No newline at end of file diff --git a/templates/toc.html b/templates/toc.html deleted file mode 100644 index 4312e7fd60bb3ead5b2855e2161e3fcc66cd3727..0000000000000000000000000000000000000000 --- a/templates/toc.html +++ /dev/null @@ -1,30 +0,0 @@ -<ol class="toc"> -<h2>Table des matières</h2> -{% for h1 in toc %} -{# <li><a href="{{h1.permalink | safe}}">{{ h1.title }}</a> #} -{% if h1.children %} -<ol class="h2"> - {% for h2 in h1.children %} - <li><a href="{{h2.permalink | safe}}">{{ h2.title }}</a> - {% if h2.children %} - <ol class="h3"> - {% for h3 in h2.children %} - <li><a href="{{h3.permalink | safe}}">{{ h3.title }}</a> - {% if h3.children %} - <ol class="h4"> - {% for h4 in h3.children %} - <li><a href="{{h4.permalink | safe}}">{{ h4.title }}</a></li> - {% endfor %} - </ol> - {% endif %} - </li> - {% endfor %} - </ol> - {% endif %} - </li> - {% endfor %} -</ol> -{% endif %} -</li> -{% endfor %} -</ol> \ No newline at end of file