@dino-ovum/preset 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/config.js +4 -26
- package/src/index.js +4 -1
- package/src/options.js +6 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.2.0",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "4BFC",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"docusaurus-plugin-sass": "^0.2.7",
|
|
35
35
|
"sass": "^1.106.1",
|
|
36
36
|
"prism-react-renderer": "^2.3.0",
|
|
37
|
-
"@dino-ovum/theme": "0.
|
|
37
|
+
"@dino-ovum/theme": "0.2.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@docusaurus/core": "3.10.1",
|
package/src/config.js
CHANGED
|
@@ -19,19 +19,6 @@ export function mergeConfig(defaults, overrides) {
|
|
|
19
19
|
return result;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
23
|
-
|
|
24
|
-
// activeBaseRegex is tested against the full pathname, which carries the
|
|
25
|
-
// baseUrl and, outside the default locale, a locale segment.
|
|
26
|
-
export function createHomeActiveRegex({baseUrl, home, localePrefixes}) {
|
|
27
|
-
const base = escapeRegex(`/${baseUrl.replace(/^\/+|\/+$/g, '')}/`.replace(/^\/\/$/, '/'));
|
|
28
|
-
const locale = localePrefixes.length
|
|
29
|
-
? `(?:(?:${localePrefixes.map(escapeRegex).join('|')})/)?`
|
|
30
|
-
: '';
|
|
31
|
-
const homePath = home.replace(/^\/+|\/+$/g, '');
|
|
32
|
-
return `^${base}${locale}${homePath ? `${escapeRegex(homePath)}/?` : ''}$`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
22
|
export function createDinoConfig(siteConfig, presetOptions = {}) {
|
|
36
23
|
if (!siteConfig?.title || !siteConfig?.url) {
|
|
37
24
|
throw new TypeError('createDinoConfig requires a site title and URL.');
|
|
@@ -43,13 +30,6 @@ export function createDinoConfig(siteConfig, presetOptions = {}) {
|
|
|
43
30
|
ko: {label: '한국어', htmlLang: 'ko'},
|
|
44
31
|
ja: {label: '日本語', htmlLang: 'ja'},
|
|
45
32
|
};
|
|
46
|
-
const home = `/${options.documents.routeBasePath.replace(/^\/+|\/+$/g, '')}`;
|
|
47
|
-
const defaultLocale = siteConfig.i18n?.defaultLocale ?? locales[0];
|
|
48
|
-
const homeActiveRegex = createHomeActiveRegex({
|
|
49
|
-
baseUrl: siteConfig.baseUrl ?? '/',
|
|
50
|
-
home,
|
|
51
|
-
localePrefixes: locales.filter((locale) => locale !== defaultLocale),
|
|
52
|
-
});
|
|
53
33
|
const defaults = {
|
|
54
34
|
baseUrl: '/',
|
|
55
35
|
staticDirectories: ['public'],
|
|
@@ -74,14 +54,12 @@ export function createDinoConfig(siteConfig, presetOptions = {}) {
|
|
|
74
54
|
title: siteConfig.title,
|
|
75
55
|
items: [
|
|
76
56
|
{type: 'custom-sidebarToggle', position: 'left'},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
label: 'Home',
|
|
80
|
-
position: 'right',
|
|
81
|
-
activeBaseRegex: homeActiveRegex,
|
|
82
|
-
},
|
|
57
|
+
// The site title already links home; its old place opens the comment drawer.
|
|
58
|
+
...(options.comments ? [{type: 'custom-comments', position: 'right'}] : []),
|
|
83
59
|
...(options.updates ? [{type: 'custom-recentUpdates', position: 'right'}] : []),
|
|
84
60
|
...(locales.length > 1 ? [{type: 'custom-languageDropdown', position: 'right'}] : []),
|
|
61
|
+
// On narrow screens it holds recent updates, languages, and the color mode.
|
|
62
|
+
{type: 'custom-moreMenu', position: 'right'},
|
|
85
63
|
],
|
|
86
64
|
},
|
|
87
65
|
prism: {theme: prismThemes.github, darkTheme: prismThemes.dracula},
|
package/src/index.js
CHANGED
|
@@ -94,7 +94,10 @@ export default function dinoPreset(context, presetOptions = {}) {
|
|
|
94
94
|
],
|
|
95
95
|
]
|
|
96
96
|
: []),
|
|
97
|
-
[
|
|
97
|
+
[
|
|
98
|
+
require.resolve('@dino-ovum/theme'),
|
|
99
|
+
{customCss: options.customCss, comments: options.comments},
|
|
100
|
+
],
|
|
98
101
|
],
|
|
99
102
|
};
|
|
100
103
|
}
|
package/src/options.js
CHANGED
|
@@ -5,7 +5,7 @@ export function resolveOptions(options = {}) {
|
|
|
5
5
|
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
6
6
|
throw new TypeError('Dino Ovum options must be an object.');
|
|
7
7
|
}
|
|
8
|
-
const supported = ['documents', 'customCss', 'search', 'pwa', 'updates'];
|
|
8
|
+
const supported = ['documents', 'customCss', 'search', 'pwa', 'updates', 'comments'];
|
|
9
9
|
for (const key of Object.keys(options)) {
|
|
10
10
|
if (!supported.includes(key)) throw new TypeError(`Unknown Dino Ovum option: ${key}`);
|
|
11
11
|
}
|
|
@@ -30,8 +30,10 @@ export function resolveOptions(options = {}) {
|
|
|
30
30
|
throw new TypeError(`${key} must be a boolean or an options object.`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
for (const key of ['updates', 'comments']) {
|
|
34
|
+
if (options[key] !== undefined && typeof options[key] !== 'boolean') {
|
|
35
|
+
throw new TypeError(`${key} must be a boolean.`);
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
const customCss =
|
|
37
39
|
options.customCss === undefined
|
|
@@ -55,5 +57,6 @@ export function resolveOptions(options = {}) {
|
|
|
55
57
|
search: options.search ?? true,
|
|
56
58
|
pwa: options.pwa ?? false,
|
|
57
59
|
updates: options.updates ?? false,
|
|
60
|
+
comments: options.comments ?? false,
|
|
58
61
|
};
|
|
59
62
|
}
|