Skip to content

Commit 991109b

Browse files
SnugugSam Richard
andauthored
🐛(site) Include tutorial links and software in docs (#774)
* Add tutorials to section nav * Add software to documentation pages --------- Co-authored-by: Sam Richard <samrichard@google.com>
1 parent 68e3047 commit 991109b

4 files changed

Lines changed: 63 additions & 7 deletions

File tree

site/lib/documentation.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Tag } from '$types/sanity';
2-
import { documentation, landings } from '$lib/sanity';
2+
import { documentation, landings, tutorials } from '$lib/sanity';
33

44
/**
55
* Build documentation sections
66
* @param {Tag} category
77
* @param {string} lang
8-
* @return {object}
8+
* @return {object[]}
99
*/
1010
export function buildSection(category: Tag, lang: string = 'en') {
1111
const sections = documentation
@@ -29,6 +29,23 @@ export function buildSection(category: Tag, lang: string = 'en') {
2929
return [landing, sections].flat();
3030
}
3131

32+
/**
33+
* Build documentation tutorials
34+
* @param {Tag} category
35+
* @param {string} lang
36+
* @return {object[] | null}
37+
*/
38+
export function buildTutorials(category: Tag, lang: string = 'en') {
39+
const tuts = tutorials
40+
.filter((l) => l._lang === lang)
41+
.filter((l) => l.category.slug === category.slug)
42+
.map((l) => ({
43+
title: l.title,
44+
href: l._path,
45+
}));
46+
return tuts.length > 0 ? tuts : null;
47+
}
48+
3249
/**
3350
* Build documentation topics
3451
* @param {string[]} paths Array of paths
@@ -37,6 +54,7 @@ export function buildSection(category: Tag, lang: string = 'en') {
3754
export function buildTopics(paths: string[]) {
3855
return documentation
3956
.filter((d) => paths.includes(d._path))
57+
.sort((a, b) => a.title.localeCompare(b.title))
4058
.sort((a, b) => a.weight - b.weight)
4159
.map((d) => ({
4260
title: d.title,

site/src/components/SectionNav.svelte

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
export let title: string;
88
export let links: Array<Link>;
9+
export let tutorials: Array<Link>;
10+
export let ttitle: string;
911
export let active: string;
1012
1113
const buttonTitle = 'Open section navigation';
@@ -20,7 +22,9 @@
2022
>
2123
<div class="section-nav--header">
2224
<div class="section-nav--text">
23-
<p id="section-nav--title" class="section-nav--title type--h5">{title}</p>
25+
<h2 id="section-nav--title" class="section-nav--title type--h5">
26+
{title}
27+
</h2>
2428
<svg role="img" aria-hidden="true" class="icon section-nav--expand">
2529
<use href="/images/icons/sprite.svg#expand-more" />
2630
</svg>
@@ -43,6 +47,20 @@
4347
</li>
4448
{/each}
4549
</ul>
50+
{#if tutorials}
51+
<h3 class="ttitle type--h6">{ttitle}</h3>
52+
<ul class="tutorials">
53+
{#each tutorials as link}
54+
<li class="section-nav--item">
55+
<a
56+
href={link.href}
57+
data-active={active === link.href ? true : null}
58+
class="section-nav--link type--secondary-nav">{link.title}</a
59+
>
60+
</li>
61+
{/each}
62+
</ul>
63+
{/if}
4664
</div>
4765
</nav>
4866

@@ -165,4 +183,11 @@
165183
}
166184
}
167185
}
186+
187+
.ttitle {
188+
padding-inline: var(--inline);
189+
padding-block: math.div($block, 3) * 2;
190+
margin: 0;
191+
line-height: 1;
192+
}
168193
</style>

site/src/layouts/views/Documentation.astro

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
22
import Doc from '$layouts/doc.astro';
3-
import { buildSection } from '$lib/documentation';
3+
import { buildSection, buildTutorials } from '$lib/documentation';
44
import { buildTOC } from '$lib/portabletext';
55
66
import TOC from '$components/TOC.svelte';
77
import SectionNav from '$components/SectionNav.svelte';
88
import Text from '$components/Text.astro';
9+
import Software from '$components/Software.svelte';
10+
911
import type { Documentation, Microcopy } from '$types/sanity';
1012
1113
export interface Props {
@@ -16,6 +18,7 @@ export interface Props {
1618
const { doc, microcopy } = Astro.props;
1719
1820
const section = buildSection(doc.category, doc._lang);
21+
const tutorials = buildTutorials(doc.category, doc._lang);
1922
const toc = buildTOC(doc.body);
2023
---
2124

@@ -30,13 +33,20 @@ const toc = buildTOC(doc.body);
3033
active={doc._path}
3134
title={doc.category.title}
3235
links={section}
36+
tutorials={tutorials}
37+
ttitle="Tutorials"
3338
client:visible
3439
slot="subnav"
3540
/>
3641
<!-- Main content area -->
3742
<Text body={doc.body} slot="content" />
3843
<!-- Extras sidebar -->
39-
<Fragment slot="extras">
44+
<div slot="extras">
45+
{
46+
doc.software && (
47+
<Software software={doc.software} microcopy={microcopy.meta.tools} />
48+
)
49+
}
4050
{toc.length > 0 && <TOC toc={toc} client:idle title={microcopy.meta.toc} />}
41-
</Fragment>
51+
</div>
4252
</Doc>

site/src/pages/[lang]/[landing].astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Section from '$layouts/section.astro';
33
44
import { landings, microcopy as micro } from '$lib/sanity';
5-
import { buildSection, buildTopics } from '$lib/documentation';
5+
import { buildSection, buildTopics, buildTutorials } from '$lib/documentation';
66
77
import SectionNav from '$components/SectionNav.svelte';
88
import Text from '$components/Text.astro';
@@ -34,6 +34,7 @@ export function getStaticPaths() {
3434
const { landing, microcopy } = Astro.props;
3535
3636
const section = buildSection(landing.category, landing._lang);
37+
const tutorials = buildTutorials(landing.category, landing._lang);
3738
const topics = buildTopics(section.map((s) => s.href));
3839
3940
let color = 'var(--primary-blue)';
@@ -60,6 +61,8 @@ switch (landing.category.slug) {
6061
active={landing._path}
6162
title={landing.category.title}
6263
links={section}
64+
tutorials={tutorials}
65+
ttitle="Tutorials"
6366
client:visible
6467
slot="subnav"
6568
/>

0 commit comments

Comments
 (0)