Skip to content
Snippets Groups Projects
Commit 8ce00eb0 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

table des matières

la table des matières est désormais déclarée directement avec [TOC]
parent c522c251
No related branches found
No related tags found
No related merge requests found
......@@ -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
{# === 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 %}
......@@ -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>
......
......@@ -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 %}
......@@ -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
<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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment