-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathdocusaurus.config.mts
More file actions
214 lines (197 loc) · 5.83 KB
/
docusaurus.config.mts
File metadata and controls
214 lines (197 loc) · 5.83 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
206
207
208
209
210
211
212
213
214
import type { Config } from "@docusaurus/types";
import type { Root } from "mdast";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { dirname, extname, relative, resolve } from "node:path";
import { themes } from "prism-react-renderer";
import type { Transformer } from "unified";
import { visit } from "unist-util-visit";
const require = createRequire(import.meta.url);
const docsRelative = "packages/app-web-docs/src/docs/";
const userRelative = docsRelative + "user";
const contributingRelative = docsRelative + "contributing";
const repoLink = "https://github.com/cursorless-dev/cursorless/tree/main/";
/**
* Files within /docs reference repository directories
* and files outside of that folder. They are not served
* in documentation hub.
*
* This plugin rewrites these links to point to GitHub.
* The algorithm roughly is:
* - For each link:
* - If absolute or already relative to index - do nothing.
* - Try resolving it relative to repo root.
* - If anywhere but /docs - link to GitHub.
*/
function remarkPluginFixLinksToRepositoryArtifacts(): Transformer<Root> {
return (ast, file) => {
visit(ast, "link", (node) => {
const { url } = node;
if (url.startsWith("http://") || url.startsWith("https://")) {
return;
}
// Docusaurus runs this plugin on its intermediate
// markdown representaiton as well as on our original files.
// These are relative links that docusaurus already figured out
// based on realative links to .md files
if (url.startsWith("/docs/")) {
return;
}
const repoRoot = resolve(
dirname(fileURLToPath(import.meta.url)),
"../..",
);
const artifact = resolve(file.dirname!, url);
const artifactRelative = relative(repoRoot, artifact).replace(/\\/g, "/");
const fileRelative = relative(repoRoot, file.path).replace(/\\/g, "/");
// We host all files under docs. Will resolve as a relative link, but
// relative links pointing to a folder passing between user and
// contributing are not resolved correctly by docusaurus so we need to
// rewrite them.
if (artifactRelative.startsWith(docsRelative)) {
if (
isFolder(url) &&
passingBetweenUserAndContributing(fileRelative, artifactRelative)
) {
node.url = "/docs/" + artifactRelative.slice(docsRelative.length);
}
return;
}
node.url = repoLink + artifactRelative;
});
};
}
function isFolder(url: string) {
return !extname(url);
}
function passingBetweenUserAndContributing(
fileRelative: string,
artifactRelative: string,
): boolean {
return fileRelative.startsWith(userRelative)
? !artifactRelative.startsWith(userRelative)
: !artifactRelative.startsWith(contributingRelative);
}
const config: Config = {
title: "Cursorless",
tagline: "Structural voice coding at the speed of thought",
url: "https://www.cursorless.org",
baseUrl: "/docs/",
onBrokenLinks: "throw",
onBrokenAnchors: "throw",
trailingSlash: true,
future: {
v4: {
removeLegacyPostBuildHeadAttribute: true,
},
experimental_faster: true,
},
stylesheets: [
// Icons generated with https://favicon.io/favicon-generator/
{
rel: "icon",
type: "image/svg+xml",
href: "/favicon.svg",
},
{
rel: "apple-touch-icon",
sizes: "180x180",
href: "/apple-touch-icon.png?v=1",
},
{
rel: "icon",
type: "image/png",
sizes: "32x32",
href: "/favicon-32x32.png?v=1",
},
{
rel: "icon",
type: "image/png",
sizes: "16x16",
href: "/favicon-16x16.png?v=1",
},
{ rel: "manifest", href: "/site.webmanifest?v=1" },
{
rel: "mask-icon",
href: "/safari-pinned-tab.svg?v=1",
color: "#7c7c7c",
},
{ rel: "shortcut icon", href: "/favicon.ico?v=1" },
],
markdown: {
hooks: {
onBrokenMarkdownLinks: "throw",
},
},
presets: [
[
"classic",
{
docs: {
path: "./src/docs",
// Followed https://ricard.dev/how-to-set-docs-as-homepage-for-docusaurus/
// to serve a markdown document on homepage
routeBasePath: "/",
editUrl:
"https://github.com/cursorless-dev/cursorless/edit/main/packages/app-web-docs/",
sidebarPath: require.resolve("./sidebar.js"),
beforeDefaultRemarkPlugins: [
remarkPluginFixLinksToRepositoryArtifacts,
],
},
theme: {
customCss: [require.resolve("./src/css/custom.scss")],
},
},
],
],
plugins: ["docusaurus-plugin-sass", "./src/plugins/scope-tests-plugin.ts"],
themeConfig: {
navbar: {
title: "Cursorless",
logo: {
alt: "Cursorless",
src: "logo.svg",
srcDark: "logo-dark.svg",
href: "https://www.cursorless.org/",
target: "_self",
},
items: [
{
position: "left",
type: "docSidebar",
to: "user/",
sidebarId: "user",
label: "For users",
},
{
type: "docSidebar",
position: "left",
to: "contributing/",
sidebarId: "contributing",
label: "For contributors",
},
{
href: "https://github.com/cursorless-dev/cursorless",
position: "right",
className: "header-github-link",
["aria-label"]: "GitHub repository",
},
],
},
prism: {
theme: themes.github,
darkTheme: themes.dracula,
additionalLanguages: ["bash", "diff", "json", "python", "lua"],
},
colorMode: {
respectPrefersColorScheme: true,
},
algolia: {
appId: "YTJQ4I3GBJ",
apiKey: "2cc808dde95f119a19420ddc2941ee7d",
indexName: "cursorless",
},
},
};
export default config;