Skip to content

Commit f14a14e

Browse files
authored
Merge pull request #202 from eecs485staff/sitemap-label
[Sitemap] Allow removing label from sitemap
2 parents 2f79dca + 0af4a0b commit f14a14e

File tree

6 files changed

+69
-20
lines changed

6 files changed

+69
-20
lines changed

_config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ description: Primer Spec is a Jekyll theme for GitHub Pages
1818
primerSpec:
1919
sitemap:
2020
label: Docs & Demos
21+
# Setting the label to an empty string removes the label from the sitemap.
22+
# label: ''
2123
externalLinks:
2224
- title: Wikipedia
2325
url: https://www.wikipedia.org/
24-
- title: "Google"
26+
- title: 'Google'
2527
url: https://google.com/
26-
- title: "EECS 485"
28+
- title: 'EECS 485'
2729
url: https://eecs485.org
2830

2931
# defaultCodeblockVariant: no-line-numbers

_layouts/spec.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,19 @@
9696
{%- endfor -%}
9797
{%- endif -%}
9898
],
99-
sitemapLabel: '{{ site.primerSpec.sitemap.label | default: "" }}',
99+
{%- comment -%}
100+
This is not intuitive, but
101+
- If the label is not defined in the config, show the default label (by unsetting it).
102+
- If the label is set to '' in the config, then DO NOT show a sitemap label.
103+
- Otherwise, use the given sitemap label.
104+
{%- endcomment -%}
105+
{% unless site.primerSpec.sitemap.label %}
106+
sitemapLabel: undefined,
107+
{% elsif site.primerSpec.sitemap.label == '' %}
108+
sitemapLabel: null,
109+
{% else %}
110+
sitemapLabel: '{{ site.primerSpec.sitemap.label }}',
111+
{% endunless -%}
100112
sitemapSiteTitle: '{{ site.title | default: "" }}',
101113
{%- comment -%}
102114
The issue with the "default" filter is that it executes on ANY
@@ -112,7 +124,7 @@
112124
{% assign useLegacyCodeBlocks = page.useLegacyCodeBlocks %}
113125
{%- if useLegacyCodeBlocks == nil -%}
114126
{%- assign useLegacyCodeBlocks = site.primerSpec.useLegacyCodeBlocks -%}
115-
{%- endif -%}
127+
{%- endif %}
116128
useLegacyCodeBlocks: {{ useLegacyCodeBlocks | default: false }},
117129
{% assign defaultCodeblockVariant = page.defaultCodeblockVariant %}
118130
{%- if defaultCodeblockVariant == nil -%}

demo/long-headings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: spec
3-
title: title: "[DEMO] Long Headings"
3+
title: '[DEMO] Long Headings'
44
excludeFromSitemap: true
55
---
66

docs/USAGE_ADVANCED.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ _[EECS 280's Project 1](https://eecs280staff.github.io/p1-stats/) has a great ex
388388

389389
If set to `true`, a sitemap will be auto-generated and displayed in the Sidebar of every Primer Spec page with the label _"Supplemental Pages"_.
390390

391-
To customize the label, specify it under a `label` field.
391+
To customize the label, specify it under a `label` field. If you would prefer to remove the label from your sitemap, set the field to the empty string (`label: ''`).
392392

393393
To add external links, specify them under an `externalLinks` field. Each item in the `externalLinks` array must have a `title` and a `url` field. External links will always appear at the bottom of the sidebar, below all internal links. They will appear in the same order that you include them in your `_config.yml`.
394394

src_js/Config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
INIT_SUBTHEME_MODE,
3232
INIT_SITEMAP_ENABLED,
3333
SITEMAP_URLS: window.PrimerSpecConfig.sitemapUrls || [],
34-
SITEMAP_LABEL: window.PrimerSpecConfig.sitemapLabel || 'Supplemental Pages',
34+
SITEMAP_LABEL: getSitemapLabel(),
3535
SITEMAP_SITE_TITLE: window.PrimerSpecConfig.sitemapSiteTitle || '',
3636
DEFAULT_CODEBLOCK_VARIANT: getDefaultCodeblockVariant(),
3737

@@ -90,3 +90,10 @@ function getDefaultCodeblockVariant(): CodeblockVariant {
9090
}
9191
return CodeblockVariant.ENHANCED;
9292
}
93+
94+
function getSitemapLabel(): null | string {
95+
if (window.PrimerSpecConfig.sitemapLabel === null) {
96+
return null;
97+
}
98+
return window.PrimerSpecConfig.sitemapLabel || 'Supplemental Pages';
99+
}

src_js/components/sidebar/SidebarContent.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,56 @@ export default function SidebarContent(props: PropsType): h.JSX.Element {
1717
);
1818
}
1919

20+
const isRootPageCurrent = props.sitemap.rootPage.current;
21+
2022
return (
2123
<Fragment>
22-
<details
23-
role="navigation"
24-
aria-label={Config.SITEMAP_LABEL}
25-
open={props.sitemap.rootPage.current ? undefined : true}
26-
>
27-
<summary>{Config.SITEMAP_LABEL}</summary>
28-
{props.sitemap.siteUrls.map((sitePage) => (
29-
<SitemapPage key={sitePage.url} page={sitePage}>
30-
{sitePage.current ? props.children : undefined}
31-
</SitemapPage>
32-
))}
33-
</details>
24+
<Sitemap sitemap={props.sitemap}>
25+
{isRootPageCurrent ? undefined : props.children}
26+
</Sitemap>
3427
<hr />
3528
<SitemapPage page={props.sitemap.rootPage} dedent>
36-
{props.sitemap.rootPage.current ? props.children : undefined}
29+
{isRootPageCurrent ? props.children : undefined}
3730
</SitemapPage>
3831
</Fragment>
3932
);
4033
}
4134

35+
function Sitemap(props: {
36+
sitemap: SitemapType;
37+
children?: h.JSX.Element;
38+
}): h.JSX.Element {
39+
const shouldDedentSitemap = Config.SITEMAP_LABEL == null;
40+
const renderedSiteUrls = (
41+
<Fragment>
42+
{props.sitemap.siteUrls.map((sitePage) => (
43+
<SitemapPage
44+
key={sitePage.url}
45+
page={sitePage}
46+
dedent={shouldDedentSitemap}
47+
>
48+
{sitePage.current ? props.children : undefined}
49+
</SitemapPage>
50+
))}
51+
</Fragment>
52+
);
53+
54+
if (shouldDedentSitemap) {
55+
return renderedSiteUrls;
56+
}
57+
58+
return (
59+
<details
60+
role="navigation"
61+
aria-label={Config.SITEMAP_LABEL}
62+
open={props.sitemap.rootPage.current ? undefined : true}
63+
>
64+
<summary>{Config.SITEMAP_LABEL}</summary>
65+
{renderedSiteUrls}
66+
</details>
67+
);
68+
}
69+
4270
function SitemapPage(props: {
4371
page: SitemapPageInfoType;
4472
dedent?: boolean;

0 commit comments

Comments
 (0)