mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Add the auto-generated node catalog to the website's user manual (#3662)
* Generate the MVP node catalog in the manual (with some placeholders) * Implement nearly the rest of everything * Move to the tools directory and make it generate nicer default values * Add category descriptions * Organize file structure and improve type naming * Improve book table of contents code * Add collapsing chapter navigation to the book template * Add to build workflow * Clean up site structure
This commit is contained in:
@@ -1,38 +1,52 @@
|
||||
{% extends "base.html" %}
|
||||
{% import "macros/book-outline.html" as book_outline %}
|
||||
|
||||
{%- block head -%}{%- set page = page | default(value = section) -%}
|
||||
{%- set title = page.title -%}
|
||||
{%- set meta_article_type = true -%}
|
||||
{%- set meta_description = page.extra.summary | default(value = page.content | striptags | safe | linebreaksbr | replace(from = "<br>", to = " ") | replace(from = " ", to = " ") | trim | truncate(length = 200)) -%}
|
||||
{%- set css = ["/template/book.css", "/layout/reading-material.css", "/component/code-snippet.css"] -%}
|
||||
{%- set js = ["/js/book.js"] -%}
|
||||
{%- set js = ["/js/template/book.js"] -%}
|
||||
{%- endblock head -%}
|
||||
|
||||
{%- block content -%}{%- set page = page | default(value = section) -%}
|
||||
|
||||
{# Search this page-or-section's ancestor tree for a section that identifies itself as a book, and save it to a `book` variable #}
|
||||
{% for ancestor_path in page.ancestors | concat(with = page.relative_path) %}
|
||||
{# Get the ancestor section from this ancestor path string #}
|
||||
{% if ancestor_path is ending_with("/_index.md") %}
|
||||
{% set potential_book = get_section(path = ancestor_path) %}
|
||||
{% endif %}
|
||||
{#- Search this page-or-section's ancestor tree for a section that identifies itself as a book, and save it to a `book` variable -#}
|
||||
{%- for ancestor_path in page.ancestors | concat(with = page.relative_path) -%}
|
||||
{#- Get the ancestor section from this ancestor path string -#}
|
||||
{%- if ancestor_path is ending_with("/_index.md") -%}
|
||||
{%- set potential_book = get_section(path = ancestor_path) -%}
|
||||
{%- endif -%}
|
||||
|
||||
{# Check if the ancestor section is the root of a book, and if so, set it to a variable accessible outside the loop #}
|
||||
{% if potential_book.extra.book %}
|
||||
{% set_global book = get_section(path = potential_book.path ~ "_index.md" | trim_start_matches(pat="/")) %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{#- Check if the ancestor section is the root of a book, and if so, set it to a variable accessible outside the loop -#}
|
||||
{%- if potential_book.extra.book -%}
|
||||
{%- set_global book = get_section(path = potential_book.path ~ "_index.md" | trim_start_matches(pat = "/")) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
{# Map this book's chapter path strings to an array of sections #}
|
||||
{% set chapters = [] %}
|
||||
{% for chapter_path in book.subsections %}
|
||||
{% set_global chapters = chapters | concat(with = get_section(path = chapter_path)) %}
|
||||
{% endfor %}
|
||||
{% set chapters = chapters | sort(attribute = "extra.order") %}
|
||||
{#- Map this book's chapter path strings to an array of sections -#}
|
||||
{%- set chapters = [] -%}
|
||||
{%- for chapter_path in book.subsections -%}
|
||||
{%- set_global chapters = chapters | concat(with = get_section(path = chapter_path)) -%}
|
||||
{%- endfor -%}
|
||||
{%- set chapters = chapters | sort(attribute = "extra.order") -%}
|
||||
|
||||
{# A flat list of all pages in the ToC, initialized to just the book root section but updated when we generate the ToC #}
|
||||
{% set flat_pages = [book] %}
|
||||
{% set flat_index_of_this = 0 %}
|
||||
{#- A flat list of all pages in the ToC -#}
|
||||
{%- set flattened_outline = book_outline::flatten_book_outline(section = book) -%}
|
||||
{%- set flat_pages_list = book.path ~ ",,,,," ~ book.title ~ ";;;;;" ~ flattened_outline | split(pat = ";;;;;") -%}
|
||||
{%- set flat_index_of_this = 0 -%}
|
||||
{%- set flat_pages_path = [] -%}
|
||||
{%- set flat_pages_title = [] -%}
|
||||
{%- for item_str in flat_pages_list -%}
|
||||
{%- if item_str | trim | length > 0 -%}
|
||||
{%- set parts = item_str | split(pat = ",,,,,") -%}
|
||||
{%- if current_path == parts | first -%}
|
||||
{%- set_global flat_index_of_this = loop.index0 -%}
|
||||
{%- endif -%}
|
||||
{%- set_global flat_pages_path = flat_pages_path | concat(with = parts | first) -%}
|
||||
{%- set_global flat_pages_title = flat_pages_title | concat(with = parts | last) -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
<section class="three-column-layout">
|
||||
<aside class="chapters" data-chapters>
|
||||
@@ -43,30 +57,7 @@
|
||||
<polygon points="20.7,4.7 19.3,3.3 12,10.6 4.7,3.3 3.3,4.7 10.6,12 3.3,19.3 4.7,20.7 12,13.4 19.3,20.7 20.7,19.3 13.4,12" />
|
||||
</svg>
|
||||
</button>
|
||||
<ul>
|
||||
<li class="title{% if current_path == book.path %} active{% endif %}"><a href="{{ book.path | safe }}" title="{{ book.title | safe }}">{{ book.title }}</a></li>
|
||||
</ul>
|
||||
{% for chapter in chapters %}
|
||||
<ul>
|
||||
<li class="chapter{% if current_path == chapter.path %} active{% endif %}"><a href="{{ chapter.path | safe }}" title="{{ chapter.title | safe }}">» {{ chapter.title }}</a></li>
|
||||
|
||||
{% set_global flat_pages = flat_pages | concat(with = chapter) %}
|
||||
{% if chapter == page %}{% set_global flat_index_of_this = flat_pages | length - 1 %}{% endif %}
|
||||
|
||||
{% if chapter.pages %}
|
||||
|
||||
{% for chapter_page in chapter.pages | sort(attribute = "extra.order") %}
|
||||
|
||||
{% set_global flat_pages = flat_pages | concat(with = chapter_page) %}
|
||||
{% if chapter_page == page %}{% set_global flat_index_of_this = flat_pages | length - 1 %}{% endif %}
|
||||
|
||||
<li {% if current_path == chapter_page.path %}class="active"{% endif %}><a href="{{ chapter_page.path | safe }}" title="{{ page.title | safe }}">» {{ chapter_page.title }}</a></li>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
{{- book_outline::render_book_outline(parent = book, current_path = current_path, index = 0, indents = 3) }}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -86,39 +77,41 @@
|
||||
</h1>
|
||||
</div>
|
||||
<article>
|
||||
{{ page.content | safe }}
|
||||
{{ page.content | safe }}
|
||||
</article>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="prev-next">
|
||||
{% if flat_index_of_this >= 1 %}
|
||||
{% set prev = flat_pages | nth(n = flat_index_of_this - 1) %}
|
||||
{% endif %}
|
||||
{% if prev %}
|
||||
<a href="{{ prev.path | safe }}" title="{{ prev.title | safe }}">
|
||||
{%- if flat_index_of_this >= 1 -%}
|
||||
{%- set prev_path = flat_pages_path | nth(n = flat_index_of_this - 1) -%}
|
||||
{%- set prev_title = flat_pages_title | nth(n = flat_index_of_this - 1) -%}
|
||||
{%- endif -%}
|
||||
{%- if prev_path %}
|
||||
<a href="{{ prev_path | safe }}" title="{{ prev_title | safe }}">
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M20,0C8.95,0,0,8.95,0,20c0,11.05,8.95,20,20,20c11.05,0,20-8.95,20-20C40,8.95,31.05,0,20,0z M20,38c-9.93,0-18-8.07-18-18S10.07,2,20,2s18,8.07,18,18S29.93,38,20,38z" />
|
||||
<polygon points="24.71,10.71 23.29,9.29 12.59,20 23.29,30.71 24.71,29.29 15.41,20" />
|
||||
</svg>
|
||||
{{ prev.title }}
|
||||
{{ prev_title }}
|
||||
</a>
|
||||
{% else %}
|
||||
<a><!-- Spacer --></a>
|
||||
{% endif %}
|
||||
{%- else -%}
|
||||
<a>{#- Spacer -#}</a>
|
||||
{%- endif -%}
|
||||
|
||||
{% if flat_index_of_this < flat_pages | length - 1 %}
|
||||
{% set next = flat_pages | nth(n = flat_index_of_this + 1) %}
|
||||
{% endif %}
|
||||
{% if next %}
|
||||
<a href="{{ next.path | safe }}" title="{{ next.title | safe }}">
|
||||
{{ next.title }}
|
||||
{%- if flat_index_of_this < flat_pages_path | length - 1 -%}
|
||||
{%- set next_path = flat_pages_path | nth(n = flat_index_of_this + 1) -%}
|
||||
{%- set next_title = flat_pages_title | nth(n = flat_index_of_this + 1) -%}
|
||||
{%- endif -%}
|
||||
{%- if next_path %}
|
||||
<a href="{{ next_path | safe }}" title="{{ next_title | safe }}">
|
||||
{{ next_title }}
|
||||
<svg width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M20,0C8.95,0,0,8.95,0,20c0,11.05,8.95,20,20,20c11.05,0,20-8.95,20-20C40,8.95,31.05,0,20,0z M20,38c-9.93,0-18-8.07-18-18S10.07,2,20,2s18,8.07,18,18S29.93,38,20,38z" />
|
||||
<polygon points="16.71,9.29 15.29,10.71 24.59,20 15.29,29.29 16.71,30.71 27.41,20" />
|
||||
</svg>
|
||||
</a>
|
||||
{% endif %}
|
||||
{%- endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -130,36 +123,7 @@
|
||||
{% if page.toc | length > 0 %}Contents<span> (top ↑)</span>{% else %}Back to top ↑{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
{% for depth_1 in page.toc %}
|
||||
<li><a href="#{{ depth_1.id }}" title="{{ depth_1.title | safe }}">{{ depth_1.title }}</a></li>
|
||||
{% for depth_2 in depth_1.children %}
|
||||
<ul>
|
||||
<li><a href="#{{ depth_2.id }}" title="{{ depth_2.title | safe }}">{{ depth_2.title }}</a></li>
|
||||
{% for depth_3 in depth_2.children %}
|
||||
<ul>
|
||||
<li><a href="#{{ depth_3.id }}" title="{{ depth_3.title | safe }}">{{ depth_3.title }}</a></li>
|
||||
{% for depth_4 in depth_3.children %}
|
||||
<ul>
|
||||
<li><a href="#{{ depth_4.id }}" title="{{ depth_4.title | safe }}">{{ depth_4.title }}</a></li>
|
||||
{% for depth_5 in depth_4.children %}
|
||||
<ul>
|
||||
<li><a href="#{{ depth_5.id }}" title="{{ depth_5.title | safe }}">{{ depth_5.title }}</a></li>
|
||||
{% for depth_6 in depth_5.children %}
|
||||
<ul>
|
||||
<li><a href="#{{ depth_6.id }}" title="{{ depth_6.title | safe }}">{{ depth_6.title }}</a></li>
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{{- book_outline::render_book_page_toc(children = page.toc, indents = 1) }}
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user