Skip to content

Commit 3e0049b

Browse files
authored
Merge pull request #402 from wpaccessibility/387-sitemap
Sitemap for users
2 parents 74fc136 + ffb28df commit 3e0049b

10 files changed

Lines changed: 275 additions & 57 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
{%- comment -%}
2+
Include as: {%- include components/children_nav-sitemap.html -%}
3+
Depends on: page, site, nav_breadcrumbs.
4+
Results in: HTML for the children-navigation component.
5+
Includes: components/nav/sorted.html.
6+
Overwrites:
7+
nav_ancestor_links, nav_top_node_titles, nav_child_candidates, nav_children,
8+
nav_child, nav_child_ok, nav_child_ancestor, nav_sorted.
9+
{%- endcomment -%}
10+
11+
{%- comment -%}
12+
Whether a page has any children is checked efficiently by inspecting the cached
13+
site_nav. If the page has no children, nav_children is set to an empty array;
14+
otherwise nav_children is left unset. (The site_nav is rendered the first time
15+
it is included, and that may overwrite various variables.)
16+
{%- endcomment -%}
17+
18+
{%- if page.has_children == false -%}
19+
{%- assign nav_children = "" | split: "" -%}
20+
{%- else -%}
21+
22+
{%- capture site_nav -%}
23+
{%- include_cached components/site_nav.html all=true -%}
24+
{%- endcapture -%}
25+
26+
{%- assign nav_children = nil -%}
27+
28+
{%- capture nav_list_link -%}
29+
<a href="{{ page.url | relative_url }}">
30+
{%- endcapture -%}
31+
32+
{%- capture nav_list_simple -%}
33+
<ul>
34+
{%- endcapture -%}
35+
36+
37+
{%- endif -%}
38+
39+
{%- unless nav_children -%}
40+
41+
{%- comment -%}
42+
The layout is assumed to include components/breadcrumbs.html before this file,
43+
otherwise it needs to be included here.
44+
{%- endcomment -%}
45+
46+
47+
{%- assign nav_parenthood = site[page.collection] | default: site.html_pages
48+
| where_exp: "item", "item.title != nil" | group_by: "parent" -%}
49+
50+
{%- assign nav_top_nodes = nav_parenthood
51+
| where_exp: "item", "item.name == ''" | map: "items" | first -%}
52+
53+
{% assign nav_top_node_titles = nav_top_nodes | map: "title" -%}
54+
55+
{%- include components/nav/children.html node=page ancestors=nav_ancestors all=true -%}
56+
57+
{%- endunless -%}
58+
59+
{%- if nav_children.size >= 1 -%}
60+
61+
{%- if page.child_nav_order == 'desc' or page.child_nav_order == 'reversed' -%}
62+
{%- assign nav_children = nav_children | reverse -%}
63+
{%- endif -%}
64+
65+
<nav aria-label="Related content" class="toc">
66+
67+
<h2 class="no_toc" id="table-of-contents">Pages in: {{ page.title }}</h2>
68+
<ul role="list">
69+
{% for nav_child in nav_children %}
70+
<li>
71+
<h3>
72+
<a href="{{ nav_child.url | relative_url }}">{{ nav_child.title }}</a>
73+
</h3>
74+
<p>{{ nav_child.description }}</p>
75+
</li>
76+
{% endfor %}
77+
78+
</ul>
79+
80+
{% if page.parent %}
81+
{% assign introPage = site.pages | where: "title", page.parent | first %}
82+
83+
<p>
84+
<span aria-hidden="true">&larr;</span> <a href="{{ introPage.url | relative_url }}">Back to: {{ introPage.title }}</a>
85+
</p>
86+
87+
{% else %}
88+
89+
<p>
90+
<span aria-hidden="true">&larr;</span> <a href="{{ site.url | relative_url }}">Back to: Home</a>
91+
</p>
92+
93+
{% endif %}
94+
95+
</nav>
96+
97+
{% else %}
98+
99+
{% include components/siblings.html %}
100+
101+
{%- endif -%}

