@riebeckite/plugin-archive 0.0.38 → 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
@@ -63,6 +63,7 @@ recomputing the period.
63
63
  | `pageSize` | `number` | `10` | Entries per page. `0` keeps a single page. |
64
64
  | `locale` | `string` | `site.locale` | Locale used for the period and pagination labels. |
65
65
  | `className` | `string` | `"rb-archive"` | Root CSS class for the rendered fragment. |
66
+ | `localeMode` | `"current" \| "fallback" \| "all"` | `"current"` | Locale selection for archive entries and generated pages. |
66
67
 
67
68
  ## Exports
68
69
 
package/README_ja.md CHANGED
@@ -64,6 +64,7 @@ export default {
64
64
  | `pageSize` | `number` | `10` | 1 ページあたりのエントリ数。`0` で単一ページにします。 |
65
65
  | `locale` | `string` | `site.locale` | 期間・ページネーションのラベルに使うロケール。 |
66
66
  | `className` | `string` | `"rb-archive"` | 描画フラグメントのルート CSS クラス。 |
67
+ | `localeMode` | `"current" \| "fallback" \| "all"` | `"current"` | アーカイブの記事と言語別ページの選択。 |
67
68
 
68
69
  ## エクスポート
69
70
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ArchiveOptions } from "./src/types.js";
2
- export { ARCHIVE_COLLECTION_KIND, archiveDefinitions, buildArchiveCollections, } from "./src/collections.js";
2
+ export { ARCHIVE_COLLECTION_KIND, archiveDefinitions, buildArchiveCollections, buildArchivePages, } from "./src/collections.js";
3
3
  export { archivePaginationLabels, buildArchiveDescription, formatArchivePeriod, } from "./src/locale.js";
4
4
  export { DEFAULT_ARCHIVE_BASE_PATH, DEFAULT_ARCHIVE_CLASS_NAME, DEFAULT_ARCHIVE_PAGE_SIZE, resolveArchiveOptions, } from "./src/options.js";
5
5
  export { renderArchivePage } from "./src/pages.js";
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
1
  // index.ts
2
2
  import {
3
3
  createStyleAsset,
4
- definePlugin
4
+ definePlugin,
5
+ localizedPagePath as localizedPagePath2
5
6
  } from "@riebeckite/core";
6
7
 
7
8
  // src/collections.ts
8
9
  import {
9
- buildContentCollections
10
+ buildContentCollections,
11
+ localizedPagePath,
12
+ selectLocalizedEntries
10
13
  } from "@riebeckite/core";
11
14
 
12
15
  // src/locale.ts
