Add Site reference to Output, clean up template url handling
The following changes have been made all with template cleanup in mind: - Make Output.url relative to the origin root - Keep weakref to Site in all Output objects. - Add several helpers to get urls from Site: home_url(), tag_url(tag), section_url(section) and tags_url(). - Add helpers to Index to get pagination urls: pagination_url(n) - Clean up templates by making use of these new facilities
This commit is contained in:
@@ -1,25 +1,22 @@
|
||||
{% extends "base.html" %}
|
||||
{% set base_path = ("/" + label) if kind == "section" else (("/tags/" + label) if kind == "tag" else "") %}
|
||||
{% set heading = label or "" %}
|
||||
|
||||
{% block title %}{% if heading %}{{ heading }} — {% endif %}{{ site.name }}{% if page_num > 1 %} — Page {{ page_num }}{% endif %}{% endblock %}
|
||||
{% block title %}{% if page.label %}{{ page.label }} — {% endif %}{{ site.name }}{% if page.page_num > 1 %} — Page {{ page.page_num }}{% endif %}{% endblock %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="canonical" href="{{ site.origin }}{{ site.base_dir }}{% if page_num == 1 %}{{ base_path or "/" }}{% else %}{{ base_path }}/page-{{ page_num }}.html{% endif %}">
|
||||
{% if page_num > 1 %}<meta name="robots" content="noindex, follow">{% endif %}
|
||||
{% if page.page_num > 1 %}<meta name="robots" content="noindex, follow">{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{% if kind == "section" %}
|
||||
{% if page.kind == "section" %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<a href="{{ site.base_dir or "/" }}">{{ site.name }}</a> ›
|
||||
{{ label }}
|
||||
<a href="{{ site.home_url() }}">{{ site.name }}</a> ›
|
||||
{{ page.label }}
|
||||
</nav>
|
||||
{% elif kind == "tag" %}
|
||||
{% elif page.kind == "tag" %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<a href="{{ site.base_dir or "/" }}">{{ site.name }}</a> ›
|
||||
<a href="{{ site.base_dir }}/tags">Tags</a> ›
|
||||
{{ label }}
|
||||
<a href="{{ site.home_url() }}">{{ site.name }}</a> ›
|
||||
<a href="{{ site.tags_url() }}">Tags</a> ›
|
||||
{{ page.label }}
|
||||
</nav>
|
||||
{% else %}
|
||||
{{ super() }}
|
||||
@@ -27,28 +24,28 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if heading %}<h1>{{ heading }}</h1>{% endif %}
|
||||
{% for item in items %}
|
||||
{% if page.label %}<h1>{{ page.label }}</h1>{% endif %}
|
||||
{% for item in page.items %}
|
||||
<article>
|
||||
<header>
|
||||
<h2><a href="{{ site.base_dir }}{{ item.url }}">{{ item.title }}</a></h2>
|
||||
<h2><a href="{{ item.url }}">{{ item.title }}</a></h2>
|
||||
<time datetime="{{ item.created }}">{{ item.created }}</time>
|
||||
</header>
|
||||
{% if item.summary %}<p>{{ item.summary }}</p>{% endif %}
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% if total_pages > 1 %}
|
||||
{% if page.total_pages > 1 %}
|
||||
<nav>
|
||||
{% if page_num > 1 %}
|
||||
<a href="{{ site.base_dir }}{% if page_num - 1 == 1 %}{{ base_path or "/" }}{% else %}{{ base_path }}/page-{{ page_num - 1 }}.html{% endif %}">← Newer</a>
|
||||
{% if page.page_num > 1 %}
|
||||
<a href="{{ page.pagination_url(page.page_num - 1) }}">← Newer</a>
|
||||
{% endif %}
|
||||
{% for p in range(1, total_pages + 1) %}
|
||||
{% if p == page_num %}<strong>{{ p }}</strong>
|
||||
{% else %}<a href="{{ site.base_dir }}{% if p == 1 %}{{ base_path or "/" }}{% else %}{{ base_path }}/page-{{ p }}.html{% endif %}">{{ p }}</a>
|
||||
{% for p in range(1, page.total_pages + 1) %}
|
||||
{% if p == page.page_num %}<strong>{{ p }}</strong>
|
||||
{% else %}<a href="{{ page.pagination_url(p) }}">{{ p }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if page_num < total_pages %}
|
||||
<a href="{{ site.base_dir }}{{ base_path }}/page-{{ page_num + 1 }}.html">Older →</a>
|
||||
{% if page.page_num < page.total_pages %}
|
||||
<a href="{{ page.pagination_url(page.page_num + 1) }}">Older →</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user