‎_includes/components/footer.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h3>Quick links</h3>
1111
<ul>
1212
<li><a href="{{site.baseurl}}/docs/accessibility-ready/">Accessibility-ready program</a></li>
1313
<li><a href="{{site.baseurl}}/docs/topics/code/screen-reader-text/">CSS class .screen-reader-text</a></li>
14-
<li><a href="{{site.baseurl}}/docs/topics/legislation/">Legislation worldwide</a></li>
14+
<li><a href="{{site.baseurl}}/sitemap/">Sitemap</a></li>
1515
<li><a href="{{site.baseurl}}/docs/start/overlays/">Accessibility Overlays</a></li>
1616
<li><a href="{{site.baseurl}}/docs/about/sponsors/">Sponsors</a></li>
1717
<li><a href="{{site.baseurl}}/docs/about/contact/">Contact us</a></li>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{%- comment -%}
2+
Include as: {%- include components/nav/children.html node=node ancestors=title_array all=bool -%}
3+
Depends on: include.node, include.ancestors, include.all, nav_parenthood, nav_top_node_titles.
4+
Includes: components/nav/sorted.html.
5+
Assigns to: nav_children.
6+
Overwrites:
7+
nav_candidates, nav_child, nav_child_ok.
8+
{%- endcomment -%}
9+
10+
{%- assign nav_children = "" | split: "" -%}
11+
12+
{%- if include.all == true or include.node.has_children != false -%}
13+
14+
{%- assign nav_candidates = nav_parenthood
15+
| where: "name", include.node.title | map: "items" | first -%}
16+
17+
{%- for nav_child in nav_candidates -%}
18+
{%- assign nav_child_ok = true -%}
19+
20+
{%- if nav_child.grand_parent and nav_child.grand_parent != include.node.parent -%}
21+
{%- assign nav_child_ok = false -%}
22+
{%- endif -%}
23+
24+
{%- if nav_child.ancestor and nav_child.ancestor != include.node.title -%}
25+
{%- unless include.ancestors contains nav_child.ancestor -%}
26+
{%- assign nav_child_ok = false -%}
27+
{%- endunless -%}
28+
{%- endif -%}
29+
30+
{%- comment -%}
31+
The following check rejects nav_child as 3rd-level when include.node is 2nd-level
32+
and nav_child can also be 2nd-level. This is for backwards compatibility with
33+
existing 3-level sites.
34+
{%- endcomment -%}
35+
{%- if nav_child.grand_parent == nil and nav_child.ancestor == nil and
36+
nav_top_node_titles contains nav_child.parent and include.ancestors.size >= 1 -%}
37+
{%- assign nav_child_ok = false -%}
38+
{%- endif -%}
39+
40+
{%- if nav_child_ok -%}
41+
{%- assign nav_children = nav_children | push: nav_child -%}
42+
{%- endif -%}
43+
{%- endfor -%}
44+
45+
{%- endif -%}
46+
47+
{%- include components/nav/sorted.html pages=nav_children -%}
48+
{%- assign nav_children = nav_sorted -%}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{%- comment -%}
2+
Include as: {%- include components/nav/links-sitemap.html pages=page_array ancestors=title_array all=bool -%}
3+
Depends on: include.pages, include.ancestors, include.all.
4+
Results in: HTML for the main navigation when all is nil or false;
5+
includes links to pages excluded from the main navigation when all is true.
6+
Includes: components/nav/sorted.html, components/nav/children.html, components/nav/links.html.
7+
Overwrites:
8+
node, nav_children, nav_ancestors.
9+
{%- endcomment -%}
10+
11+
<ul role="list">
12+
13+
{%- for node in include.pages -%}
14+
15+
{% unless node.url contains "/blog/page" %}
16+
17+
{%- if include.all == true or node.nav_exclude != true -%}
18+
19+
{%- if include.ancestors contains node.title -%}
20+
21+
<li>
22+
<a href="{{ node.url | relative_url }}"> ∞ </a>
23+
</li>
24+
25+
{%- else -%}
26+
27+
{%- include components/nav/children-sitemap.html node=node ancestors=include.ancestors all=include.all -%}
28+
29+
<li>
30+
31+
<a href="{{ node.url | relative_url }}">{{ node.title }}</a>
32+
33+
{%- if nav_children.size >= 1 -%}
34+
{%- if node.child_nav_order == 'desc' or node.child_nav_order == 'reversed' -%}
35+
{%- assign nav_children = nav_children | reverse -%}
36+
{%- endif -%}
37+
{%- assign nav_ancestors = include.ancestors | push: node.title -%}
38+
{%- include components/nav/links-sitemap.html pages=nav_children ancestors=nav_ancestors all=include.all -%}
39+
{%- endif -%}
40+
41+
</li>
42+
43+
{%- endif -%}
44+
45+
{%- endif -%}
46+
47+
{% endunless %}
48+
49+
{%- endfor -%}
50+
51+
</ul>
52+
53+
{%- comment -%}{%- endcomment -%}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{%- comment -%}
2+
Include as: {%- include components/nav/pages.html pages=page_array all=bool -%}
3+
Depends on: include.pages.
4+
Results in: HTML for the main navigation when all is nil or false;
5+
adds links to pages excluded from the main navigation when all is true.
6+
Includes: components/nav/links-sitemap.html
7+
Assigns to:
8+
nav_parenthood, nav_top_nodes, nav_top_node_titles, nav_ancestors.
9+
{%- endcomment -%}
10+
11+
{%- assign nav_parenthood = include.pages
12+
| where_exp: "item", "item.title != nil" | group_by: "parent" -%}
13+
14+
{%- assign nav_top_nodes = nav_parenthood
15+
| where_exp: "item", "item.name == ''" | map: "items" | first -%}
16+
17+
{%- include components/nav/sorted.html pages=nav_top_nodes -%}
18+
19+
{% assign nav_top_node_titles = nav_top_nodes | map: "title" -%}
20+
21+
{%- assign nav_ancestors = "" | split: "" -%}
22+
23+
<nav aria-label="Sitemap" class="sitemap">
24+
{%- include components/nav/links-sitemap.html pages=nav_sorted ancestors=nav_ancestors all=include.all -%}
25+
</nav>

