-
Notifications
You must be signed in to change notification settings - Fork 66
/
content.ts
111 lines (90 loc) · 2.69 KB
/
content.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { Document, PageFrontmatter, useDocuments } from "iles";
import { marked } from "marked";
// Quick start pages
export type QuickStartPageProps = {
title: string;
summary?: string[];
order: number;
};
export type QuickStartPage = Document<QuickStartPageProps>;
const quickStartPages: QuickStartPage[] =
useDocuments<QuickStartPageProps>("~/pages/start").value;
export const numQuickStartPages: number = quickStartPages.length;
export const sortedQuickStartPages: QuickStartPage[] = quickStartPages.sort(
(p1: QuickStartPage, p2: QuickStartPage) => p1.order - p2.order,
);
// Concept pages
export type ExternalSource = {
title: string;
href: string;
source?: {
title: string;
href: string;
};
};
export type ConceptPageProps = {
title: string;
id: string; // Generated by extendFrontMatter in iles.config.ts
snippet: string;
externalSources?: ExternalSource[];
related?: string[];
wip: boolean;
};
export type ConceptPage = Document<ConceptPageProps>;
export const conceptPages: ConceptPage[] =
useDocuments<ConceptPageProps>("~/pages/concepts").value;
export const conceptPage = (id: string): ConceptPage =>
conceptPages.find((page: ConceptPage) => page.id === id)!;
// Pagination
export const getPrevious = (order: number): QuickStartPage | undefined =>
quickStartPages.find((p: QuickStartPage) => p.order === order - 1);
export const getNext = (order: number): QuickStartPage | undefined =>
quickStartPages.find((p: QuickStartPage) => p.order === order + 1);
// Related concepts
export const relatedConceptPages = (
currentHref: string,
ids: string[],
): ConceptPage[] =>
ids.map((id: string) => {
const maybePage = conceptPages.find((page: ConceptPage) => page.id === id);
if (maybePage === undefined) {
throw new Error(
`No concept page found for concept id ${id} in the front matter for page ${currentHref}`,
);
}
return maybePage!;
});
// Briefs
type BriefProps = {
id: string;
};
export type BriefPage = Document<BriefProps>;
export const getBrief = (id: string): BriefPage =>
useDocuments<BriefProps>("~/briefs").value.find(
(page: BriefPage) => page.id === id,
)!;
// Plain pages (like the About page)
export type PlainPageProps = {
title: string;
description?: string;
};
// Render small Markdown snippets without the encapsulating <p>...</p>
export const md = (input: string): string => marked.parseInline(input);
// Dropdowns
export type DropdownProps = {
text: string;
pages: PageFrontmatter[];
};
// Other stuff
export type ButtonProps = {
text: string;
href: string;
highlight?: boolean;
};
export type BreadcrumbProps = {
back: {
title: string;
href: string;
};
title: string;
};