@riebeckite/plugin-archive 0.0.31 → 0.0.32
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 +11 -3
- package/README_ja.md +10 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -4
- package/dist/src/locale.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,7 +27,9 @@ export default {
|
|
|
27
27
|
## Page types
|
|
28
28
|
|
|
29
29
|
The plugin registers a single Page Type, `archive`, and only while the plugin is
|
|
30
|
-
enabled. Routes are generated by the plugin, not by application code
|
|
30
|
+
enabled. Routes are generated by the plugin, not by application code: the site's
|
|
31
|
+
catch-all content route serves them, so no dedicated application route is
|
|
32
|
+
needed.
|
|
31
33
|
|
|
32
34
|
- `archive`: one listing page per month at `<basePath>/<yyyy>/<mm>`, with
|
|
33
35
|
additional pages at `<basePath>/<yyyy>/<mm>/page/<n>` when pagination applies.
|
|
@@ -42,7 +44,12 @@ Listings are built from `manifest.discoverableEntries`, so unlisted, draft, and
|
|
|
42
44
|
scheduled notes never appear. The period title and the previous/next pagination
|
|
43
45
|
labels follow `site.locale`; set `locale` on the plugin to override it. Japanese
|
|
44
46
|
and English labels are provided, and the period is formatted through
|
|
45
|
-
`Intl.DateTimeFormat` for any locale.
|
|
47
|
+
`Intl.DateTimeFormat` for any locale. Locale tags written with underscores, such
|
|
48
|
+
as `en_US`, are normalized before formatting.
|
|
49
|
+
|
|
50
|
+
Each resolved page also sets `description` and `language`, so the site's
|
|
51
|
+
document frame can render archive SEO metadata and the `lang` attribute without
|
|
52
|
+
recomputing the period.
|
|
46
53
|
|
|
47
54
|
## Options
|
|
48
55
|
|
|
@@ -60,7 +67,8 @@ and English labels are provided, and the period is formatted through
|
|
|
60
67
|
- `buildArchiveCollections` — builds the monthly collections for entries.
|
|
61
68
|
- `archiveDefinitions` — the Core collection definitions used by the plugin.
|
|
62
69
|
- `renderArchivePage` — renders one archive listing page to HTML.
|
|
63
|
-
- `formatArchivePeriod`, `archivePaginationLabels
|
|
70
|
+
- `formatArchivePeriod`, `archivePaginationLabels`,
|
|
71
|
+
`buildArchiveDescription` — locale helpers.
|
|
64
72
|
- `DEFAULT_ARCHIVE_BASE_PATH`, `DEFAULT_ARCHIVE_PAGE_SIZE`,
|
|
65
73
|
`DEFAULT_ARCHIVE_CLASS_NAME`, `ARCHIVE_COLLECTION_KIND`.
|
|
66
74
|
|
package/README_ja.md
CHANGED
|
@@ -28,7 +28,8 @@ export default {
|
|
|
28
28
|
|
|
29
29
|
`archive` という 1 つの Page Type を登録し、plugin を有効にしている間だけ
|
|
30
30
|
ルートを生成します。ルートはアプリケーションコードではなく plugin が生成
|
|
31
|
-
|
|
31
|
+
し、サイトの catch-all content route が配信します。専用のアプリケーション
|
|
32
|
+
ルートは不要です。
|
|
32
33
|
|
|
33
34
|
- `archive`: `<basePath>/<yyyy>/<mm>` に月ごとの一覧ページを、ページネー
|
|
34
35
|
ションがある場合は `<basePath>/<yyyy>/<mm>/page/<n>` に追加ページを生成
|
|
@@ -44,7 +45,12 @@ export default {
|
|
|
44
45
|
スケジュール公開のノートは現れません。期間タイトルと前後ページのラベルは
|
|
45
46
|
`site.locale` に従います。plugin の `locale` で上書きできます。日本語と英語
|
|
46
47
|
のラベルを用意し、期間は `Intl.DateTimeFormat` で任意のロケール向けに整形し
|
|
47
|
-
|
|
48
|
+
ます。`en_US` のようなアンダースコア区切りのロケールは整形前に正規化しま
|
|
49
|
+
す。
|
|
50
|
+
|
|
51
|
+
解決したページは `description` と `language` も設定するため、サイトの
|
|
52
|
+
document frame は期間を再計算せずにアーカイブの SEO メタデータと `lang` 属性
|
|
53
|
+
を描画できます。
|
|
48
54
|
|
|
49
55
|
## オプション
|
|
50
56
|
|
|
@@ -62,7 +68,8 @@ export default {
|
|
|
62
68
|
- `buildArchiveCollections`:エントリから月別 collection を組み立てます。
|
|
63
69
|
- `archiveDefinitions`:plugin が使う Core collection 定義。
|
|
64
70
|
- `renderArchivePage`:アーカイブ一覧ページを HTML に描画します。
|
|
65
|
-
- `formatArchivePeriod`、`archivePaginationLabels
|
|
71
|
+
- `formatArchivePeriod`、`archivePaginationLabels`、
|
|
72
|
+
`buildArchiveDescription`:ロケール補助関数。
|
|
66
73
|
- `DEFAULT_ARCHIVE_BASE_PATH`、`DEFAULT_ARCHIVE_PAGE_SIZE`、
|
|
67
74
|
`DEFAULT_ARCHIVE_CLASS_NAME`、`ARCHIVE_COLLECTION_KIND`。
|
|
68
75
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArchiveOptions } from "./src/types.js";
|
|
2
2
|
export { ARCHIVE_COLLECTION_KIND, archiveDefinitions, buildArchiveCollections, } from "./src/collections.js";
|
|
3
|
-
export { archivePaginationLabels, formatArchivePeriod } from "./src/locale.js";
|
|
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";
|
|
6
6
|
export type { ArchiveOptions, ArchivePage, ResolvedArchiveOptions, } from "./src/types.js";
|
package/dist/index.js
CHANGED
|
@@ -12,16 +12,26 @@ import {
|
|
|
12
12
|
function archivePaginationLabels(locale) {
|
|
13
13
|
return isJapanese(locale) ? { previous: "前のページ", next: "次のページ" } : { previous: "Previous", next: "Next" };
|
|
14
14
|
}
|
|
15
|
+
function buildArchiveDescription(siteTitle, period, locale) {
|
|
16
|
+
return isJapanese(locale) ? `${siteTitle} の ${period} の記事一覧です。` : `Posts from ${period} on ${siteTitle}.`;
|
|
17
|
+
}
|
|
18
|
+
function normalizeArchiveLocale(locale) {
|
|
19
|
+
const value = locale?.trim();
|
|
20
|
+
return value ? value.replace(/_/g, "-") : "en-US";
|
|
21
|
+
}
|
|
15
22
|
function formatArchivePeriod(value, locale) {
|
|
16
23
|
const match = /^(\d{4})(?:-(\d{1,2}))?$/.exec(value);
|
|
17
24
|
if (!match) return value;
|
|
18
25
|
const year = Number(match[1]);
|
|
19
26
|
const month = match[2] ? Number(match[2]) : null;
|
|
20
|
-
const tag = isJapanese(locale) ? "ja-JP" : locale && locale.trim() !== "" ? locale : "en-US";
|
|
21
27
|
const options = month === null ? { year: "numeric", timeZone: "UTC" } : { year: "numeric", month: "long", timeZone: "UTC" };
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
const date = new Date(Date.UTC(year, (month ?? 1) - 1, 1));
|
|
29
|
+
const tag = isJapanese(locale) ? "ja-JP" : normalizeArchiveLocale(locale);
|
|
30
|
+
try {
|
|
31
|
+
return new Intl.DateTimeFormat(tag, options).format(date);
|
|
32
|
+
} catch {
|
|
33
|
+
return new Intl.DateTimeFormat("en-US", options).format(date);
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
function isJapanese(locale) {
|
|
27
37
|
return Boolean(locale && /^ja($|[-_])/i.test(locale));
|
|
@@ -140,6 +150,8 @@ function archive(options = {}) {
|
|
|
140
150
|
type: "archive",
|
|
141
151
|
pathname: collection.path,
|
|
142
152
|
title: page.title,
|
|
153
|
+
description: config ? buildArchiveDescription(config.site.title, page.title, locale) : void 0,
|
|
154
|
+
language: normalizeArchiveLocale(locale),
|
|
143
155
|
body: page.html
|
|
144
156
|
};
|
|
145
157
|
}
|
|
@@ -182,6 +194,7 @@ export {
|
|
|
182
194
|
archivePaginationLabels,
|
|
183
195
|
archivePlugin,
|
|
184
196
|
buildArchiveCollections,
|
|
197
|
+
buildArchiveDescription,
|
|
185
198
|
formatArchivePeriod,
|
|
186
199
|
renderArchivePage,
|
|
187
200
|
resolveArchiveOptions
|
package/dist/src/locale.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export declare function archivePaginationLabels(locale: string | null | undefine
|
|
|
2
2
|
previous: string;
|
|
3
3
|
next: string;
|
|
4
4
|
};
|
|
5
|
+
export declare function buildArchiveDescription(siteTitle: string, period: string, locale: string | null | undefined): string;
|
|
6
|
+
export declare function normalizeArchiveLocale(locale: string | null | undefined): string;
|
|
5
7
|
export declare function formatArchivePeriod(value: string, locale: string | null | undefined): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-archive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@riebeckite/core": "0.0.
|
|
17
|
+
"@riebeckite/core": "0.0.32"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"tsx": "^4.22.4"
|