Skip to content

Commit 0d2c0d9

Browse files
committed
feature: source section title from index.md for breadcrumbs
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
1 parent cc746f5 commit 0d2c0d9

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

dist/partials/path-item.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
{#-
22
This file was automatically generated - do not edit
33
-#}
4-
{% macro render_content(nav_item) %}
4+
{% macro render_content(nav_item, ref) %}
5+
{% set ref = ref or nav_item %}
56
<span class="md-ellipsis">
6-
{{ nav_item.title }}
7+
{{ ref.title or nav_item.title }}
78
</span>
89
{% endmacro %}
910
{% macro render(nav_item, ref) %}
1011
{% set ref = ref or nav_item %}
1112
{% if nav_item.children %}
12-
{% set first = nav_item.children | first %}
13+
{% set _ = namespace(index = none) %}
14+
{% if "navigation.indexes" in features %}
15+
{% for item in nav_item.children %}
16+
{% if item.is_index and _.index is none %}
17+
{% set _.index = item %}
18+
{% endif %}
19+
{% endfor %}
20+
{% endif %}
21+
{% set index = _.index %}
22+
{% set first = index or nav_item.children | first %}
1323
{% if first.children %}
1424
{{ render(first, ref) }}
1525
{% else %}
1626
<li class="md-path__item">
1727
<a href="{{ first.url | url }}" class="md-path__link">
18-
{{ render_content(ref) }}
28+
{{ render_content(first, ref) }}
1929
</a>
2030
</li>
2131
{% endif %}
2232
{% else %}
2333
<li class="md-path__item">
2434
<a href="{{ nav_item.url | url }}" class="md-path__link">
25-
{{ render_content(ref) }}
35+
{{ render_content(first, ref) }}
2636
</a>
2737
</li>
2838
{% endif %}

src/partials/path-item.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
-->
2525

2626
<!-- Render navigation link content -->
27-
{% macro render_content(nav_item) %}
27+
{% macro render_content(nav_item, ref) %}
28+
{% set ref = ref or nav_item %}
2829
<span class="md-ellipsis">
29-
{{ nav_item.title }}
30+
{{ ref.title or nav_item.title }}
3031
</span>
3132
{% endmacro %}
3233

@@ -36,7 +37,20 @@
3637

3738
<!-- Navigation item with nested items -->
3839
{% if nav_item.children %}
39-
{% set first = nav_item.children | first %}
40+
41+
<!-- Determine all nested items that are index pages -->
42+
{% set _ = namespace(index = none) %}
43+
{% if "navigation.indexes" in features %}
44+
{% for item in nav_item.children %}
45+
{% if item.is_index and _.index is none %}
46+
{% set _.index = item %}
47+
{% endif %}
48+
{% endfor %}
49+
{% endif %}
50+
{% set index = _.index %}
51+
52+
<!-- Use index page as entry point if present, otherwise first child -->
53+
{% set first = index or nav_item.children | first %}
4054

4155
<!-- Recurse, if the first item has further nested items -->
4256
{% if first.children %}
@@ -46,7 +60,7 @@
4660
{% else %}
4761
<li class="md-path__item">
4862
<a href="{{ first.url | url }}" class="md-path__link">
49-
{{ render_content(ref) }}
63+
{{ render_content(first, ref) }}
5064
</a>
5165
</li>
5266
{% endif %}
@@ -55,7 +69,7 @@
5569
{% else %}
5670
<li class="md-path__item">
5771
<a href="{{ nav_item.url | url }}" class="md-path__link">
58-
{{ render_content(ref) }}
72+
{{ render_content(first, ref) }}
5973
</a>
6074
</li>
6175
{% endif %}

0 commit comments

Comments
 (0)