@riebeckite/plugin-glossary 0.0.38 → 0.0.40
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/README.md +1 -0
- package/README_ja.md +1 -0
- package/dist/index.js +52 -15
- package/dist/src/types.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,3 +51,4 @@ active theme's color and typography tokens.
|
|
|
51
51
|
| `definitionKey` | `string` | `"definition"` | Optional short definition key. |
|
|
52
52
|
| `title` | `string` | `"Glossary"` | Page heading and title. |
|
|
53
53
|
| `className` | `string` | `"rb-glossary"` | Root CSS class. |
|
|
54
|
+
| `localeMode` | `"current" \| "fallback" \| "all"` | `"current"` | Locale selection for the glossary page. |
|
package/README_ja.md
CHANGED
|
@@ -51,3 +51,4 @@ definition: デプロイ前に HTML を生成する方式です。
|
|
|
51
51
|
| `definitionKey` | `string` | `"definition"` | 任意の短い定義のキー。 |
|
|
52
52
|
| `title` | `string` | `"Glossary"` | ページ見出しと title。 |
|
|
53
53
|
| `className` | `string` | `"rb-glossary"` | ルート CSS クラス。 |
|
|
54
|
+
| `localeMode` | `"current" \| "fallback" \| "all"` | `"current"` | 用語集ページに表示する言語の選択。 |
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import {
|
|
3
3
|
createStyleAsset,
|
|
4
|
-
definePlugin
|
|
4
|
+
definePlugin,
|
|
5
|
+
localizedPagePath,
|
|
6
|
+
selectLocalizedEntries
|
|
5
7
|
} from "@riebeckite/core";
|
|
6
8
|
|
|
7
9
|
// src/glossary.ts
|
|
@@ -19,7 +21,8 @@ function resolveGlossaryOptions(options = {}) {
|
|
|
19
21
|
key: options.key?.trim() || DEFAULT_GLOSSARY_KEY,
|
|
20
22
|
termKey: options.termKey?.trim() || "term",
|
|
21
23
|
definitionKey: options.definitionKey?.trim() || "definition",
|
|
22
|
-
title: options.title?.trim() || "Glossary"
|
|
24
|
+
title: options.title?.trim() || "Glossary",
|
|
25
|
+
localeMode: options.localeMode === "all" || options.localeMode === "fallback" ? options.localeMode : "current"
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
function buildGlossary(entries, options) {
|
|
@@ -64,38 +67,66 @@ function glossary(options = {}) {
|
|
|
64
67
|
pageTypes: [
|
|
65
68
|
{
|
|
66
69
|
id: "glossary",
|
|
67
|
-
paths: ({ manifest }) =>
|
|
70
|
+
paths: ({ manifest }) => glossaryPages(manifest, resolved).map((page) => page.pathname),
|
|
68
71
|
outputDependencies: [{ type: "global" }],
|
|
69
72
|
resolve: ({ manifest, pathname }) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
const page = renderGlossaryPage(entries, resolved);
|
|
73
|
+
const model = glossaryPages(manifest, resolved).find(
|
|
74
|
+
(page2) => page2.pathname === pathname
|
|
75
|
+
);
|
|
76
|
+
if (!model) return null;
|
|
77
|
+
const page = renderGlossaryPage(model.entries, resolved);
|
|
75
78
|
return {
|
|
76
79
|
type: "glossary",
|
|
77
80
|
pathname,
|
|
78
81
|
title: page.title,
|
|
79
|
-
body: page.html
|
|
82
|
+
body: page.html,
|
|
83
|
+
...model.locale ? { language: model.locale } : {}
|
|
80
84
|
};
|
|
81
85
|
},
|
|
82
86
|
resolveRoute: ({ manifest, pathname }) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
const page = renderGlossaryPage(entries, resolved);
|
|
87
|
+
const model = glossaryPages(manifest, resolved).find(
|
|
88
|
+
(page2) => page2.pathname === pathname
|
|
89
|
+
);
|
|
90
|
+
if (!model) return null;
|
|
91
|
+
const page = renderGlossaryPage(model.entries, resolved);
|
|
88
92
|
return {
|
|
89
93
|
type: "glossary",
|
|
90
94
|
pathname,
|
|
91
95
|
title: page.title,
|
|
92
|
-
body: page.html
|
|
96
|
+
body: page.html,
|
|
97
|
+
...model.locale ? { language: model.locale } : {}
|
|
93
98
|
};
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
]
|
|
97
102
|
});
|
|
98
103
|
}
|
|
104
|
+
function glossaryPages(manifest, options) {
|
|
105
|
+
if (options.basePath === "") return [];
|
|
106
|
+
const localization = manifest.localization;
|
|
107
|
+
if (!localization) {
|
|
108
|
+
const entries = buildGlossary(manifest.discoverableEntries, options);
|
|
109
|
+
return entries.length === 0 ? [] : [{ pathname: options.basePath, entries }];
|
|
110
|
+
}
|
|
111
|
+
const locales = options.localeMode === "all" ? [localization.defaultLocale] : localization.locales;
|
|
112
|
+
return locales.flatMap((locale) => {
|
|
113
|
+
const entries = buildGlossary(
|
|
114
|
+
selectLocalizedEntries(manifest.discoverableEntries, {
|
|
115
|
+
mode: options.localeMode,
|
|
116
|
+
locale,
|
|
117
|
+
...localization.fallbackLocale ? { fallbackLocale: localization.fallbackLocale } : {}
|
|
118
|
+
}),
|
|
119
|
+
options
|
|
120
|
+
);
|
|
121
|
+
return entries.length === 0 ? [] : [
|
|
122
|
+
{
|
|
123
|
+
pathname: localizedPagePath(localization, options.basePath, locale),
|
|
124
|
+
locale,
|
|
125
|
+
entries
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
});
|
|
129
|
+
}
|
|
99
130
|
function validateGlossaryOptions(options) {
|
|
100
131
|
if (!options) return [];
|
|
101
132
|
const issues = [];
|
|
@@ -112,6 +143,12 @@ function validateGlossaryOptions(options) {
|
|
|
112
143
|
issues.push({ path: key, message: "Expected a non-empty string." });
|
|
113
144
|
}
|
|
114
145
|
}
|
|
146
|
+
if (options.localeMode !== void 0 && options.localeMode !== "current" && options.localeMode !== "fallback" && options.localeMode !== "all") {
|
|
147
|
+
issues.push({
|
|
148
|
+
path: "localeMode",
|
|
149
|
+
message: 'Expected "current", "fallback", or "all".'
|
|
150
|
+
});
|
|
151
|
+
}
|
|
115
152
|
return issues;
|
|
116
153
|
}
|
|
117
154
|
export {
|
package/dist/src/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-glossary",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"./style.css": "./style.css"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@riebeckite/core": "0.0.
|
|
18
|
+
"@riebeckite/core": "0.0.40"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"tsx": "^4.22.4"
|