added: default taxonomies templates, custom nav links

This commit is contained in:
Ahmed M Alaa 2022-12-05 14:48:27 +02:00
parent 2d7be35ef5
commit 7daa254c0b
No known key found for this signature in database
GPG key ID: 754EEB8AD6C08BF2
14 changed files with 205 additions and 7 deletions

View file

@ -22,6 +22,19 @@ theme = "no-style-please"
## Options ## Options
### Default taxonomies
Special templates for `tags`, `categories`, and `contexts` taxonomies are provided. However, generic templates exist for custom taxonomies.
To use taxonomies, in a page metadata add
```toml
[taxonomies]
tags = [ 'tag1', 'tag2' ]
categories = [ 'category A', 'B class' ]
genre = [ 'rock', 'alternative' ] # custom taxonomy
```
### Pages list in homepage ### Pages list in homepage
To enable listing of pages in homepage add the following in `config.toml` To enable listing of pages in homepage add the following in `config.toml`
@ -31,6 +44,26 @@ To enable listing of pages in homepage add the following in `config.toml`
list_pages = false list_pages = false
``` ```
### Header and footer nav links
Also in the `extra` section in `config.toml`
```toml
[extra]
header_nav = [
{ name = "~home", url = "/" },
{ name = "#tags", url = "/tags" },
{ name = "+categories", url = "/categories" },
{ name = "@contexts", url = "/contexts" },
]
footer_nav = [
{ name = "< previous", url = "#" },
{ name = "webring", url = "#" },
{ name = "next >", url = "#" },
]
```
### Add TOC to pages ### Add TOC to pages
In a page frontmatter, set `extra.add_toc` to `true` In a page frontmatter, set `extra.add_toc` to `true`

View file

@ -6,7 +6,9 @@ compile_sass = true
generate_feed = true generate_feed = true
taxonomies = [ taxonomies = [
{ name = "tags" },
{ name = "categories" }, { name = "categories" },
{ name = "contexts" },
] ]
[markdown] [markdown]
@ -14,4 +16,15 @@ highlight_code = true
[extra] [extra]
author = "Ahmed Alaa" author = "Ahmed Alaa"
logo = "images/logo.png" logo = "images/logo.png"
header_nav = [
{ name = "~home", url = "/" },
{ name = "#tags", url = "/tags" },
{ name = "+categories", url = "/categories" },
{ name = "@contexts", url = "/contexts" },
]
footer_nav = [
{ name = "< previous", url = "#" },
{ name = "webring", url = "#" },
{ name = "next >", url = "#" },
]

View file

@ -102,4 +102,6 @@ img {
p { p {
display: inline; display: inline;
} }
} }
nav, .taxonomies { text-align: center; }

View file

@ -95,6 +95,13 @@
<body theme="auto"> <body theme="auto">
<div class="w"> <div class="w">
<header> <header>
{% if config.extra.header_nav %}
<nav>
{% for nav_item in config.extra.header_nav %}
<a href="{{ nav_item.url | safe }}">{{ nav_item.name }}</a>
{% endfor %}
</nav>
{% endif %}
{% block header %}{% if title %}<h1>{{ config.title }}</h1>{% endif %}{% endblock header %} {% block header %}{% if title %}<h1>{{ config.title }}</h1>{% endif %}{% endblock header %}
</header> </header>
<main class="page-content" aria-label="Content"> <main class="page-content" aria-label="Content">
@ -102,6 +109,13 @@
</main> </main>
<footer> <footer>
{% block footer %}{% endblock footer %} {% block footer %}{% endblock footer %}
{% if config.extra.footer_nav %}
<nav>
{% for nav_item in config.extra.footer_nav %}
<a href="{{ nav_item.url | safe }}">{{ nav_item.name }}</a>
{% endfor %}
</nav>
{% endif %}
</footer> </footer>
</div> </div>
</body> </body>

View file

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}..">..</a>{{ current_path }}</p>
<h1>{{ taxonomy.name }}</h1>
{% endblock header %}
{% block content %}
<ul>
{% for term in terms %}
<li>
<a href="{{ term.permalink | safe }}">{{ term.name }}</a> [{{ term.pages | length }}]
</li>
{% endfor %}
</ul>
{% endblock content %}

View file

@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}">..</a>/{{ term.slug }}/</p>
<h1>{{ term.name }}</h1>
{% endblock header %}
{% block content %}
{% if paginator %}
{% set pages = paginator.pages %}
{% else %}
{% set pages = term.pages %}
{% endif %}
<ul>
{% for page in pages %}
<li>
<a href="{{ page.permalink | safe }}">{% if page.date %}{{ page.date }} - {% endif %}{{ page.title }}</a>
<br />
{{ page.description }}
</li>
{% endfor %}
</ul>
{% if paginator %}
<p>{% if paginator.previous %}<a href="{{ paginator.first }}">&lt;&lt; First</a> <a href="{{ paginator.previous }}">&lt; Previous</a>{% endif %} [{{ paginator.current_index }}/{{ paginator.number_pagers }}] {% if paginator.next %}<a href="{{ paginator.next }}">Next &gt;</a> <a href="{{ paginator.last }}">Last &gt;&gt;</a>{% endif %}</p>
{% endif %}
{% endblock content %}