‎_includes/components/sitemap.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
{% assign pages_top_size = site.html_pages
4+
| where_exp:"item", "item.title != nil"
5+
| where_exp:"item", "item.parent == nil"
6+
| where_exp:"item", "item.nav_exclude != true"
7+
| size %}
8+
9+
{% if pages_top_size > 0 %}
10+
{% include components/nav/pages-sitemap.html pages=site.html_pages all=include.all %}
11+
{% endif %}

‎_sass/layout/_navigation.scss‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@
237237
display: block;
238238
}
239239

240+
/* Sitemap. */
241+
.sitemap {
242+
margin-top: 1em;
243+
244+
ul {
245+
a {
246+
text-decoration: none;
247+
}
248+
249+
a:hover {
250+
text-decoration: underline;
251+
}
252+
}
253+
254+
> ul {
255+
padding-left: 0;
256+
list-style: none;
257+
258+
> li > ul > li:last-child {
259+
margin-bottom: 2.5em;
260+
}
261+
}
262+
}
263+
240264
/* Text meant only for screen readers. */
241265
.screen-reader-text {
242266
border: 0;

‎docs/about/contribute/github/blog-post.md‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎docs/about/contribute/github/documentation.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Add a topic
3-
parent: Technical documentation website
3+
parent: Technical documentation
44
nav_order: 1
55
description: Add or change a page in this documentation.
66
---

‎sitemap.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Sitemap
3+
layout: default
4+
description: "Sitemap WP Accessibility Knowledge Base."
5+
nav_exclude: true
6+
search_exclude: true
7+
---
8+
9+
# Sitemap of wpaccessibility.org
10+
11+
{% include components/sitemap.html %}

0 commit comments

Comments
 (0)