-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdocusaurus.config.mts
More file actions
413 lines (377 loc) · 11 KB
/
docusaurus.config.mts
File metadata and controls
413 lines (377 loc) · 11 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import { themes as prismThemes } from "prism-react-renderer";
import type { Config } from "@docusaurus/types";
import type * as Preset from "@docusaurus/preset-classic";
import type {
NormalizedSidebarItem,
SidebarItemsGeneratorDoc,
} from "@docusaurus/plugin-content-docs/src/sidebars/types.js";
import remarkGithubAdmonitionsToDirectives from "remark-github-admonitions-to-directives";
import * as path from "path";
import * as fs from "fs";
import { AlphaTabWebPackPlugin } from "@coderline/alphatab-webpack";
import { RuleSetRule } from "webpack";
const alphaTabVersionFull = JSON.parse(
fs.readFileSync(
path.join("node_modules", "@coderline", "alphatab", "package.json"),
"utf8"
)
).version;
const isPreRelease = alphaTabVersionFull.indexOf("-") >= 0;
let alphaTabVersion;
let algoliaAppId = '26AE6KNYRK';
let algoliaApiKey = '3db9646111702a74fe1f2249ddafa870';
let algoliaIndexName;
if (isPreRelease) {
alphaTabVersion = alphaTabVersionFull.substring(
0,
alphaTabVersionFull.indexOf("-")
);
algoliaIndexName = 'next_alphaTab';
} else {
alphaTabVersion = alphaTabVersionFull;
algoliaIndexName = 'alphaTab';
}
function getSortValue(
prop: string,
docs: Map<string, SidebarItemsGeneratorDoc>,
item: NormalizedSidebarItem
): string | number | undefined {
if (prop in item) {
return item[prop];
}
switch (item.type) {
case "doc":
const doc = docs.get(item.id);
if (doc) {
if (prop in doc) {
return doc[prop];
}
if (prop in doc.frontMatter) {
switch (typeof doc.frontMatter[prop]) {
case "number":
case "string":
return doc.frontMatter[prop];
case "undefined":
break;
default:
return String(doc.frontMatter[prop]);
}
}
}
break;
case "category":
if (prop === "title") {
return item.label;
}
break;
}
if (item.customProps && prop in item.customProps) {
switch (typeof item.customProps[prop]) {
case "number":
case "string":
return item.customProps[prop];
default:
return String(item.customProps[prop]);
}
}
// console.warn(`Could not get sort prop '${prop}' on sidebar item`, item);
return undefined;
}
const config: Config = {
title: "alphaTab",
tagline: "Build modern music notation apps for web, desktop and mobile",
url: "https://alphatab.net",
baseUrl: "/",
favicon: "img/favicon.ico",
organizationName: "CoderLine",
projectName: "alphaTab",
onBrokenLinks: "throw",
customFields: {
isPreRelease: isPreRelease,
alphaTabVersion: alphaTabVersion,
alphaTabVersionFull: alphaTabVersionFull,
},
markdown: {
mermaid: true,
hooks: {
onBrokenMarkdownLinks: "warn",
}
},
themes: ["@docusaurus/theme-mermaid"],
presets: [
[
"classic",
{
docs: {
sidebarPath: "./sidebars.ts",
editUrl: "https://github.com/CoderLine/alphaTabWebsite/tree/main/",
beforeDefaultRemarkPlugins: [remarkGithubAdmonitionsToDirectives],
async sidebarItemsGenerator({
defaultSidebarItemsGenerator,
...args
}) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
if (Array.isArray(args.item.customProps?.["sort"])) {
let props = args.item.customProps?.["sort"] as
| [string, string]
| [string, string][];
if (!Array.isArray(props[0])) {
props = [props as [string, string]];
}
const docsLookup = new Map<string, SidebarItemsGeneratorDoc>(
args.docs.map((d) => [d.id, d])
);
// Reverse items in categories
sidebarItems.sort((a, b) => {
for (const prop of props) {
const ascending = prop[1] !== "desc";
let av = getSortValue(prop[0], docsLookup, a);
let bv = getSortValue(prop[0], docsLookup, b);
if (typeof av !== typeof bv) {
av = av === undefined ? av : String(av);
bv = bv === undefined ? bv : String(bv);
}
var result = 0;
if (av === undefined && bv === undefined) {
// continue
} else if (av === undefined) {
return -1;
} else if (bv === undefined) {
return 1;
} else if (typeof av === "string") {
if (ascending) {
result = av.localeCompare(bv as string);
} else {
result = (bv as string).localeCompare(av);
}
} else {
if (ascending) {
result = av - (bv as number);
} else {
result = (bv as number) - av;
}
}
if (result !== 0) {
return result;
}
}
return 0;
});
}
return sidebarItems;
},
},
theme: {
customCss: "./src/css/custom.scss",
},
sitemap: {
async createSitemapItems({defaultCreateSitemapItems, ...params}) {
const defaultItems = await defaultCreateSitemapItems(params);
// rank reference type docs lower than manual docs
for(const item of defaultItems) {
if(item.url.includes('reference/types')) {
item.priority = 0.1;
}
}
return defaultItems;
},
}
} satisfies Preset.Options,
],
],
themeConfig: {
docs: {
sidebar: {
hideable: true,
},
},
navbar: {
title: "alphaTab",
logo: {
alt: "alphaTab Logo",
src: "img/alphaTab.png",
},
items: [
{
type: "doc",
docId: "introduction",
position: "left",
label: "Docs",
},
{
type: "doc",
docId: "tutorials",
position: "left",
label: "Tutorial",
},
{
type: "doc",
docId: "alphatex/introduction",
position: "left",
label: "alphaTex",
},
{
type: "doc",
docId: "showcase/introduction",
position: "left",
label: "Showcase",
},
{
type: "doc",
docId: "playground/playground",
position: "left",
label: "Playground",
},
// Right
{
type: "dropdown",
position: "right",
label: isPreRelease ? `${alphaTabVersion} 🚧` : alphaTabVersion,
items: [
{
href: "https://next.alphatab.net",
label: "Next Version 🚧",
},
{
href: "https://alphatab.net",
label: "Stable Version",
},
],
},
{
href: "https://github.com/CoderLine/alphaTab",
label: "GitHub",
className: "header-github-link",
position: "right",
},
],
},
footer: {
style: "dark",
links: [
{
title: "Docs",
items: [
{
label: "Introduction",
to: "docs/introduction",
},
{
label: "Installation",
to: "docs/getting-started/installation-web",
},
{
label: "AlphaTex",
to: "docs/alphatex/introduction",
},
],
},
{
title: "Community",
items: [
{
label: "GitHub",
href: "https://github.com/CoderLine/alphaTab",
},
{
label: "Stack Overflow",
href: "https://stackoverflow.com/questions/tagged/alphatab",
},
],
},
],
copyright: `Copyright © ${new Date().getFullYear()} Daniel Kuschny and Contributors`,
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
additionalLanguages: ["csharp", "diff", "kotlin", "groovy"],
},
colorMode: {
defaultMode: 'light'
},
algolia: {
appId: algoliaAppId,
apiKey: algoliaApiKey,
indexName: algoliaIndexName
},
} satisfies Preset.ThemeConfig,
plugins: [
"docusaurus-plugin-sass",
() => ({
name: "docusaurus-customization",
injectHtmlTags() {
return {};
},
configureWebpack(config, isServer, options) {
const matchRule = (r: RuleSetRule) => {
if (typeof r === "object") {
if (r.test instanceof RegExp) {
return !!r.test.exec("custom.sass");
} else if (typeof r.test === "undefined") {
return true;
} else {
// unsupported
return false;
}
} else {
return false;
}
};
let sassRule = config.module!.rules!.find(matchRule);
if (typeof sassRule !== "object") {
throw new Error("Could not find SASS rule");
}
if (sassRule!.oneOf) {
sassRule = sassRule!.oneOf.find(matchRule);
}
if (typeof sassRule !== "object") {
throw new Error("Could not find inner SASS rule");
}
if (!Array.isArray(sassRule!.use)) {
throw new Error("Need SASS rule with use[]");
}
const sassLoaderIndex = sassRule!.use.findIndex(
(l) => typeof l === "object" && l!.loader?.includes("sass-loader")
);
if (sassLoaderIndex === -1) {
throw new Error("Could not find sass-loader in rule");
}
// ensure source-map before resolve-url-loader
const sassLoader = sassRule!.use[sassLoaderIndex] as RuleSetRule;
sassLoader.options = {
...((sassLoader.options as object | undefined) ?? {}),
sourceMap: true, // force sourcemaps
};
// insert resolve-url-loader before SASS loader to fix relative URLs
sassRule!.use.splice(sassLoaderIndex, 0, {
loader: "resolve-url-loader",
});
return {
plugins: [
// Copy the Font and SoundFont Files to the output
new AlphaTabWebPackPlugin({
assetOutputDir: config.output!.path,
}),
],
resolve: {
fallback: {
fs: false,
buffer: false,
path: false,
os: false,
util: false,
assert: false,
stream: false,
crypto: false,
constants: false,
child_process: false,
module: false,
},
},
};
},
}),
],
};
export default config;