@riebeckite/plugin-changelog 0.0.6

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 ADDED
@@ -0,0 +1,153 @@
1
+ # @riebeckite/plugin-changelog
2
+
3
+ Build-time change history derived from local Git history. For every published
4
+ note the plugin adds a "change history" section with commit dates, subjects,
5
+ and authors, and it can build a site-wide changelog dataset from the notes'
6
+ commits. No client-side JavaScript is required.
7
+
8
+ [日本語](./README_ja.md)
9
+
10
+ ## Overview
11
+
12
+ `changelog()` reads the local Git repository at build time using the same
13
+ `git` access as [`@riebeckite/plugin-diff`](../diff/README.md) (`execFile` with
14
+ graceful failure). It never invents its own filesystem layer.
15
+
16
+ Results are published through the manifest `bodySlots` mechanism. Each public
17
+ entry receives its own history in the `article.after-content` slot. The site's
18
+ layout decides whether and where to render that slot, so the plugin stays
19
+ inside the Plugin boundary and does not create application routes. When
20
+ `siteWide` is enabled, the site-wide changelog is written to the slot of the
21
+ note named by `siteWideSlug`; that note (the route) is owned by the app or the
22
+ author, not by this plugin. No client script is registered.
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { defineConfig } from "@riebeckite/core";
28
+ import { changelog } from "@riebeckite/plugin-changelog";
29
+
30
+ export default defineConfig({
31
+ // ...
32
+ plugins: [
33
+ changelog({
34
+ // Point at the content root so Git sees the notes' repository paths.
35
+ cwd: "./content",
36
+ lookbackDays: 180,
37
+ dateFormat: "iso",
38
+ }),
39
+ ],
40
+ });
41
+ ```
42
+
43
+ ## Options
44
+
45
+ | Option | Type | Default | Description |
46
+ | ------ | ---- | ------- | ----------- |
47
+ | `cwd` | `string` | `process.cwd()` | Working directory for Git commands |
48
+ | `lookbackDays` | `number` | — (full history) | Only include commits newer than this many days |
49
+ | `dateFormat` | `"iso" \| "long" \| "short"` | `"iso"` | How dates are rendered |
50
+ | `locale` | `string` | `"en"` | Locale for `"long"` / `"short"` dates |
51
+ | `perNote` | `boolean` | `true` | Add a history section to every public note |
52
+ | `siteWide` | `boolean` | `false` | Build and inject the site-wide changelog |
53
+ | `siteWideSlug` | `string` | `"changelog"` | Note that receives the site-wide changelog |
54
+ | `maxPerNote` | `number` | `10` | Maximum commits listed per note |
55
+ | `maxSiteWide` | `number` | `50` | Maximum commits listed site-wide |
56
+ | `showAuthor` | `boolean` | `true` | Show the commit author |
57
+ | `heading` | `boolean` | `true` | Render the `<h2>` heading |
58
+ | `perNoteHeading` | `string` | `"Change history"` | Per-note heading text |
59
+ | `siteWideHeading` | `string` | `"Changelog"` | Site-wide heading text |
60
+ | `className` | `string` | `"rr-changelog"` | Root CSS class |
61
+
62
+ ## Output
63
+
64
+ The plugin appends a fragment like this to the `article.after-content` slot:
65
+
66
+ ```html
67
+ <section class="rr-changelog rr-changelog--note" data-changelog-note>
68
+ <h2 class="rr-changelog__heading">Change history</h2>
69
+ <ol class="rr-changelog__list">
70
+ <li class="rr-changelog__item">
71
+ <time class="rr-changelog__date" datetime="2026-09-30T09:00:00+09:00">2026-09-30</time>
72
+ <span class="rr-changelog__subject">Fix the sidebar offset</span>
73
+ <span class="rr-changelog__author">Author Name</span>
74
+ <code class="rr-changelog__hash" title="…full hash…">abc1234</code>
75
+ </li>
76
+ </ol>
77
+ </section>
78
+ ```
79
+
80
+ `data-changelog-note` and `data-changelog-site` mark the two fragments for
81
+ styling and idempotency checks.
82
+
83
+ ## App wiring (site-wide changelog)
84
+
85
+ The site-wide list is data, not a page. The app owns the route; the plugin
86
+ either fills the `article.after-content` slot of an existing note
87
+ (`siteWide: true` + `siteWideSlug`, which requires a public note at that slug)
88
+ or exposes the dataset for the app to render itself:
89
+
90
+ ```ts
91
+ import {
92
+ buildSiteChangelog,
93
+ GitChangelogReader,
94
+ renderSiteChangelog,
95
+ resolveChangelogOptions,
96
+ } from "@riebeckite/plugin-changelog";
97
+
98
+ const options = resolveChangelogOptions({ lookbackDays: 90 });
99
+ const manifest = await content.getManifest();
100
+ const reader = new GitChangelogReader({ cwd: "./content" });
101
+ const commits = await reader.getRecentCommits();
102
+ const dataset = buildSiteChangelog({
103
+ entries: manifest.publicEntries,
104
+ commits,
105
+ contentIndex: manifest.contentIndex,
106
+ options,
107
+ });
108
+ const html = renderSiteChangelog(dataset, options);
109
+ ```
110
+
111
+ The reference app renders manifest `bodySlots` in
112
+ `apps/web/app/components/article/article.tsx`; a dedicated route can render the
113
+ exported HTML directly.
114
+
115
+ ## Failure behavior
116
+
117
+ When `git` is missing or `cwd` is not a Git repository, the plugin reports a
118
+ `changelog-git-unavailable` warning diagnostic and a logger warning, then leaves
119
+ the build output untouched. The build never fails because history is
120
+ unavailable, and the same guarantee holds for an empty repository.
121
+
122
+ ## Style
123
+
124
+ The package ships `style.css` with the stable `.rr-changelog` root hook. Themes
125
+ can restyle it without editing the plugin:
126
+
127
+ ```ts
128
+ import "@riebeckite/plugin-changelog/style.css";
129
+ ```
130
+
131
+ ## Exports
132
+
133
+ - `changelog(options?)` — plugin factory
134
+ - `changelogPlugin` — alias of `changelog`
135
+ - `resolveChangelogOptions(options?)` — apply option defaults
136
+ - `GitChangelogReader` — Git-backed history reader (`getFileHistory`,
137
+ `getRecentCommits`, `isAvailable`)
138
+ - `buildNoteChangeHistory(entry, commits, options)` — per-note dataset
139
+ - `buildSiteChangelog({ entries, commits, contentIndex, options })` — site-wide
140
+ dataset
141
+ - `renderNoteChangeHistory(history, options)` /
142
+ `renderSiteChangelog(changelog, options)` — HTML renderers
143
+ - `filterChangelogCommits(commits, options)` /
144
+ `formatChangelogDate(date, options)` / `resolveLookbackSince(days, now?)` —
145
+ pure helpers
146
+ - Types: `ChangelogOptions`, `ResolvedChangelogOptions`, `ChangelogCommit`,
147
+ `ChangelogRecord`, `NoteChangeHistory`, `SiteChangelog`, `SiteChangelogEntry`,
148
+ `SiteChangelogNote`, `ChangelogDateFormat`, `GitChangelogReaderOptions`
149
+
150
+ ## See also
151
+
152
+ - [plugin-diff](../diff/README.md) — revision history and line diffs
153
+ - [Plugin guide](../../../docs/en/plugin-system.md)
package/README_ja.md ADDED
@@ -0,0 +1,125 @@
1
+ # @riebeckite/plugin-changelog
2
+
3
+ ローカル Git の履歴からビルド時に変更履歴を生成するプラグインです。公開ノートごとにコミット日・件名・作成者を並べた「変更履歴」セクションを追加し、サイト全体の変更履歴データセットも組み立てられます。クライアント JavaScript は不要です。
4
+
5
+ [English](./README.md)
6
+
7
+ ## できること
8
+
9
+ `changelog()` は [`@riebeckite/plugin-diff`](../diff/README_ja.md) と同じ方法でローカル Git を読み取ります(`execFile` で `git` を実行し、失敗時は安全に縮退)。独自のファイルシステム層は作りません。
10
+
11
+ 結果はマニフェストの `bodySlots` に出力します。公開エントリは `article.after-content` スロットに自分の履歴を受け取り、サイト側のレイアウトがそのスロットを描画するかどうかを決めます。プラグインは Plugin の境界を越えず、アプリケーションのルートも作りません。`siteWide` を有効にすると、`siteWideSlug` で指定したノートのスロットにサイト全体の変更履歴を書き込みます。そのノート(=ルート)はアプリまたは作者が所有するもので、プラグインが作るものではありません。クライアントスクリプトは登録しません。
12
+
13
+ ## 使い方
14
+
15
+ ```ts
16
+ import { defineConfig } from "@riebeckite/core";
17
+ import { changelog } from "@riebeckite/plugin-changelog";
18
+
19
+ export default defineConfig({
20
+ // ...
21
+ plugins: [
22
+ changelog({
23
+ // ノートのリポジトリ上のパスが見えるよう、コンテンツのルートを指定します。
24
+ cwd: "./content",
25
+ lookbackDays: 180,
26
+ dateFormat: "iso",
27
+ }),
28
+ ],
29
+ });
30
+ ```
31
+
32
+ ## オプション
33
+
34
+ | オプション | 型 | 初期値 | 説明 |
35
+ | --- | --- | --- | --- |
36
+ | `cwd` | `string` | `process.cwd()` | Git コマンドを実行するディレクトリ |
37
+ | `lookbackDays` | `number` | なし(全履歴) | 直近この日数以内のコミットだけを含める |
38
+ | `dateFormat` | `"iso" \| "long" \| "short"` | `"iso"` | 日付の表示形式 |
39
+ | `locale` | `string` | `"en"` | `"long"` / `"short"` のロケール |
40
+ | `perNote` | `boolean` | `true` | 公開ノートごとに履歴セクションを追加する |
41
+ | `siteWide` | `boolean` | `false` | サイト全体の変更履歴を生成して注入する |
42
+ | `siteWideSlug` | `string` | `"changelog"` | サイト全体の変更履歴を受け取るノート |
43
+ | `maxPerNote` | `number` | `10` | ノートごとに表示するコミット上限 |
44
+ | `maxSiteWide` | `number` | `50` | サイト全体で表示するコミット上限 |
45
+ | `showAuthor` | `boolean` | `true` | コミット作成者を表示する |
46
+ | `heading` | `boolean` | `true` | `<h2>` 見出しを描画する |
47
+ | `perNoteHeading` | `string` | `"Change history"` | ノートごとの見出し文言 |
48
+ | `siteWideHeading` | `string` | `"Changelog"` | サイト全体の見出し文言 |
49
+ | `className` | `string` | `"rr-changelog"` | ルート CSS クラス |
50
+
51
+ ## 出力
52
+
53
+ `article.after-content` スロットに次のような断片を追加します。
54
+
55
+ ```html
56
+ <section class="rr-changelog rr-changelog--note" data-changelog-note>
57
+ <h2 class="rr-changelog__heading">Change history</h2>
58
+ <ol class="rr-changelog__list">
59
+ <li class="rr-changelog__item">
60
+ <time class="rr-changelog__date" datetime="2026-09-30T09:00:00+09:00">2026-09-30</time>
61
+ <span class="rr-changelog__subject">Fix the sidebar offset</span>
62
+ <span class="rr-changelog__author">Author Name</span>
63
+ <code class="rr-changelog__hash" title="…完全なハッシュ…">abc1234</code>
64
+ </li>
65
+ </ol>
66
+ </section>
67
+ ```
68
+
69
+ `data-changelog-note` と `data-changelog-site` は、2 種類の断片をスタイリングと重複防止のために識別する属性です。
70
+
71
+ ## アプリ側の接続(サイト全体の変更履歴)
72
+
73
+ サイト全体の一覧はページではなくデータです。ルートはアプリが所有します。プラグインは既存ノートの `article.after-content` スロットに書き込む(`siteWide: true` と `siteWideSlug`。その slug の公開ノートが必要)か、データセットを公開してアプリ自身に描画させます。
74
+
75
+ ```ts
76
+ import {
77
+ buildSiteChangelog,
78
+ GitChangelogReader,
79
+ renderSiteChangelog,
80
+ resolveChangelogOptions,
81
+ } from "@riebeckite/plugin-changelog";
82
+
83
+ const options = resolveChangelogOptions({ lookbackDays: 90 });
84
+ const manifest = await content.getManifest();
85
+ const reader = new GitChangelogReader({ cwd: "./content" });
86
+ const commits = await reader.getRecentCommits();
87
+ const dataset = buildSiteChangelog({
88
+ entries: manifest.publicEntries,
89
+ commits,
90
+ contentIndex: manifest.contentIndex,
91
+ options,
92
+ });
93
+ const html = renderSiteChangelog(dataset, options);
94
+ ```
95
+
96
+ 参照アプリはマニフェストの `bodySlots` を `apps/web/app/components/article/article.tsx` で描画します。専用ルートでは公開された HTML をそのまま描画できます。
97
+
98
+ ## 失敗時の挙動
99
+
100
+ `git` が無い、または `cwd` が Git リポジトリでない場合、プラグインは `changelog-git-unavailable` 警告診断とロガー警告を出し、ビルド成果物には何も加えません。履歴が取得できないことを理由にビルドが失敗することはなく、空のリポジトリでも同じです。
101
+
102
+ ## スタイル
103
+
104
+ パッケージは安定した `.rr-changelog` ルートフックを持つ `style.css` を同梱します。テーマはプラグインを編集せずに見た目を変更できます。
105
+
106
+ ```ts
107
+ import "@riebeckite/plugin-changelog/style.css";
108
+ ```
109
+
110
+ ## 公開 API
111
+
112
+ - `changelog(options?)` — プラグインファクトリ
113
+ - `changelogPlugin` — `changelog` の別名
114
+ - `resolveChangelogOptions(options?)` — 既定値を適用
115
+ - `GitChangelogReader` — Git 履歴リーダー(`getFileHistory`、`getRecentCommits`、`isAvailable`)
116
+ - `buildNoteChangeHistory(entry, commits, options)` — ノート単位のデータセット
117
+ - `buildSiteChangelog({ entries, commits, contentIndex, options })` — サイト全体のデータセット
118
+ - `renderNoteChangeHistory(history, options)` / `renderSiteChangelog(changelog, options)` — HTML レンダラ
119
+ - `filterChangelogCommits(commits, options)` / `formatChangelogDate(date, options)` / `resolveLookbackSince(days, now?)` — 純粋な補助関数
120
+ - 型: `ChangelogOptions`、`ResolvedChangelogOptions`、`ChangelogCommit`、`ChangelogRecord`、`NoteChangeHistory`、`SiteChangelog`、`SiteChangelogEntry`、`SiteChangelogNote`、`ChangelogDateFormat`、`GitChangelogReaderOptions`
121
+
122
+ ## 関連資料
123
+
124
+ - [plugin-diff](../diff/README_ja.md) — リビジョン履歴と行差分
125
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
@@ -0,0 +1,29 @@
1
+ import type { ChangelogOptions } from "./src/types.js";
2
+ export { buildNoteChangeHistory, buildSiteChangelog, filterChangelogCommits, formatChangelogDate, resolveLookbackSince, } from "./src/changelog.js";
3
+ export { GitChangelogReader, type GitLogWindow, } from "./src/git/history_reader.js";
4
+ export { DEFAULT_CHANGELOG_CLASS_NAME, DEFAULT_CHANGELOG_HEADING, DEFAULT_CHANGELOG_LOCALE, DEFAULT_CHANGELOG_MAX_PER_NOTE, DEFAULT_CHANGELOG_MAX_SITE_WIDE, DEFAULT_CHANGELOG_PER_NOTE_HEADING, DEFAULT_CHANGELOG_SITE_WIDE_HEADING, DEFAULT_CHANGELOG_SITE_WIDE_SLUG, resolveChangelogOptions, } from "./src/options.js";
5
+ export { CHANGELOG_NOTE_ATTRIBUTE, CHANGELOG_SITE_ATTRIBUTE, renderNoteChangeHistory, renderSiteChangelog, } from "./src/render.js";
6
+ export type { ChangelogCommit, ChangelogDateFormat, ChangelogOptions, ChangelogRecord, GitChangelogReaderOptions, NoteChangeHistory, ResolvedChangelogOptions, SiteChangelog, SiteChangelogEntry, SiteChangelogNote, } from "./src/types.js";
7
+ export declare const CHANGELOG_PLUGIN_NAME = "changelog";
8
+ /** Site layout slot the generated history is written to. */
9
+ export declare const CHANGELOG_BODY_SLOT = "article.after-content";
10
+ /**
11
+ * Git-backed change history for Riebeckite sites.
12
+ *
13
+ * At build time the plugin reads local Git history and publishes HTML
14
+ * fragments through the manifest `bodySlots` mechanism:
15
+ *
16
+ * - every public note gets its own "change history" section;
17
+ * - optionally, a designated note gets the site-wide changelog.
18
+ *
19
+ * The plugin never creates a route. The Site owns the note and the layout; the
20
+ * plugin only fills the `article.after-content` slot. The same dataset is also
21
+ * exported (`buildSiteChangelog`, `renderSiteChangelog`) so a Site can render
22
+ * it from its own route. No client JavaScript is required.
23
+ *
24
+ * When Git is unavailable the build is left untouched and a warning diagnostic
25
+ * is reported instead of failing.
26
+ */
27
+ export declare function changelog(options?: ChangelogOptions): import("@riebeckite/core").RiebeckitePlugin<ChangelogOptions>;
28
+ /** Alias matching the `*Plugin` suffix used by other plugin factories. */
29
+ export declare const changelogPlugin: typeof changelog;
package/dist/index.js ADDED
@@ -0,0 +1,445 @@
1
+ // index.ts
2
+ import {
3
+ appendContentBodySlot,
4
+ createStyleAsset,
5
+ definePlugin
6
+ } from "@riebeckite/core";
7
+
8
+ // src/changelog.ts
9
+ function resolveLookbackSince(lookbackDays, now = /* @__PURE__ */ new Date()) {
10
+ if (lookbackDays === void 0) return void 0;
11
+ const since = now.getTime() - lookbackDays * 24 * 60 * 60 * 1e3;
12
+ return new Date(since).toISOString();
13
+ }
14
+ function formatChangelogDate(isoDate, options) {
15
+ if (options.dateFormat === "iso") return isoDate.slice(0, 10);
16
+ const date = new Date(isoDate);
17
+ if (Number.isNaN(date.getTime())) return isoDate;
18
+ return new Intl.DateTimeFormat(options.locale, {
19
+ dateStyle: options.dateFormat === "long" ? "long" : "medium",
20
+ timeZone: "UTC"
21
+ }).format(date);
22
+ }
23
+ function filterChangelogCommits(commits, options) {
24
+ const cutoff = resolveCutoff(options.lookbackDays);
25
+ return commits.filter((commit) => cutoff === null || Date.parse(commit.date) >= cutoff).toSorted(compareCommitsDescending);
26
+ }
27
+ function buildNoteChangeHistory(entry, commits, options) {
28
+ return {
29
+ slug: entry.slug,
30
+ permalink: entry.permalink,
31
+ title: entry.title,
32
+ commits: filterChangelogCommits(commits, options).slice(0, options.maxPerNote).map((commit) => toChangelogRecord(commit, options))
33
+ };
34
+ }
35
+ function buildSiteChangelog(args) {
36
+ const byPath = invertContentIndex(args.contentIndex, args.entries);
37
+ const bySlug = new Map(args.entries.map((entry) => [entry.slug, entry]));
38
+ const entries = filterChangelogCommits(args.commits, args.options).slice(0, args.options.maxSiteWide).map(
39
+ (commit) => ({
40
+ ...toChangelogRecord(commit, args.options),
41
+ notes: resolveCommitNotes(commit, byPath, bySlug)
42
+ })
43
+ );
44
+ return { entries };
45
+ }
46
+ function toChangelogRecord(commit, options) {
47
+ return {
48
+ hash: commit.hash,
49
+ shortHash: commit.shortHash,
50
+ date: formatChangelogDate(commit.date, options),
51
+ dateIso: commit.date,
52
+ subject: commit.subject,
53
+ author: commit.author
54
+ };
55
+ }
56
+ function resolveCommitNotes(commit, byPath, bySlug) {
57
+ const notes = /* @__PURE__ */ new Map();
58
+ for (const file of commit.files) {
59
+ const slug = byPath.get(normalizePath(file));
60
+ if (!slug) continue;
61
+ const entry = bySlug.get(slug);
62
+ if (!entry) continue;
63
+ notes.set(slug, {
64
+ slug: entry.slug,
65
+ permalink: entry.permalink,
66
+ title: entry.title
67
+ });
68
+ }
69
+ return [...notes.values()].toSorted((a, b) => a.title.localeCompare(b.title));
70
+ }
71
+ function invertContentIndex(contentIndex, entries) {
72
+ const byPath = /* @__PURE__ */ new Map();
73
+ for (const entry of entries) {
74
+ const path = contentIndex.get(entry.slug.toLowerCase());
75
+ if (path) byPath.set(normalizePath(path), entry.slug);
76
+ }
77
+ return byPath;
78
+ }
79
+ function resolveCutoff(lookbackDays) {
80
+ if (lookbackDays === void 0) return null;
81
+ return Date.now() - lookbackDays * 24 * 60 * 60 * 1e3;
82
+ }
83
+ function compareCommitsDescending(a, b) {
84
+ const difference = Date.parse(b.date) - Date.parse(a.date);
85
+ if (difference !== 0) return difference;
86
+ return b.hash.localeCompare(a.hash);
87
+ }
88
+ function normalizePath(filePath) {
89
+ return filePath.replace(/\\/g, "/").replace(/^\.\//, "");
90
+ }
91
+
92
+ // src/git/history_reader.ts
93
+ import { execFile } from "node:child_process";
94
+ import { promisify } from "node:util";
95
+ var execFileAsync = promisify(execFile);
96
+ var fieldSeparator = "";
97
+ var recordSeparator = "";
98
+ var logFormat = ["%H", "%h", "%cI", "%s", "%an"].join(fieldSeparator);
99
+ var GitChangelogReader = class {
100
+ #cwd;
101
+ #fileCache = /* @__PURE__ */ new Map();
102
+ #recentCache;
103
+ #repositoryAvailable;
104
+ constructor(options = {}) {
105
+ this.#cwd = options.cwd ?? process.cwd();
106
+ }
107
+ /** Commit history for one file, newest first, following renames. */
108
+ getFileHistory(filePath, window = {}) {
109
+ const normalizedPath = normalizeGitPath(filePath);
110
+ if (window.since)
111
+ return this.#readFileHistory(normalizedPath, window.since);
112
+ const cached = this.#fileCache.get(normalizedPath);
113
+ if (cached) return cached;
114
+ const history = this.#readFileHistory(normalizedPath);
115
+ this.#fileCache.set(normalizedPath, history);
116
+ return history;
117
+ }
118
+ /**
119
+ * Recent commits that touch the working directory, newest first, each with
120
+ * the paths it changed.
121
+ */
122
+ getRecentCommits(window = {}) {
123
+ if (window.since) return this.#readRecentCommits(window.since);
124
+ this.#recentCache ??= this.#readRecentCommits();
125
+ return this.#recentCache;
126
+ }
127
+ /** True when `cwd` is inside a Git working tree. */
128
+ async isAvailable() {
129
+ this.#repositoryAvailable ??= runGit(this.#cwd, [
130
+ "rev-parse",
131
+ "--is-inside-work-tree"
132
+ ]).then((result) => result.ok && result.stdout.trim() === "true");
133
+ return this.#repositoryAvailable;
134
+ }
135
+ async #readFileHistory(filePath, since) {
136
+ if (!await this.isAvailable()) return [];
137
+ const args = ["log", "--follow", `--format=${recordSeparator}${logFormat}`];
138
+ if (since) args.push(`--since=${since}`);
139
+ args.push("--", filePath);
140
+ const result = await runGit(this.#cwd, args);
141
+ if (!result.ok) return [];
142
+ return parseCommitRecords(result.stdout);
143
+ }
144
+ async #readRecentCommits(since) {
145
+ if (!await this.isAvailable()) return [];
146
+ const args = [
147
+ "log",
148
+ `--format=${recordSeparator}${logFormat}`,
149
+ "--name-only"
150
+ ];
151
+ if (since) args.push(`--since=${since}`);
152
+ args.push("--", ".");
153
+ const result = await runGit(this.#cwd, args);
154
+ if (!result.ok) return [];
155
+ return parseCommitRecords(result.stdout);
156
+ }
157
+ };
158
+ function parseCommitRecords(stdout) {
159
+ if (!stdout.trim()) return [];
160
+ return stdout.split(recordSeparator).map((chunk) => chunk.replace(/^\n+/, "").replace(/\n+$/, "")).filter(Boolean).map(parseCommitRecord).filter((commit) => commit !== null);
161
+ }
162
+ function parseCommitRecord(chunk) {
163
+ const [header = "", ...rest] = chunk.split("\n");
164
+ const [hash, shortHash, date, subject, author] = header.split(fieldSeparator);
165
+ if (!hash || !shortHash || !date) return null;
166
+ return {
167
+ hash,
168
+ shortHash,
169
+ date,
170
+ subject: subject ?? "",
171
+ author: author ?? "",
172
+ files: rest.map((line) => line.trim()).filter(Boolean).map(normalizeGitPath)
173
+ };
174
+ }
175
+ function normalizeGitPath(filePath) {
176
+ return filePath.replace(/\\/g, "/").replace(/^\.\//, "");
177
+ }
178
+ async function runGit(cwd, args) {
179
+ try {
180
+ const { stdout } = await execFileAsync("git", args, {
181
+ cwd,
182
+ maxBuffer: 1024 * 1024 * 10
183
+ });
184
+ return { ok: true, stdout };
185
+ } catch (error) {
186
+ const stdout = typeof error === "object" && error !== null && "stdout" in error && typeof error.stdout === "string" ? error.stdout : "";
187
+ return { ok: false, stdout };
188
+ }
189
+ }
190
+
191
+ // src/options.ts
192
+ var DEFAULT_CHANGELOG_DATE_FORMAT = "iso";
193
+ var DEFAULT_CHANGELOG_LOCALE = "en";
194
+ var DEFAULT_CHANGELOG_PER_NOTE = true;
195
+ var DEFAULT_CHANGELOG_SITE_WIDE = false;
196
+ var DEFAULT_CHANGELOG_SITE_WIDE_SLUG = "changelog";
197
+ var DEFAULT_CHANGELOG_MAX_PER_NOTE = 10;
198
+ var DEFAULT_CHANGELOG_MAX_SITE_WIDE = 50;
199
+ var DEFAULT_CHANGELOG_SHOW_AUTHOR = true;
200
+ var DEFAULT_CHANGELOG_HEADING = true;
201
+ var DEFAULT_CHANGELOG_PER_NOTE_HEADING = "Change history";
202
+ var DEFAULT_CHANGELOG_SITE_WIDE_HEADING = "Changelog";
203
+ var DEFAULT_CHANGELOG_CLASS_NAME = "rr-changelog";
204
+ function resolveChangelogOptions(options = {}) {
205
+ return {
206
+ cwd: optionalText(options.cwd),
207
+ lookbackDays: options.lookbackDays,
208
+ dateFormat: options.dateFormat ?? DEFAULT_CHANGELOG_DATE_FORMAT,
209
+ locale: optionalText(options.locale) ?? DEFAULT_CHANGELOG_LOCALE,
210
+ perNote: options.perNote ?? DEFAULT_CHANGELOG_PER_NOTE,
211
+ siteWide: options.siteWide ?? DEFAULT_CHANGELOG_SITE_WIDE,
212
+ siteWideSlug: optionalText(options.siteWideSlug) ?? DEFAULT_CHANGELOG_SITE_WIDE_SLUG,
213
+ maxPerNote: options.maxPerNote ?? DEFAULT_CHANGELOG_MAX_PER_NOTE,
214
+ maxSiteWide: options.maxSiteWide ?? DEFAULT_CHANGELOG_MAX_SITE_WIDE,
215
+ showAuthor: options.showAuthor ?? DEFAULT_CHANGELOG_SHOW_AUTHOR,
216
+ heading: options.heading ?? DEFAULT_CHANGELOG_HEADING,
217
+ perNoteHeading: optionalText(options.perNoteHeading) ?? DEFAULT_CHANGELOG_PER_NOTE_HEADING,
218
+ siteWideHeading: optionalText(options.siteWideHeading) ?? DEFAULT_CHANGELOG_SITE_WIDE_HEADING,
219
+ className: optionalText(options.className) ?? DEFAULT_CHANGELOG_CLASS_NAME
220
+ };
221
+ }
222
+ function optionalText(value) {
223
+ if (typeof value !== "string") return void 0;
224
+ const trimmed = value.trim();
225
+ return trimmed === "" ? void 0 : trimmed;
226
+ }
227
+
228
+ // src/render.ts
229
+ import { escapeHtml, escapeHtmlAttribute } from "@riebeckite/core";
230
+ var CHANGELOG_NOTE_ATTRIBUTE = "data-changelog-note";
231
+ var CHANGELOG_SITE_ATTRIBUTE = "data-changelog-site";
232
+ function renderNoteChangeHistory(history, options) {
233
+ if (history.commits.length === 0) return "";
234
+ const className = escapeHtmlAttribute(options.className);
235
+ const heading = options.heading ? renderHeading(className, options.perNoteHeading) : "";
236
+ const items = history.commits.map((commit) => renderCommit(commit, className, options, [])).join("");
237
+ return `<section class="${className} ${className}--note" ${CHANGELOG_NOTE_ATTRIBUTE}>${heading}<ol class="${className}__list">${items}</ol></section>`;
238
+ }
239
+ function renderSiteChangelog(changelog2, options) {
240
+ if (changelog2.entries.length === 0) return "";
241
+ const className = escapeHtmlAttribute(options.className);
242
+ const heading = options.heading ? renderHeading(className, options.siteWideHeading) : "";
243
+ const items = changelog2.entries.map((entry) => renderCommit(entry, className, options, entry.notes)).join("");
244
+ return `<section class="${className} ${className}--site" ${CHANGELOG_SITE_ATTRIBUTE}>${heading}<ol class="${className}__list">${items}</ol></section>`;
245
+ }
246
+ function renderHeading(className, text) {
247
+ return `<h2 class="${className}__heading">${escapeHtml(text)}</h2>`;
248
+ }
249
+ function renderCommit(commit, className, options, notes) {
250
+ const author = options.showAuthor ? `<span class="${className}__author">${escapeHtml(commit.author)}</span>` : "";
251
+ const subject = `<span class="${className}__subject">${escapeHtml(
252
+ commit.subject
253
+ )}</span>`;
254
+ const hash = `<code class="${className}__hash" title="${escapeHtmlAttribute(
255
+ commit.hash
256
+ )}">${escapeHtml(commit.shortHash)}</code>`;
257
+ const date = `<time class="${className}__date" datetime="${escapeHtmlAttribute(
258
+ commit.dateIso
259
+ )}">${escapeHtml(commit.date)}</time>`;
260
+ const noteList = renderNotes(notes, className);
261
+ return `<li class="${className}__item">${date}${subject}${author}${hash}${noteList}</li>`;
262
+ }
263
+ function renderNotes(notes, className) {
264
+ if (notes.length === 0) return "";
265
+ const items = notes.map(
266
+ (note) => `<li class="${className}__note"><a class="${className}__note-link" href="${escapeHtmlAttribute(
267
+ note.permalink
268
+ )}">${escapeHtml(note.title)}</a></li>`
269
+ ).join("");
270
+ return `<ul class="${className}__notes">${items}</ul>`;
271
+ }
272
+
273
+ // index.ts
274
+ var CHANGELOG_PLUGIN_NAME = "changelog";
275
+ var CHANGELOG_BODY_SLOT = "article.after-content";
276
+ var PER_NOTE_CONCURRENCY = 4;
277
+ function changelog(options = {}) {
278
+ const resolved = resolveChangelogOptions(options);
279
+ return definePlugin({
280
+ name: CHANGELOG_PLUGIN_NAME,
281
+ options,
282
+ validateOptions: validateChangelogOptions,
283
+ onManifestCreated: (context) => applyChangelog(context, resolved),
284
+ assets: [createStyleAsset(CHANGELOG_PLUGIN_NAME)]
285
+ });
286
+ }
287
+ var changelogPlugin = changelog;
288
+ async function applyChangelog(context, options) {
289
+ if (!options.perNote && !options.siteWide) return;
290
+ const reader = new GitChangelogReader({ cwd: options.cwd });
291
+ if (!await reader.isAvailable()) {
292
+ reportGitUnavailable(context);
293
+ return;
294
+ }
295
+ const since = resolveLookbackSince(options.lookbackDays);
296
+ if (options.perNote) {
297
+ await forEachWithConcurrency(
298
+ context.manifest.publicEntries,
299
+ PER_NOTE_CONCURRENCY,
300
+ async (entry) => {
301
+ if (options.siteWide && entry.slug === options.siteWideSlug) return;
302
+ await applyNoteHistory(context, options, reader, entry, since);
303
+ }
304
+ );
305
+ }
306
+ if (options.siteWide) {
307
+ await applySiteChangelog(context, options, reader, since);
308
+ }
309
+ }
310
+ async function applyNoteHistory(context, options, reader, entry, since) {
311
+ if (hasSlot(entry, CHANGELOG_NOTE_ATTRIBUTE)) return;
312
+ const filePath = resolveEntryFilePath(entry, context.manifest.contentIndex);
313
+ const commits = await reader.getFileHistory(filePath, { since });
314
+ const history = buildNoteChangeHistory(entry, commits, options);
315
+ const html = renderNoteChangeHistory(history, options);
316
+ if (html) appendContentBodySlot(entry, CHANGELOG_BODY_SLOT, html);
317
+ }
318
+ async function applySiteChangelog(context, options, reader, since) {
319
+ const target = context.manifest.publicEntries.find(
320
+ (entry) => entry.slug === options.siteWideSlug
321
+ );
322
+ if (!target) {
323
+ context.diagnostics.push({
324
+ code: "changelog-target-missing",
325
+ severity: "warning",
326
+ pluginName: CHANGELOG_PLUGIN_NAME,
327
+ message: `changelog: the site-wide target note "${options.siteWideSlug}" was not found; the site-wide changelog was skipped.`,
328
+ suggestion: `Create a public note with slug "${options.siteWideSlug}" or set siteWideSlug to an existing note.`
329
+ });
330
+ return;
331
+ }
332
+ if (hasSlot(target, CHANGELOG_SITE_ATTRIBUTE)) return;
333
+ const commits = await reader.getRecentCommits({ since });
334
+ const changelog2 = buildSiteChangelog({
335
+ entries: context.manifest.publicEntries,
336
+ commits,
337
+ contentIndex: context.manifest.contentIndex,
338
+ options
339
+ });
340
+ const html = renderSiteChangelog(changelog2, options);
341
+ if (html) appendContentBodySlot(target, CHANGELOG_BODY_SLOT, html);
342
+ }
343
+ function resolveEntryFilePath(entry, contentIndex) {
344
+ const indexedPath = contentIndex.get(entry.slug.toLowerCase());
345
+ return indexedPath ?? `${entry.slug}.md`;
346
+ }
347
+ function hasSlot(entry, attribute) {
348
+ return entry.bodySlots?.[CHANGELOG_BODY_SLOT]?.includes(attribute) ?? false;
349
+ }
350
+ function reportGitUnavailable(context) {
351
+ const message = "changelog: Git is unavailable or this directory is not a Git repository; change history was skipped.";
352
+ context.diagnostics.push({
353
+ code: "changelog-git-unavailable",
354
+ severity: "warning",
355
+ pluginName: CHANGELOG_PLUGIN_NAME,
356
+ message
357
+ });
358
+ context.logger.warn(message);
359
+ }
360
+ async function forEachWithConcurrency(items, limit, work) {
361
+ let index = 0;
362
+ const workers = Array.from(
363
+ { length: Math.min(limit, items.length) },
364
+ async () => {
365
+ while (index < items.length) {
366
+ const current = items[index];
367
+ index += 1;
368
+ await work(current);
369
+ }
370
+ }
371
+ );
372
+ await Promise.all(workers);
373
+ }
374
+ function validateChangelogOptions(options) {
375
+ if (!options) return [];
376
+ const issues = [];
377
+ const assertNonEmptyString = (key) => {
378
+ const value = options[key];
379
+ if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
380
+ issues.push({ path: key, message: "Expected a non-empty string." });
381
+ }
382
+ };
383
+ const assertBoolean = (key) => {
384
+ if (options[key] !== void 0 && typeof options[key] !== "boolean") {
385
+ issues.push({ path: key, message: "Expected a boolean." });
386
+ }
387
+ };
388
+ const assertNonNegativeInteger = (key) => {
389
+ const value = options[key];
390
+ if (value !== void 0 && (typeof value !== "number" || !Number.isInteger(value) || value < 0)) {
391
+ issues.push({
392
+ path: key,
393
+ message: "Expected a non-negative integer."
394
+ });
395
+ }
396
+ };
397
+ for (const key of [
398
+ "cwd",
399
+ "locale",
400
+ "siteWideSlug",
401
+ "perNoteHeading",
402
+ "siteWideHeading",
403
+ "className"
404
+ ]) {
405
+ assertNonEmptyString(key);
406
+ }
407
+ for (const key of ["perNote", "siteWide", "showAuthor", "heading"]) {
408
+ assertBoolean(key);
409
+ }
410
+ for (const key of ["lookbackDays", "maxPerNote", "maxSiteWide"]) {
411
+ assertNonNegativeInteger(key);
412
+ }
413
+ if (options.dateFormat !== void 0 && options.dateFormat !== "iso" && options.dateFormat !== "long" && options.dateFormat !== "short") {
414
+ issues.push({
415
+ path: "dateFormat",
416
+ message: 'Expected "iso", "long", or "short".'
417
+ });
418
+ }
419
+ return issues;
420
+ }
421
+ export {
422
+ CHANGELOG_BODY_SLOT,
423
+ CHANGELOG_NOTE_ATTRIBUTE,
424
+ CHANGELOG_PLUGIN_NAME,
425
+ CHANGELOG_SITE_ATTRIBUTE,
426
+ DEFAULT_CHANGELOG_CLASS_NAME,
427
+ DEFAULT_CHANGELOG_HEADING,
428
+ DEFAULT_CHANGELOG_LOCALE,
429
+ DEFAULT_CHANGELOG_MAX_PER_NOTE,
430
+ DEFAULT_CHANGELOG_MAX_SITE_WIDE,
431
+ DEFAULT_CHANGELOG_PER_NOTE_HEADING,
432
+ DEFAULT_CHANGELOG_SITE_WIDE_HEADING,
433
+ DEFAULT_CHANGELOG_SITE_WIDE_SLUG,
434
+ GitChangelogReader,
435
+ buildNoteChangeHistory,
436
+ buildSiteChangelog,
437
+ changelog,
438
+ changelogPlugin,
439
+ filterChangelogCommits,
440
+ formatChangelogDate,
441
+ renderNoteChangeHistory,
442
+ renderSiteChangelog,
443
+ resolveChangelogOptions,
444
+ resolveLookbackSince
445
+ };
@@ -0,0 +1,27 @@
1
+ import type { ContentManifestEntry } from "@riebeckite/core";
2
+ import type { ChangelogCommit, NoteChangeHistory, ResolvedChangelogOptions, SiteChangelog } from "./types.js";
3
+ /**
4
+ * Converts a lookback window in days to the ISO timestamp Git's `--since`
5
+ * accepts. Pure so callers can compute it once per build.
6
+ */
7
+ export declare function resolveLookbackSince(lookbackDays: number | undefined, now?: Date): string | undefined;
8
+ /** Formats an ISO commit date for display. */
9
+ export declare function formatChangelogDate(isoDate: string, options: ResolvedChangelogOptions): string;
10
+ /**
11
+ * Filters commits to the lookback window and returns them newest first.
12
+ * Git already returns newest first; sorting keeps the dataset deterministic
13
+ * when commits share a timestamp.
14
+ */
15
+ export declare function filterChangelogCommits(commits: readonly ChangelogCommit[], options: ResolvedChangelogOptions): ChangelogCommit[];
16
+ /** Builds the per-note history for one entry. */
17
+ export declare function buildNoteChangeHistory(entry: ContentManifestEntry, commits: readonly ChangelogCommit[], options: ResolvedChangelogOptions): NoteChangeHistory;
18
+ /**
19
+ * Builds the site-wide changelog dataset. Each commit is linked to the notes
20
+ * it touched by matching changed paths against the manifest content index.
21
+ */
22
+ export declare function buildSiteChangelog(args: {
23
+ entries: readonly ContentManifestEntry[];
24
+ commits: readonly ChangelogCommit[];
25
+ contentIndex: Map<string, string>;
26
+ options: ResolvedChangelogOptions;
27
+ }): SiteChangelog;
@@ -0,0 +1,25 @@
1
+ import type { ChangelogCommit, GitChangelogReaderOptions } from "../types.js";
2
+ /** Optional window applied to a Git query. */
3
+ export type GitLogWindow = {
4
+ /** ISO timestamp passed to `git log --since`. */
5
+ since?: string;
6
+ };
7
+ /**
8
+ * Reads local Git history for individual files and for the whole working
9
+ * directory. Mirrors the Git access used by `@riebeckite/plugin-diff`: it runs
10
+ * `git` through `execFile` and degrades to empty results when Git is missing or
11
+ * the directory is not a repository.
12
+ */
13
+ export declare class GitChangelogReader {
14
+ #private;
15
+ constructor(options?: GitChangelogReaderOptions);
16
+ /** Commit history for one file, newest first, following renames. */
17
+ getFileHistory(filePath: string, window?: GitLogWindow): Promise<ChangelogCommit[]>;
18
+ /**
19
+ * Recent commits that touch the working directory, newest first, each with
20
+ * the paths it changed.
21
+ */
22
+ getRecentCommits(window?: GitLogWindow): Promise<ChangelogCommit[]>;
23
+ /** True when `cwd` is inside a Git working tree. */
24
+ isAvailable(): Promise<boolean>;
25
+ }
@@ -0,0 +1,18 @@
1
+ import type { ChangelogDateFormat, ChangelogOptions, ResolvedChangelogOptions } from "./types.js";
2
+ export declare const DEFAULT_CHANGELOG_DATE_FORMAT: ChangelogDateFormat;
3
+ export declare const DEFAULT_CHANGELOG_LOCALE = "en";
4
+ export declare const DEFAULT_CHANGELOG_PER_NOTE = true;
5
+ export declare const DEFAULT_CHANGELOG_SITE_WIDE = false;
6
+ export declare const DEFAULT_CHANGELOG_SITE_WIDE_SLUG = "changelog";
7
+ export declare const DEFAULT_CHANGELOG_MAX_PER_NOTE = 10;
8
+ export declare const DEFAULT_CHANGELOG_MAX_SITE_WIDE = 50;
9
+ export declare const DEFAULT_CHANGELOG_SHOW_AUTHOR = true;
10
+ export declare const DEFAULT_CHANGELOG_HEADING = true;
11
+ export declare const DEFAULT_CHANGELOG_PER_NOTE_HEADING = "Change history";
12
+ export declare const DEFAULT_CHANGELOG_SITE_WIDE_HEADING = "Changelog";
13
+ export declare const DEFAULT_CHANGELOG_CLASS_NAME = "rr-changelog";
14
+ /**
15
+ * Applies defaults to `ChangelogOptions`. Pure and deterministic so the plugin
16
+ * can resolve options once and reuse them for every manifest entry.
17
+ */
18
+ export declare function resolveChangelogOptions(options?: ChangelogOptions): ResolvedChangelogOptions;
@@ -0,0 +1,15 @@
1
+ import type { NoteChangeHistory, ResolvedChangelogOptions, SiteChangelog } from "./types.js";
2
+ /** Boolean attribute that marks a rendered per-note history section. */
3
+ export declare const CHANGELOG_NOTE_ATTRIBUTE = "data-changelog-note";
4
+ /** Boolean attribute that marks the rendered site-wide changelog section. */
5
+ export declare const CHANGELOG_SITE_ATTRIBUTE = "data-changelog-site";
6
+ /**
7
+ * Renders a note's change history. Returns an empty string when there is
8
+ * nothing to show, so callers can leave the entry's HTML untouched.
9
+ */
10
+ export declare function renderNoteChangeHistory(history: NoteChangeHistory, options: ResolvedChangelogOptions): string;
11
+ /**
12
+ * Renders the site-wide changelog dataset. Returns an empty string when there
13
+ * are no commits, so callers can leave the target's HTML untouched.
14
+ */
15
+ export declare function renderSiteChangelog(changelog: SiteChangelog, options: ResolvedChangelogOptions): string;
@@ -0,0 +1,108 @@
1
+ /** How commit dates are formatted in rendered output. */
2
+ export type ChangelogDateFormat = "iso" | "long" | "short";
3
+ /** Options accepted by `changelog()`. */
4
+ export type ChangelogOptions = {
5
+ /**
6
+ * Working directory for Git commands. Defaults to `process.cwd()`. Point it
7
+ * at the content directory when the site is built from elsewhere.
8
+ */
9
+ cwd?: string;
10
+ /**
11
+ * Only include commits newer than this many days. When omitted, the full
12
+ * history is used.
13
+ */
14
+ lookbackDays?: number;
15
+ /** Date format for rendered entries. Defaults to `"iso"`. */
16
+ dateFormat?: ChangelogDateFormat;
17
+ /** Locale used by `"long"` and `"short"` dates. Defaults to `"en"`. */
18
+ locale?: string;
19
+ /** Render a per-note history section on every public note. Defaults to `true`. */
20
+ perNote?: boolean;
21
+ /**
22
+ * Build the site-wide changelog and inject it into the note at
23
+ * `siteWideSlug`. Defaults to `false`. The note itself is owned by the app;
24
+ * the plugin only fills its body slot.
25
+ */
26
+ siteWide?: boolean;
27
+ /** Slug of the note that receives the site-wide changelog. Defaults to `"changelog"`. */
28
+ siteWideSlug?: string;
29
+ /** Maximum commits listed per note. Defaults to `10`. */
30
+ maxPerNote?: number;
31
+ /** Maximum commits listed in the site-wide changelog. Defaults to `50`. */
32
+ maxSiteWide?: number;
33
+ /** Show the commit author. Defaults to `true`. */
34
+ showAuthor?: boolean;
35
+ /** Render an `<h2>` heading above each listing. Defaults to `true`. */
36
+ heading?: boolean;
37
+ /** Heading text for per-note history. Defaults to `"Change history"`. */
38
+ perNoteHeading?: string;
39
+ /** Heading text for the site-wide changelog. Defaults to `"Changelog"`. */
40
+ siteWideHeading?: string;
41
+ /** Root CSS class. Defaults to `"rr-changelog"`. */
42
+ className?: string;
43
+ };
44
+ /** `ChangelogOptions` with every default applied. */
45
+ export type ResolvedChangelogOptions = {
46
+ cwd?: string;
47
+ lookbackDays?: number;
48
+ dateFormat: ChangelogDateFormat;
49
+ locale: string;
50
+ perNote: boolean;
51
+ siteWide: boolean;
52
+ siteWideSlug: string;
53
+ maxPerNote: number;
54
+ maxSiteWide: number;
55
+ showAuthor: boolean;
56
+ heading: boolean;
57
+ perNoteHeading: string;
58
+ siteWideHeading: string;
59
+ className: string;
60
+ };
61
+ /** A commit exactly as returned by the Git-backed reader. */
62
+ export type ChangelogCommit = {
63
+ hash: string;
64
+ shortHash: string;
65
+ /** ISO 8601 committer date. */
66
+ date: string;
67
+ subject: string;
68
+ author: string;
69
+ /** Paths changed by the commit, relative to the Git working directory. */
70
+ files: string[];
71
+ };
72
+ /** A commit prepared for rendering. */
73
+ export type ChangelogRecord = {
74
+ hash: string;
75
+ shortHash: string;
76
+ /** Display date formatted for the resolved options. */
77
+ date: string;
78
+ /** Machine-readable ISO 8601 date. */
79
+ dateIso: string;
80
+ subject: string;
81
+ author: string;
82
+ };
83
+ /** Per-note change history, ready to render. */
84
+ export type NoteChangeHistory = {
85
+ slug: string;
86
+ permalink: string;
87
+ title: string;
88
+ commits: ChangelogRecord[];
89
+ };
90
+ /** A note touched by a site-wide changelog commit. */
91
+ export type SiteChangelogNote = {
92
+ slug: string;
93
+ permalink: string;
94
+ title: string;
95
+ };
96
+ /** A site-wide changelog entry: a commit plus the notes it touched. */
97
+ export type SiteChangelogEntry = ChangelogRecord & {
98
+ notes: SiteChangelogNote[];
99
+ };
100
+ /** The site-wide changelog dataset, ready for the app to render. */
101
+ export type SiteChangelog = {
102
+ entries: SiteChangelogEntry[];
103
+ };
104
+ /** Options accepted by `GitChangelogReader`. */
105
+ export type GitChangelogReaderOptions = {
106
+ /** Working directory for Git commands. Defaults to `process.cwd()`. */
107
+ cwd?: string;
108
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@riebeckite/plugin-changelog",
3
+ "version": "0.0.6",
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
+ "./style.css": "./style.css"
16
+ },
17
+ "dependencies": {
18
+ "@riebeckite/core": "0.0.6"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^24.5.2"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "LICENSE",
28
+ "README.md",
29
+ "README_ja.md",
30
+ "dist",
31
+ "style.css"
32
+ ],
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/Rerurate514/riebeckite.git",
36
+ "directory": "packages/plugins/changelog"
37
+ },
38
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
41
+ },
42
+ "description": "Git-backed change history and changelogs for Riebeckite.",
43
+ "keywords": [
44
+ "riebeckite",
45
+ "plugin",
46
+ "git",
47
+ "changelog"
48
+ ],
49
+ "engines": {
50
+ "node": "^20.19.0 || >=22.12.0"
51
+ },
52
+ "sideEffects": [
53
+ "./style.css"
54
+ ],
55
+ "scripts": {
56
+ "build": "node ../../../scripts/build_package.mjs"
57
+ }
58
+ }
package/style.css ADDED
@@ -0,0 +1,97 @@
1
+ .rr-changelog {
2
+ margin-block: 3rem 2rem;
3
+ border-block-start: 1px solid
4
+ var(--rb-color-border, color-mix(in srgb, currentColor 18%, transparent));
5
+ padding-block-start: 1.25rem;
6
+ color: var(--rb-color-ink, currentColor);
7
+ }
8
+
9
+ .rr-changelog__heading {
10
+ margin: 0 0 0.75rem;
11
+ font-size: 0.8125rem;
12
+ font-weight: 600;
13
+ letter-spacing: 0.08em;
14
+ text-transform: uppercase;
15
+ }
16
+
17
+ .rr-changelog__list {
18
+ display: grid;
19
+ gap: 0.75rem;
20
+ margin: 0;
21
+ padding: 0;
22
+ list-style: none;
23
+ }
24
+
25
+ .rr-changelog__item {
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ align-items: baseline;
29
+ gap: 0.5rem 0.75rem;
30
+ border-block-start: 1px solid
31
+ var(--rb-color-border, color-mix(in srgb, currentColor 12%, transparent));
32
+ padding-block-start: 0.75rem;
33
+ }
34
+
35
+ .rr-changelog__item:first-child {
36
+ border-block-start: 0;
37
+ padding-block-start: 0;
38
+ }
39
+
40
+ .rr-changelog__date {
41
+ min-width: 6rem;
42
+ color: var(
43
+ --rb-color-muted,
44
+ color-mix(in srgb, currentColor 62%, transparent)
45
+ );
46
+ font-size: 0.8125rem;
47
+ font-variant-numeric: tabular-nums;
48
+ }
49
+
50
+ .rr-changelog__subject {
51
+ flex: 1 1 12rem;
52
+ overflow-wrap: anywhere;
53
+ font-size: 0.9375rem;
54
+ line-height: 1.45;
55
+ }
56
+
57
+ .rr-changelog__author {
58
+ color: var(
59
+ --rb-color-muted,
60
+ color-mix(in srgb, currentColor 62%, transparent)
61
+ );
62
+ font-size: 0.8125rem;
63
+ }
64
+
65
+ .rr-changelog__hash {
66
+ font-family: var(
67
+ --rb-font-mono,
68
+ ui-monospace,
69
+ SFMono-Regular,
70
+ Consolas,
71
+ monospace
72
+ );
73
+ font-size: 0.75rem;
74
+ color: var(
75
+ --rb-color-muted,
76
+ color-mix(in srgb, currentColor 56%, transparent)
77
+ );
78
+ }
79
+
80
+ .rr-changelog__notes {
81
+ display: flex;
82
+ flex-basis: 100%;
83
+ flex-wrap: wrap;
84
+ gap: 0.5rem;
85
+ margin: 0;
86
+ padding: 0;
87
+ list-style: none;
88
+ }
89
+
90
+ .rr-changelog__note-link {
91
+ color: var(--rb-color-accent, currentColor);
92
+ font-size: 0.8125rem;
93
+ }
94
+
95
+ .rr-changelog--site .rr-changelog__item {
96
+ padding-block-end: 0.25rem;
97
+ }