@riebeckite/plugin-glossary 0.0.37 → 0.0.39

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 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 }) => resolved.basePath === "" || buildGlossary(manifest.discoverableEntries, resolved).length === 0 ? [] : [resolved.basePath],
70
+ paths: ({ manifest }) => glossaryPages(manifest, resolved).map((page) => page.pathname),
68
71
  outputDependencies: [{ type: "global" }],
69
72
  resolve: ({ manifest, pathname }) => {
70
- if (pathname !== resolved.basePath || resolved.basePath === "")
71
- return null;
72
- const entries = buildGlossary(manifest.discoverableEntries, resolved);
73
- if (entries.length === 0) return null;
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
- if (pathname !== resolved.basePath || resolved.basePath === "")
84
- return null;
85
- const entries = buildGlossary(manifest.discoverableEntries, resolved);
86
- if (entries.length === 0) return null;
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 {
@@ -5,6 +5,7 @@ export type GlossaryOptions = {
5
5
  termKey?: string;
6
6
  definitionKey?: string;
7
7
  title?: string;
8
+ localeMode?: "current" | "fallback" | "all";
8
9
  };
9
10
  export type ResolvedGlossaryOptions = Required<GlossaryOptions>;
10
11
  export type GlossaryEntry = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-glossary",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
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.37"
18
+ "@riebeckite/core": "0.0.39"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsx": "^4.22.4"