Repository navigation
Expand file tree
/
Copy pathmod.ts
More file actions
205 lines (195 loc) · 5.41 KB
/
Copy pathmod.ts
File metadata and controls
205 lines (195 loc) · 5.41 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* This module exports the Aplós theme for Steno, ported from the Aplós
* VitePress theme (https://aplos.gxbs.dev/).
*
* @module
*/
import type { StenoTheme } from "@steno/steno";
import { compileFromUrls } from "plugin-scss";
import pluginShiki from "plugin-shiki";
// fetch() works universally: file:// for local/bundled imports, https://
// for direct JSR imports (jsr:@gabs/aplos@x.y.z).
async function readLocal(path: string): Promise<string> {
return await fetch(new URL(path, import.meta.url)).then((r) => r.text());
}
async function loadTemplates(
directory: string,
templates: Record<string, string>,
): Promise<Record<string, string>> {
return Object.fromEntries(
await Promise.all(
Object.entries(templates).map(async ([name, file]) => [
name,
await readLocal(`./${directory}/${file}.tau`),
]),
),
);
}
const layouts = await loadTemplates("layouts", {
layout: "layout",
article: "article",
articles: "articles",
helpful: "helpful",
notfound: "notfound",
});
const components = await loadTemplates("components", {
Footer: "footer",
Head: "head",
Helpful: "helpful",
Nav: "nav",
ShellEnd: "shell-end",
ShellStart: "shell-start",
Toc: "toc",
});
// Compiled once at theme-load time; ordered to match assets/style.scss.
const style = await compileFromUrls(
import.meta.url,
[
"colors",
"base",
"icons",
"navigation",
"content",
"components",
"home",
"responsive",
"article",
"notfound",
"collections",
].map((name) => `./assets/scss/_${name}.scss`),
);
const site = await readLocal("./assets/site.js");
const aplosMarkdown = {
name: "aplos-markdown",
transformHtml(html: string): string {
return html.replace(
/<blockquote>\s*<p>\[!(INFO|TIP|NOTE|WARNING|DANGER)\](?:[ \t]+(?:Info|Tip|Note|Warning|Danger))?[ \t]*\n?([\s\S]*?)<\/blockquote>/g,
(_match, kind: string, body: string) => {
const title = kind.charAt(0) + kind.slice(1).toLowerCase();
const content = body.replace(/^\s*/, "");
const wrapped = content.startsWith("<") ? content : `<p>${content}`;
return `<div class="${kind.toLowerCase()}"><p class="custom-block-title">${title}</p>${wrapped}</div>`;
},
);
},
};
const linkListSchema = {
type: "array" as const,
items: {
type: "object" as const,
properties: {
title: { type: "string" as const },
text: { type: "string" as const },
url: { type: "string" as const },
link: { type: "string" as const },
},
},
};
/** Aplós theme, ported to Steno. */
const theme: StenoTheme = {
name: "aplos",
version: "0.3.0",
layouts,
components,
assets: {
"style.css": style,
"site.js": site,
},
plugins: [aplosMarkdown, pluginShiki()],
defaultConfig: {
author: "",
currentYear: new Date().getFullYear(),
locale: "en-US",
nav: { show: true },
articles: { authors: true },
footer: {
copyright: true,
poweredBy: true,
},
},
configSchema: {
accent: { type: "string", description: "Light-mode accent color" },
accentDark: { type: "string", description: "Dark-mode accent color" },
author: { type: "string", default: "" },
locale: { type: "string", default: "en-US" },
currentYear: { type: "integer" },
links: { type: "string", enum: ["default", "icons"], default: "default" },
minimal: { type: "boolean", default: false },
numericHeadings: { type: "boolean", default: false },
webFonts: {
type: "boolean",
default: true,
description: "Load Inter/Geist Mono from Google Fonts. " +
"Set false to use the system font stack only, no network request.",
},
nav: {
type: "object",
properties: {
show: { type: "boolean", default: true },
title: { type: "string" },
rss: { type: "string" },
git: { type: "string" },
links: linkListSchema,
},
},
social: {
type: "object",
properties: {
image: { type: "string" },
twitterCard: {
type: "string",
enum: ["summary", "summary_large_image"],
default: "summary_large_image",
},
},
},
articles: {
type: "object",
properties: {
authors: { type: "boolean", default: true },
message: { type: "string" },
},
},
footer: {
type: "object",
properties: {
startYear: { type: "string" },
message: { type: "string" },
copyright: { type: "boolean", default: true },
customCopyright: { type: "string" },
custom: {
type: "object",
properties: {
copyright: { type: "string" },
},
},
poweredBy: { type: "boolean", default: true },
madeby: {
type: "object",
properties: {
show: { type: "boolean", default: false },
name: { type: "string" },
link: { type: "string" },
},
},
copyleft: {
type: "object",
properties: {
show: { type: "boolean", default: false },
license: { type: "string" },
info: { type: "string" },
},
},
sourcecode: {
type: "object",
properties: {
show: { type: "boolean", default: false },
link: { type: "string" },
},
},
links: linkListSchema,
},
},
},
};
export default theme;