View file

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}..">..</a>{{ current_path }}</p>
<h1>{{ taxonomy.name }}</h1>
{% endblock header %}
{% block content %}
<p>
{% for term in terms %}
<a href="{{ term.permalink | safe }}">@{{ term.name }}</a>
{% endfor %}
</p>
{% endblock content %}

View file

@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}">..</a>/{{ term.slug }}/</p>
<h1>{{ term.name }}</h1>
{% endblock header %}
{% block content %}
{% if paginator %}
{% set pages = paginator.pages %}
{% else %}
{% set pages = term.pages %}
{% endif %}
<ul>
{% for page in pages %}
<li>
<a href="{{ page.permalink | safe }}">{% if page.date %}{{ page.date }} - {% endif %}{{ page.title }}</a>
<br />
{{ page.description }}
</li>
{% endfor %}
</ul>
{% if paginator %}
<p>{% if paginator.previous %}<a href="{{ paginator.first }}">&lt;&lt; First</a> <a href="{{ paginator.previous }}">&lt; Previous</a>{% endif %} [{{ paginator.current_index }}/{{ paginator.number_pagers }}] {% if paginator.next %}<a href="{{ paginator.next }}">Next &gt;</a> <a href="{{ paginator.last }}">Last &gt;&gt;</a>{% endif %}</p>
{% endif %}
{% endblock content %}

View file

@ -12,7 +12,7 @@
<ul> <ul>
{% for page in pages %} {% for page in pages %}
<li> <li>
<a href="{{ page.permalink | safe }}">{{ page.date }} - {{ page.title }}</a> <a href="{{ page.permalink | safe }}">{% if page.date %}{{ page.date }} - {% endif %}{{ page.title }}</a>
<br /> <br />
{{ page.description }} {{ page.description }}
</li> </li>

View file

@ -29,4 +29,20 @@ Table of contents
{% endif %} {% endif %}
{{ page.content | safe }} {{ page.content | safe }}
{% endblock content %} {% endblock content %}
{% block footer %}
<p class="taxonomies">
{% if page.taxonomies.tags %}
{% for tag in page.taxonomies.tags %}
<a href="/tags/{{ tag | slugify }}">#{{ tag }}</a>
{% endfor %}
{% for category in page.taxonomies.categories %}
<a href="/categories/{{ category | slugify }}">+{{ category }}</a>
{% endfor %}
{% for context in page.taxonomies.contexts %}
<a href="/contexts/{{ context | slugify }}">@{{ context }}</a>
{% endfor %}
{% endif %}
</p>
{% endblock footer %}

14
templates/tags/list.html Normal file
View file

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}..">..</a>{{ current_path }}</p>
<h1>{{ taxonomy.name }}</h1>
{% endblock header %}
{% block content %}
<p>
{% for term in terms %}
<a href="{{ term.permalink | safe }}">#{{ term.name }}</a>[{{ term.pages | length }}]
{% endfor %}
</p>
{% endblock content %}

View file

@ -0,0 +1,26 @@
{% extends "base.html" %}
{% block header %}
<p><a href="{{ current_path }}">..</a>/{{ term.slug }}/</p>
<h1>{{ term.name }}</h1>
{% endblock header %}
{% block content %}
{% if paginator %}
{% set pages = paginator.pages %}
{% else %}
{% set pages = term.pages %}
{% endif %}
<ul>
{% for page in pages %}
<li>
<a href="{{ page.permalink | safe }}">{% if page.date %}{{ page.date }} - {% endif %}{{ page.title }}</a>
<br />
{{ page.description }}
</li>
{% endfor %}
</ul>
{% if paginator %}
<p>{% if paginator.previous %}<a href="{{ paginator.first }}">&lt;&lt; First</a> <a href="{{ paginator.previous }}">&lt; Previous</a>{% endif %} [{{ paginator.current_index }}/{{ paginator.number_pagers }}] {% if paginator.next %}<a href="{{ paginator.next }}">Next &gt;</a> <a href="{{ paginator.last }}">Last &gt;&gt;</a>{% endif %}</p>
{% endif %}
{% endblock content %}

View file

@ -2,7 +2,6 @@
{% block header %} {% block header %}
<p><a href="{{ current_path }}..">..</a>{{ current_path }}</p> <p><a href="{{ current_path }}..">..</a>{{ current_path }}</p>
<h1>{{ taxonomy.name }}</h1> <h1>{{ taxonomy.name }}</h1>
{% endblock header %} {% endblock header %}

View file

@ -2,7 +2,6 @@
{% block header %} {% block header %}
<p><a href="{{ current_path }}">..</a>/{{ term.slug }}/</p> <p><a href="{{ current_path }}">..</a>/{{ term.slug }}/</p>
<h1>{{ term.name }}</h1> <h1>{{ term.name }}</h1>
{% endblock header %} {% endblock header %}
@ -15,7 +14,7 @@
<ul> <ul>
{% for page in pages %} {% for page in pages %}
<li> <li>
<a href="{{ page.permalink | safe }}">{{ page.date }} - {{ page.title }}</a> <a href="{{ page.permalink | safe }}">{% if page.date %}{{ page.date }} - {% endif %}{{ page.title }}</a>
<br /> <br />
{{ page.description }} {{ page.description }}
</li> </li>