@riebeckite/plugin-daily-notes 0.0.1

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,74 @@
1
+ # @riebeckite/plugin-daily-notes
2
+
3
+ Surfaces short snippets extracted from Daily Notes as a site widget.
4
+
5
+ [日本語](./README_ja.md)
6
+
7
+ ## Overview
8
+
9
+ A Daily Note is often one long, private journal file. This plugin reads the raw
10
+ manifest, picks notes under a configured directory, and extracts exactly one
11
+ short snippet per note using the first successful strategy:
12
+
13
+ 1. a frontmatter key (`daily-summary` by default),
14
+ 2. a section under a heading (`今日のひとこと` by default),
15
+ 3. a fenced code block (`daily-snippet` by default).
16
+
17
+ When every strategy fails the note is skipped. The note body is never emitted
18
+ wholesale, so a long private note only contributes the snippet that opted in.
19
+
20
+ `sourceUrl` and `sourceTitle` are attached only when `isPublished` accepts the
21
+ note. An unpublished note's permalink and title stay `null`, so private notes
22
+ never leak their location.
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { defineConfig } from "@riebeckite/core";
28
+ import { dailyNotesPlugin } from "@riebeckite/plugin-daily-notes";
29
+
30
+ export default defineConfig({
31
+ // ...
32
+ plugins: [dailyNotesPlugin()],
33
+ });
34
+ ```
35
+
36
+ ### Render the widget
37
+
38
+ ```tsx
39
+ import DailyNotes, { getDailyNotes } from "@riebeckite/plugin-daily-notes";
40
+
41
+ const notes = getDailyNotes({ manifest, config });
42
+
43
+ return <DailyNotes notes={notes} />;
44
+ ```
45
+
46
+ `getDailyNotes` reads `manifest.entries` (the raw view), sorts newest first,
47
+ and applies the default limit of 5. Pass `options` to override the location or
48
+ the extraction strategy:
49
+
50
+ ```ts
51
+ getDailyNotes({
52
+ manifest,
53
+ config,
54
+ options: {
55
+ source: { directory: "Daily", pathPattern: "Daily/{YYYY}-{MM}-{DD}" },
56
+ extract: { frontmatter: "daily-summary", section: "今日のひとこと" },
57
+ widget: { limit: 3 },
58
+ },
59
+ });
60
+ ```
61
+
62
+ Set a strategy to `false` to disable it. `pathPattern` supports `{YYYY}`,
63
+ `{MM}`, `{DD}`, and `*` so a note filename can be matched precisely.
64
+
65
+ ## Exports
66
+
67
+ - `dailyNotesPlugin(options?)` — plugin factory (registers `style.css`)
68
+ - `getDailyNotes({ manifest, config, options? })` — sorted `DailyNote[]`
69
+ - `DailyNotes` — widget component (`{ notes, limit? }`)
70
+ - Types: `DailyNote`, `DailyNotesOptions`, `ResolvedDailyNotesExtract`
71
+
72
+ ## See also
73
+
74
+ - [Plugin guide](../../docs/plugins_en.md)
package/README_ja.md ADDED
@@ -0,0 +1,66 @@
1
+ # @riebeckite/plugin-daily-notes
2
+
3
+ デイリーノートから短いスニペットを取り出してサイトのウィジェットとして表示するプラグインです。
4
+
5
+ [English](./README_en.md)
6
+
7
+ ## 概要
8
+
9
+ デイリーノートは、長い非公開の日記を 1 ファイルにまとめることが少なくありません。このプラグインは生のマニフェストを読み、指定ディレクトリ配下のノートを対象に、次の順番で最初に成功した方法からスニペットを 1 つだけ取り出します。
10
+
11
+ 1. frontmatter のキー(既定は `daily-summary`)
12
+ 2. 見出しで示した節(既定は `今日のひとこと`)
13
+ 3. コードブロック(既定は `daily-snippet`)
14
+
15
+ すべて失敗したノートは表示せず、本文を丸ごと出すこともありません。長い非公開ノートは、スニペットとして明示した部分だけを提供します。
16
+
17
+ `sourceUrl` と `sourceTitle` は `isPublished` が公開と判定したときだけ付きます。非公開ノートのパーマリンクとタイトルは `null` のままなので、置き場所が漏れることはありません。
18
+
19
+ ## 使い方
20
+
21
+ ```ts
22
+ import { defineConfig } from "@riebeckite/core";
23
+ import { dailyNotesPlugin } from "@riebeckite/plugin-daily-notes";
24
+
25
+ export default defineConfig({
26
+ // ...
27
+ plugins: [dailyNotesPlugin()],
28
+ });
29
+ ```
30
+
31
+ ### ウィジェットを置く
32
+
33
+ ```tsx
34
+ import DailyNotes, { getDailyNotes } from "@riebeckite/plugin-daily-notes";
35
+
36
+ const notes = getDailyNotes({ manifest, config });
37
+
38
+ return <DailyNotes notes={notes} />;
39
+ ```
40
+
41
+ `getDailyNotes` は生の `manifest.entries` を読み、新しい順に並べ、既定の上限 5 件に絞ります。場所や抽出方法を変えたいときは `options` を渡します。
42
+
43
+ ```ts
44
+ getDailyNotes({
45
+ manifest,
46
+ config,
47
+ options: {
48
+ source: { directory: "Daily", pathPattern: "Daily/{YYYY}-{MM}-{DD}" },
49
+ extract: { frontmatter: "daily-summary", section: "今日のひとこと" },
50
+ widget: { limit: 3 },
51
+ },
52
+ });
53
+ ```
54
+
55
+ 方法を `false` にすると、その抽出を無効にできます。`pathPattern` では `{YYYY}`、`{MM}`、`{DD}`、`*` が使え、ノートのファイル名を厳密に絞り込めます。
56
+
57
+ ## 主なエクスポート
58
+
59
+ - `dailyNotesPlugin(options?)`: プラグインを作る(`style.css` を登録する)
60
+ - `getDailyNotes({ manifest, config, options? })`: 並べ替え済みの `DailyNote[]` を返す
61
+ - `DailyNotes`: ウィジェットのコンポーネント(`{ notes, limit? }`)
62
+ - 型: `DailyNote`、`DailyNotesOptions`、`ResolvedDailyNotesExtract`
63
+
64
+ ## 関連資料
65
+
66
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
@@ -0,0 +1,7 @@
1
+ import type { DailyNote } from "../src/daily-notes.js";
2
+ type Props = {
3
+ notes: DailyNote[];
4
+ limit?: number;
5
+ };
6
+ export default function DailyNotes(props: Props): import("hono/jsx/jsx-dev-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,42 @@
1
+ // components/daily-notes.tsx
2
+ import { jsx, jsxs } from "hono/jsx/jsx-runtime";
3
+ var DEFAULT_LIMIT = 5;
4
+ function DailyNotes(props) {
5
+ const limit = props.limit ?? DEFAULT_LIMIT;
6
+ const notes = props.notes.slice(0, Math.max(0, limit));
7
+ if (notes.length === 0) return null;
8
+ return /* @__PURE__ */ jsxs(
9
+ "section",
10
+ {
11
+ class: "daily-notes rr-daily-notes",
12
+ "aria-labelledby": "daily-notes-title",
13
+ children: [
14
+ /* @__PURE__ */ jsxs("div", { class: "daily-notes__header", children: [
15
+ /* @__PURE__ */ jsx("p", { class: "daily-notes__eyebrow", children: "DAILY NOTES" }),
16
+ /* @__PURE__ */ jsx("h2", { class: "daily-notes__title", id: "daily-notes-title", children: "最近のデイリーノート" })
17
+ ] }),
18
+ /* @__PURE__ */ jsx("ul", { class: "daily-notes__list", children: notes.map((note) => /* @__PURE__ */ jsxs("li", { class: "daily-notes__item", children: [
19
+ /* @__PURE__ */ jsxs("div", { class: "daily-notes__meta", children: [
20
+ note.date.length > 0 ? /* @__PURE__ */ jsx("time", { class: "daily-notes__date", dateTime: note.date, children: formatDisplayDate(note.date) }) : null,
21
+ note.sourceUrl !== null ? /* @__PURE__ */ jsx("a", { class: "daily-notes__source", href: note.sourceUrl, children: resolveSourceLabel(note) }) : null
22
+ ] }),
23
+ /* @__PURE__ */ jsx("p", { class: "daily-notes__snippet", children: note.snippet })
24
+ ] }, note.slug)) })
25
+ ]
26
+ }
27
+ );
28
+ }
29
+ function resolveSourceLabel(note) {
30
+ if (note.sourceTitle !== null && note.sourceTitle.length > 0) {
31
+ return note.sourceTitle;
32
+ }
33
+ return note.sourceUrl ?? "";
34
+ }
35
+ function formatDisplayDate(date) {
36
+ const [year, month, day] = date.split("-");
37
+ if (!year || !month || !day) return date;
38
+ return `${year}年${Number(month)}月${Number(day)}日`;
39
+ }
40
+ export {
41
+ DailyNotes as default
42
+ };
@@ -0,0 +1,10 @@
1
+ import { type RiebeckitePlugin } from "@riebeckite/core";
2
+ import type { DailyNotesOptions } from "./src/daily-notes.js";
3
+ export { default as DailyNotes } from "./components/daily-notes.js";
4
+ export type { DailyNote, DailyNotesOptions, ResolvedDailyNotesExtract, } from "./src/daily-notes.js";
5
+ export { getDailyNotes } from "./src/daily-notes.server.js";
6
+ /**
7
+ * Registers the Daily Notes widget. Extraction options are consumed by
8
+ * `getDailyNotes`; the plugin itself only wires the stylesheet.
9
+ */
10
+ export declare function dailyNotesPlugin(options?: DailyNotesOptions): RiebeckitePlugin<DailyNotesOptions | undefined>;
package/dist/index.js ADDED
@@ -0,0 +1,271 @@
1
+ // index.ts
2
+ import {
3
+ createStyleAsset,
4
+ definePlugin
5
+ } from "@riebeckite/core";
6
+
7
+ // components/daily-notes.tsx
8
+ import { jsx, jsxs } from "hono/jsx/jsx-runtime";
9
+ var DEFAULT_LIMIT = 5;
10
+ function DailyNotes(props) {
11
+ const limit = props.limit ?? DEFAULT_LIMIT;
12
+ const notes = props.notes.slice(0, Math.max(0, limit));
13
+ if (notes.length === 0) return null;
14
+ return /* @__PURE__ */ jsxs(
15
+ "section",
16
+ {
17
+ class: "daily-notes rr-daily-notes",
18
+ "aria-labelledby": "daily-notes-title",
19
+ children: [
20
+ /* @__PURE__ */ jsxs("div", { class: "daily-notes__header", children: [
21
+ /* @__PURE__ */ jsx("p", { class: "daily-notes__eyebrow", children: "DAILY NOTES" }),
22
+ /* @__PURE__ */ jsx("h2", { class: "daily-notes__title", id: "daily-notes-title", children: "最近のデイリーノート" })
23
+ ] }),
24
+ /* @__PURE__ */ jsx("ul", { class: "daily-notes__list", children: notes.map((note) => /* @__PURE__ */ jsxs("li", { class: "daily-notes__item", children: [
25
+ /* @__PURE__ */ jsxs("div", { class: "daily-notes__meta", children: [
26
+ note.date.length > 0 ? /* @__PURE__ */ jsx("time", { class: "daily-notes__date", dateTime: note.date, children: formatDisplayDate(note.date) }) : null,
27
+ note.sourceUrl !== null ? /* @__PURE__ */ jsx("a", { class: "daily-notes__source", href: note.sourceUrl, children: resolveSourceLabel(note) }) : null
28
+ ] }),
29
+ /* @__PURE__ */ jsx("p", { class: "daily-notes__snippet", children: note.snippet })
30
+ ] }, note.slug)) })
31
+ ]
32
+ }
33
+ );
34
+ }
35
+ function resolveSourceLabel(note) {
36
+ if (note.sourceTitle !== null && note.sourceTitle.length > 0) {
37
+ return note.sourceTitle;
38
+ }
39
+ return note.sourceUrl ?? "";
40
+ }
41
+ function formatDisplayDate(date) {
42
+ const [year, month, day] = date.split("-");
43
+ if (!year || !month || !day) return date;
44
+ return `${year}年${Number(month)}月${Number(day)}日`;
45
+ }
46
+
47
+ // src/daily-notes.server.ts
48
+ import {
49
+ isPublished
50
+ } from "@riebeckite/core";
51
+
52
+ // src/daily-notes.ts
53
+ var DEFAULT_DIRECTORY = "Daily";
54
+ var DEFAULT_FRONTMATTER_KEY = "daily-summary";
55
+ var DEFAULT_SECTION = "今日のひとこと";
56
+ var DEFAULT_CODE_BLOCK = "daily-snippet";
57
+ var DEFAULT_LIMIT2 = 5;
58
+ function resolveExtractOptions(options) {
59
+ const extract = options?.extract;
60
+ return {
61
+ frontmatter: extract?.frontmatter === void 0 ? DEFAULT_FRONTMATTER_KEY : extract.frontmatter,
62
+ section: extract?.section === void 0 ? DEFAULT_SECTION : extract.section,
63
+ codeBlock: extract?.codeBlock === void 0 ? DEFAULT_CODE_BLOCK : extract.codeBlock
64
+ };
65
+ }
66
+ function isDailyNoteSlug(slug, directory, pathPattern) {
67
+ if (directory.length > 0) {
68
+ const prefix = `${directory}/`;
69
+ if (slug !== directory && !slug.startsWith(prefix)) return false;
70
+ }
71
+ if (pathPattern === void 0) return true;
72
+ return matchesSlugPattern(slug, pathPattern);
73
+ }
74
+ function matchesSlugPattern(slug, pattern) {
75
+ return new RegExp(`^${toSlugPatternSource(pattern)}$`).test(slug);
76
+ }
77
+ function toSlugPatternSource(pattern) {
78
+ let source = "";
79
+ for (let index = 0; index < pattern.length; index++) {
80
+ const character = pattern[index];
81
+ if (character === "{") {
82
+ const end = pattern.indexOf("}", index + 1);
83
+ if (end !== -1) {
84
+ source += placeholderSource(pattern.slice(index + 1, end));
85
+ index = end;
86
+ continue;
87
+ }
88
+ }
89
+ if (character === "*") {
90
+ source += "[^/]*";
91
+ continue;
92
+ }
93
+ source += escapeRegExp(character);
94
+ }
95
+ return source;
96
+ }
97
+ function placeholderSource(token) {
98
+ if (token === "YYYY") return "\\d{4}";
99
+ if (token === "MM" || token === "DD") return "\\d{2}";
100
+ return "[^/]+";
101
+ }
102
+ function escapeRegExp(value) {
103
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
104
+ }
105
+ function extractDailyNoteSnippet(entry, extract) {
106
+ if (extract.frontmatter !== false) {
107
+ const value = entry.frontmatter[extract.frontmatter];
108
+ const text = typeof value === "string" ? value.trim() : "";
109
+ if (text.length > 0) return text;
110
+ }
111
+ if (extract.section !== false) {
112
+ const text = extractSectionSnippet(entry.html, extract.section);
113
+ if (text !== null) return text;
114
+ }
115
+ if (extract.codeBlock !== false) {
116
+ const text = extractCodeBlockSnippet(entry.html, extract.codeBlock);
117
+ if (text !== null) return text;
118
+ }
119
+ return null;
120
+ }
121
+ var HEADING_PATTERN = /<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/g;
122
+ function extractSectionSnippet(html, section) {
123
+ const headings = [...html.matchAll(HEADING_PATTERN)].map((match) => {
124
+ const start = match.index ?? 0;
125
+ return {
126
+ level: Number(match[1]),
127
+ title: decodeHtmlEntities(stripHtml(match[2])).trim(),
128
+ start,
129
+ end: start + match[0].length
130
+ };
131
+ });
132
+ const target = headings.find((heading) => heading.title === section);
133
+ if (!target) return null;
134
+ const boundary = headings.find(
135
+ (heading) => heading.start >= target.end && heading.level <= target.level
136
+ );
137
+ const body = html.slice(target.end, boundary?.start ?? html.length);
138
+ const text = collapseWhitespace(decodeHtmlEntities(stripHtml(body)));
139
+ return text.length > 0 ? text : null;
140
+ }
141
+ var CODE_BLOCK_PATTERN = /<code\b([^>]*)>([\s\S]*?)<\/code>/g;
142
+ function extractCodeBlockSnippet(html, language) {
143
+ const wanted = `language-${language}`;
144
+ for (const match of html.matchAll(CODE_BLOCK_PATTERN)) {
145
+ const classAttribute = match[1].match(/\bclass="([^"]*)"/)?.[1] ?? "";
146
+ if (!classAttribute.split(/\s+/).includes(wanted)) continue;
147
+ const text = decodeHtmlEntities(stripHtml(match[2])).trim();
148
+ if (text.length > 0) return text;
149
+ }
150
+ return null;
151
+ }
152
+ function resolveDailyNoteDate(entry) {
153
+ const fromFrontmatter = normalizeDateValue(entry.frontmatter.date) ?? normalizeDateValue(entry.frontmatter.created);
154
+ if (fromFrontmatter !== null) return fromFrontmatter;
155
+ return matchDate(entry.slug) ?? "";
156
+ }
157
+ var DATE_PATTERN = /(\d{4})-(\d{1,2})-(\d{1,2})/;
158
+ function normalizeDateValue(value) {
159
+ if (value instanceof Date) {
160
+ if (Number.isNaN(value.getTime())) return null;
161
+ return formatDate(
162
+ value.getUTCFullYear(),
163
+ value.getUTCMonth() + 1,
164
+ value.getUTCDate()
165
+ );
166
+ }
167
+ if (typeof value === "string") return matchDate(value);
168
+ return null;
169
+ }
170
+ function matchDate(value) {
171
+ const match = DATE_PATTERN.exec(value);
172
+ if (!match) return null;
173
+ return formatDate(Number(match[1]), Number(match[2]), Number(match[3]));
174
+ }
175
+ function formatDate(year, month, day) {
176
+ if (month < 1 || month > 12 || day < 1 || day > 31) return null;
177
+ const paddedYear = year.toString().padStart(4, "0");
178
+ const paddedMonth = month.toString().padStart(2, "0");
179
+ const paddedDay = day.toString().padStart(2, "0");
180
+ return `${paddedYear}-${paddedMonth}-${paddedDay}`;
181
+ }
182
+ function compareDailyNotes(a, b) {
183
+ if (a.date !== b.date) {
184
+ if (a.date.length === 0) return 1;
185
+ if (b.date.length === 0) return -1;
186
+ return a.date < b.date ? 1 : -1;
187
+ }
188
+ if (a.slug === b.slug) return 0;
189
+ return a.slug < b.slug ? -1 : 1;
190
+ }
191
+ function stripHtml(html) {
192
+ return html.replace(/<[^>]*>/g, "");
193
+ }
194
+ function collapseWhitespace(text) {
195
+ return text.replace(/\s+/g, " ").trim();
196
+ }
197
+ function decodeHtmlEntities(text) {
198
+ return text.replace(
199
+ /&(#[xX]?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);/g,
200
+ (match, entity) => {
201
+ switch (entity) {
202
+ case "amp":
203
+ return "&";
204
+ case "lt":
205
+ return "<";
206
+ case "gt":
207
+ return ">";
208
+ case "quot":
209
+ return '"';
210
+ case "apos":
211
+ return "'";
212
+ case "nbsp":
213
+ return " ";
214
+ default:
215
+ return decodeNumericEntity(match, entity);
216
+ }
217
+ }
218
+ );
219
+ }
220
+ function decodeNumericEntity(match, entity) {
221
+ if (entity.startsWith("#x") || entity.startsWith("#X")) {
222
+ return fromCodePoint(match, Number.parseInt(entity.slice(2), 16));
223
+ }
224
+ if (entity.startsWith("#")) {
225
+ return fromCodePoint(match, Number.parseInt(entity.slice(1), 10));
226
+ }
227
+ return match;
228
+ }
229
+ function fromCodePoint(match, code) {
230
+ if (!Number.isInteger(code) || code < 0 || code > 1114111) return match;
231
+ return String.fromCodePoint(code);
232
+ }
233
+
234
+ // src/daily-notes.server.ts
235
+ function getDailyNotes(args) {
236
+ const options = args.options;
237
+ const extract = resolveExtractOptions(options);
238
+ const directory = options?.source?.directory ?? DEFAULT_DIRECTORY;
239
+ const pathPattern = options?.source?.pathPattern;
240
+ const limit = Math.max(0, options?.widget?.limit ?? DEFAULT_LIMIT2);
241
+ const notes = [];
242
+ for (const entry of args.manifest.entries) {
243
+ if (!isDailyNoteSlug(entry.slug, directory, pathPattern)) continue;
244
+ const snippet = extractDailyNoteSnippet(entry, extract);
245
+ if (snippet === null) continue;
246
+ const published = isPublished(args.config, entry.frontmatter);
247
+ notes.push({
248
+ date: resolveDailyNoteDate(entry),
249
+ snippet,
250
+ slug: entry.slug,
251
+ sourceUrl: published ? entry.permalink : null,
252
+ sourceTitle: published ? entry.title : null
253
+ });
254
+ }
255
+ return notes.toSorted(compareDailyNotes).slice(0, limit);
256
+ }
257
+
258
+ // index.ts
259
+ function dailyNotesPlugin(options) {
260
+ return definePlugin({
261
+ name: "daily-notes",
262
+ options,
263
+ cacheVersion: "1",
264
+ assets: [createStyleAsset("daily-notes")]
265
+ });
266
+ }
267
+ export {
268
+ DailyNotes,
269
+ dailyNotesPlugin,
270
+ getDailyNotes
271
+ };
@@ -0,0 +1,60 @@
1
+ import type { ContentManifestEntry } from "@riebeckite/core";
2
+ export type DailyNote = {
3
+ date: string;
4
+ snippet: string;
5
+ slug: string;
6
+ sourceUrl: string | null;
7
+ sourceTitle: string | null;
8
+ };
9
+ export type DailyNotesOptions = {
10
+ source?: {
11
+ /** Slug prefix that holds Daily Notes. Defaults to `"Daily"`. */
12
+ directory?: string;
13
+ /** Optional slug template (for example `"Daily/{YYYY}-{MM}-{DD}"`). */
14
+ pathPattern?: string;
15
+ };
16
+ extract?: {
17
+ /** Frontmatter key to read the snippet from. Defaults to `"daily-summary"`. */
18
+ frontmatter?: string | false;
19
+ /** Heading whose section becomes the snippet. Defaults to `"今日のひとこと"`. */
20
+ section?: string | false;
21
+ /** Code block language to read the snippet from. Defaults to `"daily-snippet"`. */
22
+ codeBlock?: string | false;
23
+ };
24
+ widget?: {
25
+ /** Maximum number of notes to surface. Defaults to `5`. */
26
+ limit?: number;
27
+ };
28
+ };
29
+ export type ResolvedDailyNotesExtract = {
30
+ frontmatter: string | false;
31
+ section: string | false;
32
+ codeBlock: string | false;
33
+ };
34
+ export declare const DEFAULT_DIRECTORY = "Daily";
35
+ export declare const DEFAULT_FRONTMATTER_KEY = "daily-summary";
36
+ export declare const DEFAULT_SECTION = "\u4ECA\u65E5\u306E\u3072\u3068\u3053\u3068";
37
+ export declare const DEFAULT_CODE_BLOCK = "daily-snippet";
38
+ export declare const DEFAULT_LIMIT = 5;
39
+ export declare function resolveExtractOptions(options: DailyNotesOptions | undefined): ResolvedDailyNotesExtract;
40
+ /**
41
+ * Matches a manifest slug against the configured Daily Notes location. The
42
+ * directory is a fast prefix filter; `pathPattern` refines it when present.
43
+ */
44
+ export declare function isDailyNoteSlug(slug: string, directory: string, pathPattern?: string): boolean;
45
+ export declare function matchesSlugPattern(slug: string, pattern: string): boolean;
46
+ /**
47
+ * Extracts exactly one snippet using the first successful strategy. Returns
48
+ * `null` when every strategy fails; callers must skip the note rather than
49
+ * fall back to the whole note body.
50
+ */
51
+ export declare function extractDailyNoteSnippet(entry: ContentManifestEntry, extract: ResolvedDailyNotesExtract): string | null;
52
+ export declare function extractSectionSnippet(html: string, section: string): string | null;
53
+ export declare function extractCodeBlockSnippet(html: string, language: string): string | null;
54
+ /**
55
+ * Derives the note date deterministically: frontmatter `date`, then `created`,
56
+ * then a `YYYY-MM-DD` sequence in the slug. Never reads the clock.
57
+ */
58
+ export declare function resolveDailyNoteDate(entry: ContentManifestEntry): string;
59
+ /** Newest first, then slug ascending. Notes without a date sort last. */
60
+ export declare function compareDailyNotes(a: DailyNote, b: DailyNote): number;
@@ -0,0 +1,15 @@
1
+ import { type ContentManifest, type ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import { type DailyNote, type DailyNotesOptions } from "./daily-notes.js";
3
+ /**
4
+ * Builds the widget view of the Daily Notes collection.
5
+ *
6
+ * Reads `manifest.entries` (the raw view) on purpose: a private note may opt
7
+ * in a snippet. Only `sourceUrl` / `sourceTitle` are gated by `isPublished`,
8
+ * so an unpublished note never leaks its permalink or title. The note body is
9
+ * never emitted wholesale — a note without a valid snippet is skipped.
10
+ */
11
+ export declare function getDailyNotes(args: {
12
+ manifest: ContentManifest;
13
+ config: ResolvedRiebeckiteConfig;
14
+ options?: DailyNotesOptions;
15
+ }): DailyNote[];
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@riebeckite/plugin-daily-notes",
3
+ "version": "0.0.1",
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
+ "./components": {
16
+ "types": "./dist/components/daily-notes.d.ts",
17
+ "import": "./dist/components/daily-notes.js",
18
+ "source": "./components/daily-notes.tsx",
19
+ "default": "./dist/components/daily-notes.js"
20
+ },
21
+ "./style.css": "./style.css"
22
+ },
23
+ "dependencies": {
24
+ "hono": "^4.12.25",
25
+ "@riebeckite/core": "0.0.1"
26
+ },
27
+ "devDependencies": {
28
+ "tsx": "^4.22.4"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "files": [
34
+ "LICENSE",
35
+ "README.md",
36
+ "README_ja.md",
37
+ "dist",
38
+ "style.css"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/Rerurate514/riebeckite.git",
43
+ "directory": "packages/plugins/daily-notes"
44
+ },
45
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
46
+ "bugs": {
47
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
48
+ },
49
+ "description": "Daily Note snippet widgets for Riebeckite sites.",
50
+ "keywords": [
51
+ "riebeckite",
52
+ "plugin",
53
+ "daily-notes",
54
+ "obsidian"
55
+ ],
56
+ "engines": {
57
+ "node": "^20.19.0 || >=22.12.0"
58
+ },
59
+ "sideEffects": [
60
+ "./style.css"
61
+ ],
62
+ "scripts": {
63
+ "build": "node ../../../scripts/build_package.mjs",
64
+ "test": "node --import tsx --test \"test/*.test.ts\""
65
+ }
66
+ }
package/style.css ADDED
@@ -0,0 +1,77 @@
1
+ @layer components {
2
+ .daily-notes {
3
+ margin-top: 4rem;
4
+ padding-top: 1.5rem;
5
+ border-top: 1px solid color-mix(in srgb, currentColor 18%, transparent);
6
+ }
7
+
8
+ .daily-notes__header {
9
+ display: grid;
10
+ gap: 0.25rem;
11
+ margin-bottom: 1.25rem;
12
+ }
13
+
14
+ .daily-notes__eyebrow {
15
+ margin: 0;
16
+ font-size: 0.75rem;
17
+ font-weight: 700;
18
+ letter-spacing: 0.12em;
19
+ color: color-mix(in srgb, currentColor 54%, transparent);
20
+ }
21
+
22
+ .daily-notes__title {
23
+ margin: 0;
24
+ font-size: clamp(1.5rem, 4vw, 2rem);
25
+ line-height: 1.2;
26
+ letter-spacing: -0.02em;
27
+ }
28
+
29
+ .daily-notes__list {
30
+ display: grid;
31
+ gap: 1.25rem;
32
+ margin: 0;
33
+ padding: 0;
34
+ list-style: none;
35
+ }
36
+
37
+ .daily-notes__item {
38
+ margin: 0;
39
+ padding: 1rem 0 0;
40
+ border-top: 1px solid color-mix(in srgb, currentColor 14%, transparent);
41
+ }
42
+
43
+ .daily-notes__meta {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: 0.75rem;
47
+ align-items: baseline;
48
+ margin-bottom: 0.5rem;
49
+ }
50
+
51
+ .daily-notes__date {
52
+ font-size: 0.75rem;
53
+ font-weight: 700;
54
+ letter-spacing: 0.08em;
55
+ color: color-mix(in srgb, currentColor 62%, transparent);
56
+ }
57
+
58
+ .daily-notes__source {
59
+ font-size: 0.75rem;
60
+ color: var(--rb-color-accent, currentColor);
61
+ text-decoration: underline;
62
+ text-underline-offset: 0.2em;
63
+ }
64
+
65
+ .daily-notes__source:focus-visible {
66
+ outline: 2px solid var(--rb-color-accent, currentColor);
67
+ outline-offset: 3px;
68
+ }
69
+
70
+ .daily-notes__snippet {
71
+ margin: 0;
72
+ font-size: 1rem;
73
+ line-height: 1.75;
74
+ white-space: pre-wrap;
75
+ overflow-wrap: anywhere;
76
+ }
77
+ }