@dino-ovum/preset 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +19 -2
- package/package.json +41 -3
- package/src/config.js +96 -0
- package/src/index.js +100 -0
- package/src/options.js +59 -0
- package/src/plugins/generated-module-compat.js +27 -0
- package/src/plugins/manifest.js +46 -0
- package/src/plugins/navigation.js +115 -0
- package/src/plugins/recent-updates.js +66 -0
- package/src/sidebar-items.js +19 -0
- package/src/sidebars.js +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 4BFC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dino-ovum/preset
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Docusaurus configuration and shared document, navigation, search, and PWA plugins for Dino Ovum.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import {createDinoConfig} from '@dino-ovum/preset/config';
|
|
7
|
+
|
|
8
|
+
export default createDinoConfig(
|
|
9
|
+
{title: 'My documents', url: 'https://example.com'},
|
|
10
|
+
{customCss: './src/css/custom.css', updates: true},
|
|
11
|
+
);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The preset includes the compatible `@dino-ovum/theme`. Use Docusaurus 3.10.1, React 19, and Node.js 24.22.1–24.x. Documents default to `documents/`, with translations under `documents/_translations/`.
|
|
15
|
+
|
|
16
|
+
Search is enabled by default. PWA and the `/updates` page are opt-in. Site settings override defaults; nested objects merge and arrays replace. Additional site plugins, themes, and presets are retained.
|
|
17
|
+
|
|
18
|
+
Read the [configuration guide](https://github.com/4BFC/dino-ovum/blob/main/docs/configuration.md) for options, translation overrides, and migration. See the [repository README](https://github.com/4BFC/dino-ovum#install) for local archive installation while the initial release is being prepared.
|
|
19
|
+
|
|
20
|
+
MIT. Dependencies retain their own licenses.
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "4BFC",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=24.22.1 <25"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/4BFC/dino-ovum.git"
|
|
20
|
+
},
|
|
2
21
|
"name": "@dino-ovum/preset",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
22
|
+
"description": "Shared Docusaurus configuration and plugins for Dino Ovum.",
|
|
23
|
+
"main": "./src/index.js",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": "./src/index.js",
|
|
26
|
+
"./config": "./src/config.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@docusaurus/preset-classic": "3.10.1",
|
|
31
|
+
"@docusaurus/plugin-pwa": "3.10.1",
|
|
32
|
+
"@docusaurus/theme-mermaid": "3.10.1",
|
|
33
|
+
"@easyops-cn/docusaurus-search-local": "^0.55.3",
|
|
34
|
+
"docusaurus-plugin-sass": "^0.2.7",
|
|
35
|
+
"sass": "^1.106.1",
|
|
36
|
+
"prism-react-renderer": "^2.3.0",
|
|
37
|
+
"@dino-ovum/theme": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@docusaurus/core": "3.10.1",
|
|
41
|
+
"react": "^19.0.0",
|
|
42
|
+
"react-dom": "^19.0.0"
|
|
43
|
+
}
|
|
6
44
|
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {fileURLToPath} from 'node:url';
|
|
2
|
+
import {themes as prismThemes} from 'prism-react-renderer';
|
|
3
|
+
import {resolveOptions} from './options.js';
|
|
4
|
+
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return (
|
|
7
|
+
value !== null && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Arrays replace defaults; objects merge. Inputs are never mutated.
|
|
12
|
+
export function mergeConfig(defaults, overrides) {
|
|
13
|
+
const result = {...defaults};
|
|
14
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
15
|
+
if (value === undefined) continue;
|
|
16
|
+
result[key] =
|
|
17
|
+
isRecord(value) && isRecord(defaults[key]) ? mergeConfig(defaults[key], value) : value;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
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
|
+
export function createDinoConfig(siteConfig, presetOptions = {}) {
|
|
36
|
+
if (!siteConfig?.title || !siteConfig?.url) {
|
|
37
|
+
throw new TypeError('createDinoConfig requires a site title and URL.');
|
|
38
|
+
}
|
|
39
|
+
const options = resolveOptions(presetOptions);
|
|
40
|
+
const locales = siteConfig.i18n?.locales ?? ['en', 'ko', 'ja'];
|
|
41
|
+
const knownLocales = {
|
|
42
|
+
en: {label: 'English', htmlLang: 'en'},
|
|
43
|
+
ko: {label: '한국어', htmlLang: 'ko'},
|
|
44
|
+
ja: {label: '日本語', htmlLang: 'ja'},
|
|
45
|
+
};
|
|
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
|
+
const defaults = {
|
|
54
|
+
baseUrl: '/',
|
|
55
|
+
staticDirectories: ['public'],
|
|
56
|
+
// v4 enables Faster implicitly; keep it opt-in so consumers do not need
|
|
57
|
+
// the optional native bundler package just to use this preset.
|
|
58
|
+
future: {v4: true, faster: false},
|
|
59
|
+
storage: {type: 'localStorage', namespace: 'dino-ovum'},
|
|
60
|
+
onBrokenLinks: 'throw',
|
|
61
|
+
onDuplicateRoutes: 'throw',
|
|
62
|
+
markdown: {format: 'detect', mermaid: true},
|
|
63
|
+
i18n: {
|
|
64
|
+
defaultLocale: locales[0],
|
|
65
|
+
locales,
|
|
66
|
+
path: `${options.documents.path}/_translations`,
|
|
67
|
+
localeConfigs: Object.fromEntries(
|
|
68
|
+
locales.map((locale) => [locale, knownLocales[locale] ?? {}]),
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
themeConfig: {
|
|
72
|
+
colorMode: {defaultMode: 'light', respectPrefersColorScheme: false},
|
|
73
|
+
navbar: {
|
|
74
|
+
title: siteConfig.title,
|
|
75
|
+
items: [
|
|
76
|
+
{type: 'custom-sidebarToggle', position: 'left'},
|
|
77
|
+
{
|
|
78
|
+
to: home,
|
|
79
|
+
label: 'Home',
|
|
80
|
+
position: 'right',
|
|
81
|
+
activeBaseRegex: homeActiveRegex,
|
|
82
|
+
},
|
|
83
|
+
...(options.updates ? [{type: 'custom-recentUpdates', position: 'right'}] : []),
|
|
84
|
+
...(locales.length > 1 ? [{type: 'custom-languageDropdown', position: 'right'}] : []),
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
prism: {theme: prismThemes.github, darkTheme: prismThemes.dracula},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const config = mergeConfig(defaults, siteConfig);
|
|
91
|
+
config.presets = [
|
|
92
|
+
[fileURLToPath(new URL('./index.js', import.meta.url)), presetOptions],
|
|
93
|
+
...(siteConfig.presets ?? []),
|
|
94
|
+
];
|
|
95
|
+
return config;
|
|
96
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {createRequire} from 'node:module';
|
|
2
|
+
import classicPreset from '@docusaurus/preset-classic';
|
|
3
|
+
import {normalizePath, documentDates, documentLocation} from '@dino-ovum/theme/utils';
|
|
4
|
+
import {resolveOptions} from './options.js';
|
|
5
|
+
import navigation from './plugins/navigation.js';
|
|
6
|
+
import recentUpdates from './plugins/recent-updates.js';
|
|
7
|
+
import generatedModuleCompat from './plugins/generated-module-compat.js';
|
|
8
|
+
import manifestPlugin from './plugins/manifest.js';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
const classicRequire = createRequire(require.resolve('@docusaurus/preset-classic'));
|
|
12
|
+
const classicThemeRequire = createRequire(classicRequire.resolve('@docusaurus/theme-classic'));
|
|
13
|
+
|
|
14
|
+
// pnpm can instantiate the same Docusaurus version with different optional
|
|
15
|
+
// peer sets. React context providers and consumers must share one module.
|
|
16
|
+
function sharedClientContexts() {
|
|
17
|
+
return {
|
|
18
|
+
name: 'dino-ovum-client-contexts',
|
|
19
|
+
configureWebpack() {
|
|
20
|
+
return {
|
|
21
|
+
resolve: {
|
|
22
|
+
alias: {
|
|
23
|
+
'@docusaurus/theme-common$': classicThemeRequire.resolve('@docusaurus/theme-common'),
|
|
24
|
+
'@docusaurus/theme-common/internal$': classicThemeRequire.resolve(
|
|
25
|
+
'@docusaurus/theme-common/internal',
|
|
26
|
+
),
|
|
27
|
+
'@docusaurus/theme-common/Details$': classicThemeRequire.resolve(
|
|
28
|
+
'@docusaurus/theme-common/Details',
|
|
29
|
+
),
|
|
30
|
+
'@docusaurus/plugin-content-docs/client$': classicRequire.resolve(
|
|
31
|
+
'@docusaurus/plugin-content-docs/client',
|
|
32
|
+
),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function dinoPreset(context, presetOptions = {}) {
|
|
41
|
+
const options = resolveOptions(presetOptions);
|
|
42
|
+
const classic = (classicPreset.default ?? classicPreset)(context, {
|
|
43
|
+
docs: options.documents,
|
|
44
|
+
blog: false,
|
|
45
|
+
sitemap: false,
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
plugins: [
|
|
49
|
+
...classic.plugins,
|
|
50
|
+
require.resolve('docusaurus-plugin-sass'),
|
|
51
|
+
generatedModuleCompat,
|
|
52
|
+
sharedClientContexts,
|
|
53
|
+
[navigation, {normalizePath, documentDates, documentLocation}],
|
|
54
|
+
[
|
|
55
|
+
recentUpdates,
|
|
56
|
+
{documentDates, labels: {default: context.siteConfig.title}, page: options.updates},
|
|
57
|
+
],
|
|
58
|
+
...(options.pwa
|
|
59
|
+
? [
|
|
60
|
+
[
|
|
61
|
+
manifestPlugin,
|
|
62
|
+
{manifest: typeof options.pwa === 'object' ? (options.pwa.manifest ?? {}) : {}},
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
require.resolve('@docusaurus/plugin-pwa'),
|
|
66
|
+
{
|
|
67
|
+
offlineModeActivationStrategies: ['always'],
|
|
68
|
+
...(typeof options.pwa === 'object'
|
|
69
|
+
? Object.fromEntries(
|
|
70
|
+
Object.entries(options.pwa).filter(([key]) => key !== 'manifest'),
|
|
71
|
+
)
|
|
72
|
+
: {}),
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
77
|
+
],
|
|
78
|
+
themes: [
|
|
79
|
+
...classic.themes,
|
|
80
|
+
require.resolve('@docusaurus/theme-mermaid'),
|
|
81
|
+
...(options.search
|
|
82
|
+
? [
|
|
83
|
+
[
|
|
84
|
+
require.resolve('@easyops-cn/docusaurus-search-local'),
|
|
85
|
+
{
|
|
86
|
+
hashed: true,
|
|
87
|
+
language: context.siteConfig.i18n.locales,
|
|
88
|
+
indexBlog: false,
|
|
89
|
+
docsRouteBasePath: [options.documents.routeBasePath],
|
|
90
|
+
docsDir: [options.documents.path],
|
|
91
|
+
highlightSearchTermsOnTargetPage: true,
|
|
92
|
+
...(typeof options.search === 'object' ? options.search : {}),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
]
|
|
96
|
+
: []),
|
|
97
|
+
[require.resolve('@dino-ovum/theme'), {customCss: options.customCss}],
|
|
98
|
+
],
|
|
99
|
+
};
|
|
100
|
+
}
|
package/src/options.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {fileURLToPath} from 'node:url';
|
|
2
|
+
import sidebarItemsGenerator from './sidebar-items.js';
|
|
3
|
+
|
|
4
|
+
export function resolveOptions(options = {}) {
|
|
5
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
6
|
+
throw new TypeError('Dino Ovum options must be an object.');
|
|
7
|
+
}
|
|
8
|
+
const supported = ['documents', 'customCss', 'search', 'pwa', 'updates'];
|
|
9
|
+
for (const key of Object.keys(options)) {
|
|
10
|
+
if (!supported.includes(key)) throw new TypeError(`Unknown Dino Ovum option: ${key}`);
|
|
11
|
+
}
|
|
12
|
+
if (
|
|
13
|
+
options.documents !== undefined &&
|
|
14
|
+
(!options.documents ||
|
|
15
|
+
typeof options.documents !== 'object' ||
|
|
16
|
+
Array.isArray(options.documents))
|
|
17
|
+
) {
|
|
18
|
+
throw new TypeError('documents must configure one document root.');
|
|
19
|
+
}
|
|
20
|
+
if (options.documents?.id && options.documents.id !== 'default') {
|
|
21
|
+
throw new TypeError('Dino Ovum 0.1 supports only the default document instance.');
|
|
22
|
+
}
|
|
23
|
+
for (const key of ['search', 'pwa']) {
|
|
24
|
+
const value = options[key];
|
|
25
|
+
if (
|
|
26
|
+
value !== undefined &&
|
|
27
|
+
typeof value !== 'boolean' &&
|
|
28
|
+
(!value || typeof value !== 'object' || Array.isArray(value))
|
|
29
|
+
) {
|
|
30
|
+
throw new TypeError(`${key} must be a boolean or an options object.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (options.updates !== undefined && typeof options.updates !== 'boolean') {
|
|
34
|
+
throw new TypeError('updates must be a boolean.');
|
|
35
|
+
}
|
|
36
|
+
const customCss =
|
|
37
|
+
options.customCss === undefined
|
|
38
|
+
? []
|
|
39
|
+
: Array.isArray(options.customCss)
|
|
40
|
+
? options.customCss
|
|
41
|
+
: [options.customCss];
|
|
42
|
+
if (customCss.some((filename) => typeof filename !== 'string' || !filename)) {
|
|
43
|
+
throw new TypeError('customCss must be a path or an array of paths.');
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
documents: {
|
|
47
|
+
path: 'documents',
|
|
48
|
+
routeBasePath: '/',
|
|
49
|
+
sidebarPath: fileURLToPath(new URL('./sidebars.js', import.meta.url)),
|
|
50
|
+
sidebarItemsGenerator,
|
|
51
|
+
exclude: ['**/_*/**', '**/_*.{md,mdx}', '**/README.md', '**/AGENTS.md', '**/CLAUDE.md'],
|
|
52
|
+
...options.documents,
|
|
53
|
+
},
|
|
54
|
+
customCss,
|
|
55
|
+
search: options.search ?? true,
|
|
56
|
+
pwa: options.pwa ?? false,
|
|
57
|
+
updates: options.updates ?? false,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Docusaurus 3.10.1 generates mixed ESM/CommonJS (registry, client modules).
|
|
2
|
+
// Scope: generated JS parsing and temporary CommonJS SSG chunks only.
|
|
3
|
+
// Upstream: https://github.com/facebook/docusaurus/discussions/11326
|
|
4
|
+
// Recheck this compatibility layer when upgrading Docusaurus; see docs/development.md.
|
|
5
|
+
export default function generatedModuleCompat({generatedFilesDir}) {
|
|
6
|
+
return {
|
|
7
|
+
name: 'generated-module-compat',
|
|
8
|
+
configureWebpack(config, isServer) {
|
|
9
|
+
return {
|
|
10
|
+
// SSG loads CommonJS chunks with Node require; .cjs overrides root ESM.
|
|
11
|
+
// Client chunk names and the framework's server entry stay unchanged.
|
|
12
|
+
...(isServer && {
|
|
13
|
+
output: {chunkFilename: config.output.chunkFilename.replace(/\.js$/, '.cjs')},
|
|
14
|
+
}),
|
|
15
|
+
module: {
|
|
16
|
+
rules: [
|
|
17
|
+
{
|
|
18
|
+
test: /\.js$/i,
|
|
19
|
+
include: generatedFilesDir,
|
|
20
|
+
type: 'javascript/auto',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {writeFile} from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export function assetUrl(filename, baseUrl) {
|
|
5
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(filename)) return filename;
|
|
6
|
+
if (filename.startsWith(baseUrl)) return filename;
|
|
7
|
+
return `${baseUrl}${filename.replace(/^\/+/, '')}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function createManifest(context, overrides = {}) {
|
|
11
|
+
const {siteConfig, i18n, baseUrl} = context;
|
|
12
|
+
return {
|
|
13
|
+
name: siteConfig.title,
|
|
14
|
+
short_name: siteConfig.title,
|
|
15
|
+
description: siteConfig.tagline ?? '',
|
|
16
|
+
lang: i18n.currentLocale,
|
|
17
|
+
start_url: baseUrl,
|
|
18
|
+
scope: baseUrl,
|
|
19
|
+
display: 'standalone',
|
|
20
|
+
background_color: '#f8f9fa',
|
|
21
|
+
theme_color: '#333333',
|
|
22
|
+
...overrides,
|
|
23
|
+
icons: (overrides.icons ?? []).map((icon) => ({
|
|
24
|
+
...icon,
|
|
25
|
+
src: assetUrl(icon.src, baseUrl),
|
|
26
|
+
})),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function manifestPlugin(context, options = {}) {
|
|
31
|
+
const manifest = createManifest(context, options.manifest);
|
|
32
|
+
return {
|
|
33
|
+
name: 'dino-ovum-manifest',
|
|
34
|
+
injectHtmlTags() {
|
|
35
|
+
return {
|
|
36
|
+
headTags: [
|
|
37
|
+
{tagName: 'link', attributes: {rel: 'manifest', href: `${context.baseUrl}manifest.json`}},
|
|
38
|
+
{tagName: 'meta', attributes: {name: 'theme-color', content: manifest.theme_color}},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
async postBuild({outDir}) {
|
|
43
|
+
await writeFile(path.join(outDir, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n');
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const DOCS_PLUGIN = 'docusaurus-plugin-content-docs';
|
|
5
|
+
|
|
6
|
+
function categoryMetadata(version, directory, siteDir) {
|
|
7
|
+
const file = [
|
|
8
|
+
version.contentPathLocalized,
|
|
9
|
+
version.contentPath ?? path.join(siteDir, 'documents'),
|
|
10
|
+
]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.map((root) => path.join(root, directory, '_category_.json'))
|
|
13
|
+
.find((candidate) => fs.existsSync(candidate));
|
|
14
|
+
return file ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Collect public docs from Docusaurus; never read a second content repository.
|
|
18
|
+
export function buildNavigation(
|
|
19
|
+
instances,
|
|
20
|
+
siteDir,
|
|
21
|
+
{normalizePath, documentDates, documentLocation},
|
|
22
|
+
) {
|
|
23
|
+
const root = {directories: new Map(), documents: []};
|
|
24
|
+
const paths = [];
|
|
25
|
+
const documentEntries = [];
|
|
26
|
+
for (const data of Object.values(instances)) {
|
|
27
|
+
for (const version of data.loadedVersions || []) {
|
|
28
|
+
for (const doc of version.docs || []) {
|
|
29
|
+
if (doc.draft || doc.unlisted) continue;
|
|
30
|
+
paths.push(normalizePath(doc.permalink));
|
|
31
|
+
const {
|
|
32
|
+
segments,
|
|
33
|
+
directory: documentDirectory,
|
|
34
|
+
isIndex,
|
|
35
|
+
} = documentLocation(doc.source, doc.sourceDirName);
|
|
36
|
+
const {updated} = documentDates(doc.frontMatter);
|
|
37
|
+
documentEntries.push({
|
|
38
|
+
title: doc.title,
|
|
39
|
+
href: doc.permalink,
|
|
40
|
+
directory: documentDirectory,
|
|
41
|
+
isIndex,
|
|
42
|
+
updated: updated ?? '',
|
|
43
|
+
});
|
|
44
|
+
let parent = root;
|
|
45
|
+
let directory = '';
|
|
46
|
+
for (const segment of segments) {
|
|
47
|
+
directory = directory ? `${directory}/${segment}` : segment;
|
|
48
|
+
if (!parent.directories.has(segment)) {
|
|
49
|
+
const metadata = categoryMetadata(version, directory, siteDir);
|
|
50
|
+
parent.directories.set(segment, {
|
|
51
|
+
label: metadata.label || segment,
|
|
52
|
+
position: metadata.position ?? Infinity,
|
|
53
|
+
directories: new Map(),
|
|
54
|
+
documents: [],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
parent = parent.directories.get(segment);
|
|
58
|
+
}
|
|
59
|
+
parent.documents.push({
|
|
60
|
+
type: 'link',
|
|
61
|
+
label: doc.title,
|
|
62
|
+
href: doc.permalink,
|
|
63
|
+
position: isIndex ? -1 : (doc.frontMatter?.sidebar_position ?? Infinity),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const compare = (a, b) =>
|
|
69
|
+
a.position - b.position || a.label.localeCompare(b.label, 'en', {numeric: true});
|
|
70
|
+
function items(node) {
|
|
71
|
+
return [
|
|
72
|
+
...node.documents,
|
|
73
|
+
...Array.from(node.directories.values()).map((child) => ({
|
|
74
|
+
type: 'category',
|
|
75
|
+
label: child.label,
|
|
76
|
+
position: child.position,
|
|
77
|
+
collapsible: true,
|
|
78
|
+
collapsed: true,
|
|
79
|
+
items: items(child),
|
|
80
|
+
})),
|
|
81
|
+
]
|
|
82
|
+
.sort(compare)
|
|
83
|
+
.map(({position, ...item}) => item);
|
|
84
|
+
}
|
|
85
|
+
function categoryLabels(node, parent = '') {
|
|
86
|
+
return Object.fromEntries(
|
|
87
|
+
[...node.directories].flatMap(([name, child]) => {
|
|
88
|
+
const directory = parent ? `${parent}/${name}` : name;
|
|
89
|
+
return [[directory, child.label], ...Object.entries(categoryLabels(child, directory))];
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return {sidebar: items(root), paths, documentEntries, categoryLabels: categoryLabels(root)};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default function libraryNavigation(context, options) {
|
|
97
|
+
if (
|
|
98
|
+
!options ||
|
|
99
|
+
![options.normalizePath, options.documentDates, options.documentLocation].every(
|
|
100
|
+
(value) => typeof value === 'function',
|
|
101
|
+
)
|
|
102
|
+
) {
|
|
103
|
+
throw new TypeError(
|
|
104
|
+
'Navigation requires normalizePath, documentDates and documentLocation options.',
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
name: 'library-navigation',
|
|
109
|
+
allContentLoaded({allContent, actions}) {
|
|
110
|
+
actions.setGlobalData(
|
|
111
|
+
buildNavigation(allContent[DOCS_PLUGIN] || {}, context.siteDir, options),
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 문서 frontmatter 의 날짜를 모아 /updates 페이지로 넘긴다.
|
|
3
|
+
*
|
|
4
|
+
* 경로를 직접 계산하지 않고 docs 플러그인이 이미 확정한 permalink 를 그대로 쓴다.
|
|
5
|
+
* 번호 접두사 제거 규칙(`07-logout` → `logout`)이 인스턴스마다 다르게 걸려서,
|
|
6
|
+
* 손으로 URL 을 만들면 조용히 404 가 되기 때문이다.
|
|
7
|
+
*
|
|
8
|
+
* 날짜는 git log 가 아니라 frontmatter 에서 읽는다 - Vercel 이 shallow clone 이라
|
|
9
|
+
* 빌드 환경에서 커밋 이력을 신뢰할 수 없다.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const DOCS_PLUGIN = 'docusaurus-plugin-content-docs';
|
|
13
|
+
|
|
14
|
+
export default function recentUpdatesPlugin(context, options = {}) {
|
|
15
|
+
const {documentDates, labels = {}} = options;
|
|
16
|
+
if (typeof documentDates !== 'function') {
|
|
17
|
+
throw new TypeError('Recent updates requires a documentDates option.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
name: 'recent-updates',
|
|
22
|
+
|
|
23
|
+
contentLoaded({actions}) {
|
|
24
|
+
if (options.page) {
|
|
25
|
+
actions.addRoute({
|
|
26
|
+
path: `${context.baseUrl}updates`,
|
|
27
|
+
component: '@theme/DinoOvum/UpdatesPage',
|
|
28
|
+
exact: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// 다른 플러그인의 결과까지 다 모인 뒤에 도는 단계여야 permalink 를 읽을 수 있다.
|
|
34
|
+
async allContentLoaded({allContent, actions}) {
|
|
35
|
+
const instances = allContent[DOCS_PLUGIN] || {};
|
|
36
|
+
const entries = [];
|
|
37
|
+
|
|
38
|
+
for (const [instanceId, data] of Object.entries(instances)) {
|
|
39
|
+
for (const version of data.loadedVersions || []) {
|
|
40
|
+
for (const doc of version.docs || []) {
|
|
41
|
+
if (doc.draft || doc.unlisted) continue;
|
|
42
|
+
|
|
43
|
+
const {created, updated} = documentDates(doc.frontMatter);
|
|
44
|
+
if (!created && !updated) continue; // 날짜가 없으면 줄 세울 기준이 없다
|
|
45
|
+
|
|
46
|
+
entries.push({
|
|
47
|
+
title: doc.title,
|
|
48
|
+
url: doc.permalink,
|
|
49
|
+
instance: labels[instanceId] || instanceId,
|
|
50
|
+
created,
|
|
51
|
+
updated,
|
|
52
|
+
// 만든 날과 고친 날이 같으면 아직 한 번도 안 고친 새 문서다
|
|
53
|
+
isNew: Boolean(created) && created === updated,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
entries.sort((a, b) =>
|
|
60
|
+
String(b.updated || b.created).localeCompare(String(a.updated || a.created)),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
actions.setGlobalData({entries});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
// Docusaurus uses category labels as translation keys by default. Scope them
|
|
4
|
+
// to their directory so names such as "database" can appear in several branches.
|
|
5
|
+
export default async function sidebarItemsGenerator(args) {
|
|
6
|
+
const items = await args.defaultSidebarItemsGenerator(args);
|
|
7
|
+
function scopeCategories(entries, parent) {
|
|
8
|
+
return entries.map((item) => {
|
|
9
|
+
if (item.type !== 'category') return item;
|
|
10
|
+
const directory = path.posix.join(parent, item.source ?? item.label);
|
|
11
|
+
return {
|
|
12
|
+
...item,
|
|
13
|
+
key: item.key ?? directory,
|
|
14
|
+
items: scopeCategories(item.items, directory),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return scopeCategories(items, args.item.dirName);
|
|
19
|
+
}
|