| 1 |
{#- Template for backlinks. |
| 2 |
|
| 3 |
This template renders backlinks. |
| 4 |
|
| 5 |
Context: |
| 6 |
backlinks (Mapping[str, Iterable[str]]): The backlinks to render. |
| 7 |
config (dict): The configuration options. |
| 8 |
verbose_type (Mapping[str, str]): The verbose backlink types. |
| 9 |
default_crumb (BacklinkCrumb): A default, empty crumb. |
| 10 |
-#} |
| 11 |
|
| 12 |
{% block logs scoped %} |
| 13 |
{#- Logging block. |
| 14 |
|
| 15 |
This block can be used to log debug messages, deprecation messages, warnings, etc. |
| 16 |
-#} |
| 17 |
{% endblock logs %} |
| 18 |
|
| 19 |
{% macro render_crumb(crumb, last=false) %} |
| 20 |
<span class="doc doc-backlink-crumb{{ " last" if last else "" }}"> |
| 21 |
{% if crumb.url and crumb.title %} |
| 22 |
<a href="{{ crumb.url }}">{{ crumb.title | safe }}</a> |
| 23 |
{% elif crumb.title %} |
| 24 |
<span>{{ crumb.title | safe }}</span> |
| 25 |
{% endif %} |
| 26 |
</span> |
| 27 |
{% endmacro %} |
| 28 |
|
| 29 |
{% macro render_tree(tree) %} |
| 30 |
<ul class="doc doc-backlink-list"> |
| 31 |
{% for node, child in tree | dictsort %} |
| 32 |
<li class="doc doc-backlink"> |
| 33 |
{% for crumb in node %} |
| 34 |
{{ render_crumb(crumb, last=loop.last and not child) }} |
| 35 |
{% endfor %} |
| 36 |
{% if child %} |
| 37 |
{{ render_tree(child) }} |
| 38 |
{% endif %} |
| 39 |
</li> |
| 40 |
{% endfor %} |
| 41 |
</ul> |
| 42 |
{% endmacro %} |
| 43 |
|
| 44 |
{% if config.backlinks %} |
| 45 |
<div class="doc doc-backlinks"> |
| 46 |
{% if config.backlinks == "tree" %} |
| 47 |
{% for backlink_type, backlink_list in backlinks | dictsort %} |
| 48 |
<b class="doc doc-backlink-type">{{ verbose_type[backlink_type] }}:</b> |
| 49 |
{{ render_tree(backlink_list|backlink_tree) }} |
| 50 |
{% endfor %} |
| 51 |
{% elif config.backlinks == "flat" %} |
| 52 |
{% for backlink_type, backlink_list in backlinks | dictsort %} |
| 53 |
<b class="doc doc-backlink-type">{{ verbose_type[backlink_type] }}:</b> |
| 54 |
<ul class="doc doc-backlink-list"> |
| 55 |
{% for backlink in backlink_list | sort(attribute="crumbs") %} |
| 56 |
<li class="doc doc-backlink"> |
| 57 |
{% for crumb in backlink.crumbs %} |
| 58 |
{{ render_crumb(crumb, last=loop.last) }} |
| 59 |
{% endfor %} |
| 60 |
</li> |
| 61 |
{% endfor %} |
| 62 |
</ul> |
| 63 |
{% endfor %} |
| 64 |
{% endif %} |
| 65 |
</div> |
| 66 |
{% endif %} |