@riebeckite/plugin-archive 0.0.0-stage → 0.0.17

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright Rerurate_514
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,70 @@
1
- # Temporary Holding Version
1
+ # @riebeckite/plugin-archive
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [日本語](./README_ja.md)
4
+
5
+ Monthly archive listing pages for Riebeckite. The plugin builds its listings with
6
+ the Core collection engine (`buildContentCollections`), so links, ordering, and
7
+ pagination reuse the same query pipeline as the rest of the site.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @riebeckite/plugin-archive
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { archive } from "@riebeckite/plugin-archive";
19
+
20
+ export default {
21
+ plugins: [archive()],
22
+ };
23
+ ```
24
+
25
+ ## Page types
26
+
27
+ The plugin registers a single Page Type, `archive`, and only while the plugin is
28
+ enabled. Routes are generated by the plugin, not by application code.
29
+
30
+ - `archive`: one listing page per month at `<basePath>/<yyyy>/<mm>`, with
31
+ additional pages at `<basePath>/<yyyy>/<mm>/page/<n>` when pagination applies.
32
+
33
+ Entries are grouped by the first available date among `published`, `date`, and
34
+ `created`, at month granularity. Months are ordered newest first, and every link
35
+ uses the entry's resolved permalink.
36
+
37
+ ## Publication and localization
38
+
39
+ Listings are built from `manifest.discoverableEntries`, so unlisted, draft, and
40
+ scheduled notes never appear. The period title and the previous/next pagination
41
+ labels follow `site.locale`; set `locale` on the plugin to override it. Japanese
42
+ and English labels are provided, and the period is formatted through
43
+ `Intl.DateTimeFormat` for any locale.
44
+
45
+ ## Options
46
+
47
+ | Option | Type | Default | Description |
48
+ | --- | --- | --- | --- |
49
+ | `basePath` | `string` | `"/archive"` | Path prefix for the generated pages. An empty string disables them. |
50
+ | `pageSize` | `number` | `10` | Entries per page. `0` keeps a single page. |
51
+ | `locale` | `string` | `site.locale` | Locale used for the period and pagination labels. |
52
+ | `className` | `string` | `"rb-archive"` | Root CSS class for the rendered fragment. |
53
+
54
+ ## Exports
55
+
56
+ - `archive` / `archivePlugin` — the plugin factory.
57
+ - `resolveArchiveOptions` — resolves options with defaults.
58
+ - `buildArchiveCollections` — builds the monthly collections for entries.
59
+ - `archiveDefinitions` — the Core collection definitions used by the plugin.
60
+ - `renderArchivePage` — renders one archive listing page to HTML.
61
+ - `formatArchivePeriod`, `archivePaginationLabels` — locale helpers.
62
+ - `DEFAULT_ARCHIVE_BASE_PATH`, `DEFAULT_ARCHIVE_PAGE_SIZE`,
63
+ `DEFAULT_ARCHIVE_CLASS_NAME`, `ARCHIVE_COLLECTION_KIND`.
64
+
65
+ ## Notes
66
+
67
+ The plugin ships no stylesheet; the rendered fragment carries `rb-archive`
68
+ classes so a site can style it directly. Set `basePath` to a different prefix if
69
+ `/archive` clashes with existing content, and set it to `""` to turn the
70
+ generated pages off without removing the plugin.
package/README_ja.md ADDED
@@ -0,0 +1,72 @@
1
+ # @riebeckite/plugin-archive
2
+
3
+ [English](./README.md)
4
+
5
+ Riebeckite の月別アーカイブ一覧ページです。Core の collection 機構
6
+ (`buildContentCollections`) で一覧を組み立てるため、リンク・順序・ページ
7
+ ネーションはサイト全体と同じ query パイプラインを再利用します。
8
+
9
+ ## インストール
10
+
11
+ ```bash
12
+ pnpm add @riebeckite/plugin-archive
13
+ ```
14
+
15
+ ## 使い方
16
+
17
+ ```ts
18
+ import { archive } from "@riebeckite/plugin-archive";
19
+
20
+ export default {
21
+ plugins: [archive()],
22
+ };
23
+ ```
24
+
25
+ ## ページタイプ
26
+
27
+ `archive` という 1 つの Page Type を登録し、plugin を有効にしている間だけ
28
+ ルートを生成します。ルートはアプリケーションコードではなく plugin が生成
29
+ します。
30
+
31
+ - `archive`: `<basePath>/<yyyy>/<mm>` に月ごとの一覧ページを、ページネー
32
+ ションがある場合は `<basePath>/<yyyy>/<mm>/page/<n>` に追加ページを生成
33
+ します。
34
+
35
+ エントリは `published`、`date`、`created` のうち最初に利用できる日付を月単
36
+ 位でグループ化します。月は新しい順に並び、各リンクはエントリの解決済み
37
+ パーマリンクを使います。
38
+
39
+ ## publication と l10n
40
+
41
+ 一覧は `manifest.discoverableEntries` から組み立てるため、unlisted・下書き・
42
+ スケジュール公開のノートは現れません。期間タイトルと前後ページのラベルは
43
+ `site.locale` に従います。plugin の `locale` で上書きできます。日本語と英語
44
+ のラベルを用意し、期間は `Intl.DateTimeFormat` で任意のロケール向けに整形し
45
+ ます。
46
+
47
+ ## オプション
48
+
49
+ | オプション | 型 | 既定値 | 説明 |
50
+ | --- | --- | --- | --- |
51
+ | `basePath` | `string` | `"/archive"` | 生成ページのパス接頭辞。空文字列で無効化します。 |
52
+ | `pageSize` | `number` | `10` | 1 ページあたりのエントリ数。`0` で単一ページにします。 |
53
+ | `locale` | `string` | `site.locale` | 期間・ページネーションのラベルに使うロケール。 |
54
+ | `className` | `string` | `"rb-archive"` | 描画フラグメントのルート CSS クラス。 |
55
+
56
+ ## エクスポート
57
+
58
+ - `archive` / `archivePlugin` — plugin ファクトリ。
59
+ - `resolveArchiveOptions` — 既定値を適用してオプションを解決します。
60
+ - `buildArchiveCollections` — エントリから月別 collection を組み立てます。
61
+ - `archiveDefinitions` — plugin が使う Core collection 定義。
62
+ - `renderArchivePage` — アーカイブ一覧ページを HTML に描画します。
63
+ - `formatArchivePeriod`、`archivePaginationLabels` — ロケール補助関数。
64
+ - `DEFAULT_ARCHIVE_BASE_PATH`、`DEFAULT_ARCHIVE_PAGE_SIZE`、
65
+ `DEFAULT_ARCHIVE_CLASS_NAME`、`ARCHIVE_COLLECTION_KIND`。
66
+
67
+ ## 補足
68
+
69
+ スタイルシートは同梱しません。描画フラグメントは `rb-archive` クラスを持つ
70
+ ので、サイト側で直接スタイルできます。`/archive` が既存コンテンツと衝突す
71
+ る場合は `basePath` を変更し、plugin を残したまま生成ページを止めたい場合は
72
+ `""` を設定します。
@@ -0,0 +1,9 @@
1
+ import type { ArchiveOptions } from "./src/types.js";
2
+ export { ARCHIVE_COLLECTION_KIND, archiveDefinitions, buildArchiveCollections, } from "./src/collections.js";
3
+ export { archivePaginationLabels, formatArchivePeriod } from "./src/locale.js";
4
+ export { DEFAULT_ARCHIVE_BASE_PATH, DEFAULT_ARCHIVE_CLASS_NAME, DEFAULT_ARCHIVE_PAGE_SIZE, resolveArchiveOptions, } from "./src/options.js";
5
+ export { renderArchivePage } from "./src/pages.js";
6
+ export type { ArchiveOptions, ArchivePage, ResolvedArchiveOptions, } from "./src/types.js";
7
+ export declare const ARCHIVE_PLUGIN_NAME = "archive";
8
+ export declare function archive(options?: ArchiveOptions): import("@riebeckite/core").RiebeckitePlugin<ArchiveOptions>;
9
+ export declare const archivePlugin: typeof archive;
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ // index.ts
2
+ import {
3
+ definePlugin
4
+ } from "@riebeckite/core";
5
+
6
+ // src/collections.ts
7
+ import {
8
+ buildContentCollections
9
+ } from "@riebeckite/core";
10
+
11
+ // src/locale.ts
12
+ function archivePaginationLabels(locale) {
13
+ return isJapanese(locale) ? { previous: "前のページ", next: "次のページ" } : { previous: "Previous", next: "Next" };
14
+ }
15
+ function formatArchivePeriod(value, locale) {
16
+ const match = /^(\d{4})(?:-(\d{1,2}))?$/.exec(value);
17
+ if (!match) return value;
18
+ const year = Number(match[1]);
19
+ const month = match[2] ? Number(match[2]) : null;
20
+ const tag = isJapanese(locale) ? "ja-JP" : locale && locale.trim() !== "" ? locale : "en-US";
21
+ const options = month === null ? { year: "numeric", timeZone: "UTC" } : { year: "numeric", month: "long", timeZone: "UTC" };
22
+ return new Intl.DateTimeFormat(tag, options).format(
23
+ new Date(Date.UTC(year, (month ?? 1) - 1, 1))
24
+ );
25
+ }
26
+ function isJapanese(locale) {
27
+ return Boolean(locale && /^ja($|[-_])/i.test(locale));
28
+ }
29
+
30
+ // src/collections.ts
31
+ var ARCHIVE_COLLECTION_KIND = "archive";
32
+ function archiveDefinitions(options, locale) {
33
+ return [
34
+ {
35
+ kind: ARCHIVE_COLLECTION_KIND,
36
+ basePath: options.basePath,
37
+ groupBy: {
38
+ by: "date",
39
+ fields: ["published", "date", "created"],
40
+ granularity: "month"
41
+ },
42
+ order: "desc",
43
+ pageSize: options.pageSize,
44
+ resolveTitle: ({ value }) => formatArchivePeriod(value, locale),
45
+ resolvePath: ({ value }) => `${options.basePath}/${value.replace(/-/g, "/")}`
46
+ }
47
+ ];
48
+ }
49
+ function buildArchiveCollections(entries, options, locale) {
50
+ if (options.basePath === "") return [];
51
+ return buildContentCollections(entries, archiveDefinitions(options, locale));
52
+ }
53
+
54
+ // src/options.ts
55
+ var DEFAULT_ARCHIVE_BASE_PATH = "/archive";
56
+ var DEFAULT_ARCHIVE_PAGE_SIZE = 10;
57
+ var DEFAULT_ARCHIVE_CLASS_NAME = "rb-archive";
58
+ function resolveArchiveOptions(options = {}) {
59
+ return {
60
+ basePath: normalizeBasePath(options.basePath ?? DEFAULT_ARCHIVE_BASE_PATH),
61
+ pageSize: normalizePageSize(options.pageSize ?? DEFAULT_ARCHIVE_PAGE_SIZE),
62
+ locale: options.locale?.trim() ? options.locale.trim() : null,
63
+ className: options.className?.trim() || DEFAULT_ARCHIVE_CLASS_NAME
64
+ };
65
+ }
66
+ function normalizeBasePath(value) {
67
+ const trimmed = value.trim().replace(/\/+$/, "");
68
+ if (trimmed.length === 0) return "";
69
+ return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
70
+ }
71
+ function normalizePageSize(value) {
72
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
73
+ }
74
+
75
+ // src/pages.ts
76
+ import {
77
+ escapeHtml,
78
+ escapeHtmlAttribute
79
+ } from "@riebeckite/core";
80
+ function renderArchivePage(collection, options, locale) {
81
+ const className = escapeHtmlAttribute(options.className);
82
+ const posts = collection.entries.map(
83
+ (entry) => `<li class="${className}__item"><a class="${className}__link" href="${escapeHtmlAttribute(
84
+ entry.permalink
85
+ )}">${escapeHtml(entry.title)}</a></li>`
86
+ ).join("");
87
+ const labels = archivePaginationLabels(locale);
88
+ const navigation = [];
89
+ if (collection.page.previousPath) {
90
+ navigation.push(
91
+ `<a class="${className}__link" rel="prev" href="${escapeHtmlAttribute(
92
+ collection.page.previousPath
93
+ )}">${escapeHtml(labels.previous)}</a>`
94
+ );
95
+ }
96
+ if (collection.page.nextPath) {
97
+ navigation.push(
98
+ `<a class="${className}__link" rel="next" href="${escapeHtmlAttribute(
99
+ collection.page.nextPath
100
+ )}">${escapeHtml(labels.next)}</a>`
101
+ );
102
+ }
103
+ const pagination = navigation.length > 0 ? `<nav class="${className}__pagination">${navigation.join(" ")}</nav>` : "";
104
+ const html = `<section class="${className}" data-rr-archive="${escapeHtmlAttribute(
105
+ collection.value
106
+ )}"><h1 class="${className}__title">${escapeHtml(
107
+ collection.title
108
+ )}</h1><ul class="${className}__list">${posts}</ul>${pagination}</section>`;
109
+ return { title: collection.title, html };
110
+ }
111
+
112
+ // index.ts
113
+ var ARCHIVE_PLUGIN_NAME = "archive";
114
+ function archive(options = {}) {
115
+ const resolved = resolveArchiveOptions(options);
116
+ return definePlugin({
117
+ name: ARCHIVE_PLUGIN_NAME,
118
+ options,
119
+ validateOptions: validateArchiveOptions,
120
+ pageTypes: [
121
+ {
122
+ id: "archive",
123
+ paths: ({ manifest, config }) => buildArchiveCollections(
124
+ manifest.discoverableEntries,
125
+ resolved,
126
+ resolveLocale(config, resolved)
127
+ ).map((collection) => collection.path),
128
+ outputDependencies: [{ type: "global" }],
129
+ resolve: ({ manifest, pathname, config }) => {
130
+ if (resolved.basePath === "") return null;
131
+ const locale = resolveLocale(config, resolved);
132
+ const collection = buildArchiveCollections(
133
+ manifest.discoverableEntries,
134
+ resolved,
135
+ locale
136
+ ).find((candidate) => candidate.path === pathname);
137
+ if (!collection) return null;
138
+ const page = renderArchivePage(collection, resolved, locale);
139
+ return {
140
+ type: "archive",
141
+ pathname: collection.path,
142
+ title: page.title,
143
+ body: page.html
144
+ };
145
+ }
146
+ }
147
+ ]
148
+ });
149
+ }
150
+ var archivePlugin = archive;
151
+ function resolveLocale(config, options) {
152
+ return options.locale ?? config?.site.locale ?? "en";
153
+ }
154
+ function validateArchiveOptions(options) {
155
+ if (!options) return [];
156
+ const issues = [];
157
+ if (options.basePath !== void 0 && typeof options.basePath !== "string") {
158
+ issues.push({ path: "basePath", message: "Expected a string." });
159
+ }
160
+ for (const key of ["locale", "className"]) {
161
+ const value = options[key];
162
+ if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
163
+ issues.push({ path: key, message: "Expected a non-empty string." });
164
+ }
165
+ }
166
+ if (options.pageSize !== void 0 && (typeof options.pageSize !== "number" || !Number.isInteger(options.pageSize) || options.pageSize < 0)) {
167
+ issues.push({
168
+ path: "pageSize",
169
+ message: "Expected a non-negative integer."
170
+ });
171
+ }
172
+ return issues;
173
+ }
174
+ export {
175
+ ARCHIVE_COLLECTION_KIND,
176
+ ARCHIVE_PLUGIN_NAME,
177
+ DEFAULT_ARCHIVE_BASE_PATH,
178
+ DEFAULT_ARCHIVE_CLASS_NAME,
179
+ DEFAULT_ARCHIVE_PAGE_SIZE,
180
+ archive,
181
+ archiveDefinitions,
182
+ archivePaginationLabels,
183
+ archivePlugin,
184
+ buildArchiveCollections,
185
+ formatArchivePeriod,
186
+ renderArchivePage,
187
+ resolveArchiveOptions
188
+ };
@@ -0,0 +1,5 @@
1
+ import { type ContentCollection, type ContentCollectionDefinition, type ContentManifestEntry } from "@riebeckite/core";
2
+ import type { ResolvedArchiveOptions } from "./types.js";
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[];
@@ -0,0 +1,5 @@
1
+ export declare function archivePaginationLabels(locale: string | null | undefined): {
2
+ previous: string;
3
+ next: string;
4
+ };
5
+ export declare function formatArchivePeriod(value: string, locale: string | null | undefined): string;
@@ -0,0 +1,5 @@
1
+ import type { ArchiveOptions, ResolvedArchiveOptions } from "./types.js";
2
+ export declare const DEFAULT_ARCHIVE_BASE_PATH = "/archive";
3
+ export declare const DEFAULT_ARCHIVE_PAGE_SIZE = 10;
4
+ export declare const DEFAULT_ARCHIVE_CLASS_NAME = "rb-archive";
5
+ export declare function resolveArchiveOptions(options?: ArchiveOptions): ResolvedArchiveOptions;
@@ -0,0 +1,3 @@
1
+ import { type ContentCollection } from "@riebeckite/core";
2
+ import type { ArchivePage, ResolvedArchiveOptions } from "./types.js";
3
+ export declare function renderArchivePage(collection: ContentCollection, options: ResolvedArchiveOptions, locale: string): ArchivePage;
@@ -0,0 +1,16 @@
1
+ export type ArchiveOptions = {
2
+ basePath?: string;
3
+ pageSize?: number;
4
+ locale?: string;
5
+ className?: string;
6
+ };
7
+ export type ResolvedArchiveOptions = {
8
+ basePath: string;
9
+ pageSize: number;
10
+ locale: string | null;
11
+ className: string;
12
+ };
13
+ export type ArchivePage = {
14
+ title: string;
15
+ html: string;
16
+ };
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-archive",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.17",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "source": "./index.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "@riebeckite/core": "0.0.17"
18
+ },
19
+ "devDependencies": {
20
+ "tsx": "^4.22.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "files": [
26
+ "LICENSE",
27
+ "README.md",
28
+ "README_ja.md",
29
+ "dist"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Rerurate514/riebeckite.git",
34
+ "directory": "packages/plugins/archive"
35
+ },
36
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
39
+ },
40
+ "description": "Monthly archive listing pages built on the Core collection engine.",
41
+ "keywords": [
42
+ "riebeckite",
43
+ "plugin",
44
+ "archive",
45
+ "collections"
46
+ ],
47
+ "engines": {
48
+ "node": "^20.19.0 || >=22.12.0"
49
+ },
50
+ "sideEffects": false,
51
+ "scripts": {
52
+ "build": "node ../../../scripts/build_package.mjs",
53
+ "test": "node --import tsx --test \"test/*.test.ts\""
54
+ }
6
55
  }