@@ -40,11 +43,16 @@ function isJapanese(locale) {
40
43
 
41
44
  // src/collections.ts
42
45
  var ARCHIVE_COLLECTION_KIND = "archive";
43
- function archiveDefinitions(options, locale) {
46
+ function archiveDefinitions(options, locale, fallbackLocale) {
44
47
  return [
45
48
  {
46
49
  kind: ARCHIVE_COLLECTION_KIND,
47
50
  basePath: options.basePath,
51
+ locale: {
52
+ mode: options.localeMode,
53
+ locale,
54
+ ...fallbackLocale ? { fallbackLocale } : {}
55
+ },
48
56
  groupBy: {
49
57
  by: "date",
50
58
  fields: ["published", "date", "created"],
@@ -57,9 +65,43 @@ function archiveDefinitions(options, locale) {
57
65
  }
58
66
  ];
59
67
  }
60
- function buildArchiveCollections(entries, options, locale) {
68
+ function buildArchiveCollections(entries, options, locale, fallbackLocale) {
69
+ if (options.basePath === "") return [];
70
+ return buildContentCollections(
71
+ entries,
72
+ archiveDefinitions(options, locale, fallbackLocale)
73
+ );
74
+ }
75
+ function buildArchivePages(manifest, options, siteLocale) {
61
76
  if (options.basePath === "") return [];
62
- return buildContentCollections(entries, archiveDefinitions(options, locale));
77
+ const localization = manifest.localization;
78
+ if (!localization) {
79
+ return [
80
+ {
81
+ locale: siteLocale,
82
+ collections: buildArchiveCollections(
83
+ manifest.discoverableEntries,
84
+ options,
85
+ siteLocale
86
+ )
87
+ }
88
+ ];
89
+ }
90
+ const locales = options.localeMode === "all" ? [localization.defaultLocale] : localization.locales;
91
+ return locales.flatMap((locale) => {
92
+ const entries = selectLocalizedEntries(manifest.discoverableEntries, {
93
+ mode: options.localeMode,
94
+ locale,
95
+ ...localization.fallbackLocale ? { fallbackLocale: localization.fallbackLocale } : {}
96
+ });
97
+ const collections = buildArchiveCollections(
98
+ entries,
99
+ options,
100
+ locale,
101
+ localization.fallbackLocale
102
+ );
103
+ return collections.length === 0 ? [] : [{ locale, collections }];
104
+ });
63
105
  }
64
106
 
65
107
  // src/options.ts
@@ -71,7 +113,8 @@ function resolveArchiveOptions(options = {}) {
71
113
  basePath: normalizeBasePath(options.basePath ?? DEFAULT_ARCHIVE_BASE_PATH),
72
114
  pageSize: normalizePageSize(options.pageSize ?? DEFAULT_ARCHIVE_PAGE_SIZE),
73
115
  locale: options.locale?.trim() ? options.locale.trim() : null,
74
- className: options.className?.trim() || DEFAULT_ARCHIVE_CLASS_NAME
116
+ className: options.className?.trim() || DEFAULT_ARCHIVE_CLASS_NAME,
117
+ localeMode: options.localeMode === "all" || options.localeMode === "fallback" ? options.localeMode : "current"
75
118
  };
76
119
  }
77
120
  function normalizeBasePath(value) {
@@ -134,47 +177,55 @@ function archive(options = {}) {
134
177
  pageTypes: [
135
178
  {
136
179
  id: "archive",
137
- paths: ({ manifest, config }) => buildArchiveCollections(
138
- manifest.discoverableEntries,
139
- resolved,
140
- resolveLocale(config, resolved)
141
- ).map((collection) => collection.path),
180
+ paths: ({ manifest, config }) => [
181
+ ...archivePageModels(manifest, config, resolved).keys()
182
+ ],
142
183
  outputDependencies: [{ type: "global" }],
143
184
  resolve: ({ manifest, pathname, config }) => {
144
185
  if (resolved.basePath === "") return null;
145
- const locale = resolveLocale(config, resolved);
146
- const collection = buildArchiveCollections(
147
- manifest.discoverableEntries,
186
+ const model = archivePageModels(manifest, config, resolved).get(
187
+ pathname
188
+ );
189
+ if (!model) return null;
190
+ const page = renderArchivePage(
191
+ model.collection,
148
192
  resolved,
149
- locale
150
- ).find((candidate) => candidate.path === pathname);
151
- if (!collection) return null;
152
- const page = renderArchivePage(collection, resolved, locale);
193
+ model.locale
194
+ );
153
195
  return {
154
196
  type: "archive",
155
- pathname: collection.path,
197
+ pathname,
156
198
  title: page.title,
157
- description: config ? buildArchiveDescription(config.site.title, page.title, locale) : void 0,
158
- language: normalizeArchiveLocale(locale),
199
+ description: config ? buildArchiveDescription(
200
+ config.site.title,
201
+ page.title,
202
+ model.locale
203
+ ) : void 0,
204
+ language: normalizeArchiveLocale(model.locale),
159
205
  body: page.html
160
206
  };
161
207
  },
162
208
  resolveRoute: ({ manifest, pathname, config }) => {
163
209
  if (resolved.basePath === "") return null;
164
- const locale = resolveLocale(config, resolved);
165
- const collection = buildArchiveCollections(
166
- manifest.discoverableEntries,
210
+ const model = archivePageModels(manifest, config, resolved).get(
211
+ pathname
212
+ );
213
+ if (!model) return null;
214
+ const page = renderArchivePage(
215
+ model.collection,
167
216
  resolved,
168
- locale
169
- ).find((candidate) => candidate.path === pathname);
170
- if (!collection) return null;
171
- const page = renderArchivePage(collection, resolved, locale);
217
+ model.locale
218
+ );
172
219
  return {
173
220
  type: "archive",
174
- pathname: collection.path,
221
+ pathname,
175
222
  title: page.title,
176
- description: config ? buildArchiveDescription(config.site.title, page.title, locale) : void 0,
177
- language: normalizeArchiveLocale(locale),
223
+ description: config ? buildArchiveDescription(
224
+ config.site.title,
225
+ page.title,
226
+ model.locale
227
+ ) : void 0,
228
+ language: normalizeArchiveLocale(model.locale),
178
229
  body: page.html
179
230
  };
180
231
  }
@@ -185,6 +236,22 @@ function archive(options = {}) {
185
236
  function resolveLocale(config, options) {
186
237
  return options.locale ?? config?.site.locale ?? "en";
187
238
  }
239
+ function archivePageModels(manifest, config, options) {
240
+ const models = /* @__PURE__ */ new Map();
241
+ for (const { locale, collections } of buildArchivePages(
242
+ manifest,
243
+ options,
244
+ resolveLocale(config, options)
245
+ )) {
246
+ for (const collection of collections) {
247
+ models.set(
248
+ localizedPagePath2(manifest.localization, collection.path, locale),
249
+ { collection, locale }
250
+ );
251
+ }
252
+ }
253
+ return models;
254
+ }
188
255
  function validateArchiveOptions(options) {
189
256
  if (!options) return [];
190
257
  const issues = [];
@@ -203,6 +270,12 @@ function validateArchiveOptions(options) {
203
270
  message: "Expected a non-negative integer."
204
271
  });
205
272
  }
273
+ if (options.localeMode !== void 0 && options.localeMode !== "current" && options.localeMode !== "fallback" && options.localeMode !== "all") {
274
+ issues.push({
275
+ path: "localeMode",
276
+ message: 'Expected "current", "fallback", or "all".'
277
+ });
278
+ }
206
279
  return issues;
207
280
  }
208
281
  export {
@@ -216,6 +289,7 @@ export {
216
289
  archivePaginationLabels,
217
290
  buildArchiveCollections,
218
291
  buildArchiveDescription,
292
+ buildArchivePages,
219
293
  formatArchivePeriod,
220
294
  renderArchivePage,
221
295
  resolveArchiveOptions
@@ -1,5 +1,11 @@
1
- import { type ContentCollection, type ContentCollectionDefinition, type ContentManifestEntry } from "@riebeckite/core";
1
+ import { type ContentCollection, type ContentCollectionDefinition, type ContentManifest, type ContentManifestEntry } from "@riebeckite/core";
2
2
  import type { ResolvedArchiveOptions } from "./types.js";
3
3
  export declare const ARCHIVE_COLLECTION_KIND = "archive";
4
- export declare function archiveDefinitions(options: ResolvedArchiveOptions, locale: string): readonly ContentCollectionDefinition[];
5
- export declare function buildArchiveCollections(entries: readonly ContentManifestEntry[], options: ResolvedArchiveOptions, locale: string): ContentCollection[];
4
+ export declare function archiveDefinitions(options: ResolvedArchiveOptions, locale: string, fallbackLocale?: string): readonly ContentCollectionDefinition[];
5
+ export declare function buildArchiveCollections(entries: readonly ContentManifestEntry[], options: ResolvedArchiveOptions, locale: string, fallbackLocale?: string): ContentCollection[];
6
+ export type ArchivePages = {
7
+ readonly locale: string;
8
+ readonly collections: readonly ContentCollection[];
9
+ };
10
+ export declare function buildArchivePages(manifest: ContentManifest, options: ResolvedArchiveOptions, siteLocale: string): readonly ArchivePages[];
11
+ export declare function localizedArchivePath(manifest: ContentManifest, path: string, locale: string): string;
@@ -3,12 +3,14 @@ export type ArchiveOptions = {
3
3
  pageSize?: number;
4
4
  locale?: string;
5
5
  className?: string;
6
+ localeMode?: "current" | "fallback" | "all";
6
7
  };
7
8
  export type ResolvedArchiveOptions = {
8
9
  basePath: string;
9
10
  pageSize: number;
10
11
  locale: string | null;
11
12
  className: string;
13
+ localeMode: "current" | "fallback" | "all";
12
14
  };
13
15
  export type ArchivePage = {
14
16
  title: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-archive",
3
- "version": "0.0.38",
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.38"
18
+ "@riebeckite/core": "0.0.39"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsx": "^4.22.4"