note-blog-kit 0.0.0-stage → 0.2.0
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 +21 -0
- package/README.md +340 -2
- package/dist/cli/index.js +32 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +1 -0
- package/dist/iterate-articles-9dzDflSn.d.ts +84 -0
- package/dist/iterate-articles-BeI9bBh3.d.cts +84 -0
- package/dist/next/index.cjs +378 -0
- package/dist/next/index.d.cts +103 -0
- package/dist/next/index.d.ts +103 -0
- package/dist/next/index.js +375 -0
- package/dist/react/index.cjs +409 -0
- package/dist/react/index.d.cts +190 -0
- package/dist/react/index.d.ts +190 -0
- package/dist/react/index.js +404 -0
- package/dist/server/index.cjs +626 -0
- package/dist/server/index.d.cts +109 -0
- package/dist/server/index.d.ts +109 -0
- package/dist/server/index.js +610 -0
- package/dist/styles.css +427 -0
- package/package.json +109 -3
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
|
|
5
|
+
// src/react/body/parse.ts
|
|
6
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
7
|
+
"p",
|
|
8
|
+
"br",
|
|
9
|
+
"h2",
|
|
10
|
+
"h3",
|
|
11
|
+
"h4",
|
|
12
|
+
"strong",
|
|
13
|
+
"em",
|
|
14
|
+
"s",
|
|
15
|
+
"a",
|
|
16
|
+
"ul",
|
|
17
|
+
"ol",
|
|
18
|
+
"li",
|
|
19
|
+
"blockquote",
|
|
20
|
+
"figure",
|
|
21
|
+
"figcaption",
|
|
22
|
+
"img",
|
|
23
|
+
"pre",
|
|
24
|
+
"code",
|
|
25
|
+
"hr",
|
|
26
|
+
"table",
|
|
27
|
+
"thead",
|
|
28
|
+
"tbody",
|
|
29
|
+
"tr",
|
|
30
|
+
"th",
|
|
31
|
+
"td",
|
|
32
|
+
"div"
|
|
33
|
+
]);
|
|
34
|
+
var DISCARD_TAGS = /* @__PURE__ */ new Set([
|
|
35
|
+
"script",
|
|
36
|
+
"style",
|
|
37
|
+
"iframe",
|
|
38
|
+
"frame",
|
|
39
|
+
"frameset",
|
|
40
|
+
"object",
|
|
41
|
+
"embed",
|
|
42
|
+
"applet",
|
|
43
|
+
"form",
|
|
44
|
+
"button",
|
|
45
|
+
"textarea",
|
|
46
|
+
"select",
|
|
47
|
+
"option",
|
|
48
|
+
"svg",
|
|
49
|
+
"math",
|
|
50
|
+
"template",
|
|
51
|
+
"noscript",
|
|
52
|
+
"title",
|
|
53
|
+
"xmp",
|
|
54
|
+
"plaintext",
|
|
55
|
+
"noembed",
|
|
56
|
+
"noframes"
|
|
57
|
+
]);
|
|
58
|
+
var VOID_TAGS = /* @__PURE__ */ new Set(["br", "hr", "img"]);
|
|
59
|
+
var NO_TEXT_TAGS = /* @__PURE__ */ new Set(["table", "thead", "tbody", "tr"]);
|
|
60
|
+
var CLOSES_P = /* @__PURE__ */ new Set(["p", "h2", "h3", "h4", "ul", "ol", "blockquote", "figure", "pre", "hr", "table", "div"]);
|
|
61
|
+
var MAX_DEPTH = 128;
|
|
62
|
+
var TOKEN_RE = /<!--[\s\S]*?(?:-->|$)|<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^\s=>/"'<]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>"'<]+))?)*)\s*\/?>|[^<]+|</g;
|
|
63
|
+
var ATTR_RE = /([^\s=>/"'<]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>"'<]+)))?/g;
|
|
64
|
+
var NAMED_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
|
|
65
|
+
function decodeEntities(text) {
|
|
66
|
+
return text.replace(/&(#x[0-9a-fA-F]{1,8}|#[0-9]{1,10}|[a-zA-Z]+);/g, (whole, name) => {
|
|
67
|
+
if (name[0] !== "#") return Object.hasOwn(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : whole;
|
|
68
|
+
const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number(name.slice(1));
|
|
69
|
+
const valid = code > 0 && code <= 1114111 && (code < 55296 || code > 57343);
|
|
70
|
+
return valid ? String.fromCodePoint(code) : "\uFFFD";
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function parseAttrs(source) {
|
|
74
|
+
const attrs = /* @__PURE__ */ Object.create(null);
|
|
75
|
+
for (const m of source.matchAll(ATTR_RE)) {
|
|
76
|
+
const name = m[1].toLowerCase();
|
|
77
|
+
if (!Object.hasOwn(attrs, name)) attrs[name] = decodeEntities(m[2] ?? m[3] ?? m[4] ?? "");
|
|
78
|
+
}
|
|
79
|
+
return attrs;
|
|
80
|
+
}
|
|
81
|
+
function parseBody(html) {
|
|
82
|
+
const root = { tag: "#root", attrs: /* @__PURE__ */ Object.create(null), children: [] };
|
|
83
|
+
const stack = [root];
|
|
84
|
+
const top = () => stack[stack.length - 1];
|
|
85
|
+
const closeTo = (tag) => {
|
|
86
|
+
for (let i = stack.length - 1; i > 0; i -= 1) {
|
|
87
|
+
if (stack[i].tag === tag) {
|
|
88
|
+
stack.length = i;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const append = (node) => {
|
|
94
|
+
if (typeof node === "string" && (NO_TEXT_TAGS.has(top().tag) || top().tag !== "pre" && node === "")) return;
|
|
95
|
+
top().children.push(node);
|
|
96
|
+
};
|
|
97
|
+
const lower = html.toLowerCase();
|
|
98
|
+
TOKEN_RE.lastIndex = 0;
|
|
99
|
+
for (let m = TOKEN_RE.exec(html); m !== null; m = TOKEN_RE.exec(html)) {
|
|
100
|
+
const [token, closing, rawName, rawAttrs] = m;
|
|
101
|
+
if (rawName === void 0) {
|
|
102
|
+
if (!token.startsWith("<!--")) append(decodeEntities(token));
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const tag = rawName.toLowerCase();
|
|
106
|
+
if (DISCARD_TAGS.has(tag)) {
|
|
107
|
+
if (!closing) {
|
|
108
|
+
const end = lower.indexOf(`</${tag}`, TOKEN_RE.lastIndex);
|
|
109
|
+
TOKEN_RE.lastIndex = end === -1 ? html.length : end;
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (!ALLOWED_TAGS.has(tag)) continue;
|
|
114
|
+
if (closing) {
|
|
115
|
+
closeTo(tag);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (CLOSES_P.has(tag)) closeTo("p");
|
|
119
|
+
if (tag === "a" && stack.some((el2) => el2.tag === "a")) closeTo("a");
|
|
120
|
+
if (stack.length > MAX_DEPTH) continue;
|
|
121
|
+
if (tag === "tr" && top().tag === "table") {
|
|
122
|
+
const tbody = { tag: "tbody", attrs: /* @__PURE__ */ Object.create(null), children: [] };
|
|
123
|
+
append(tbody);
|
|
124
|
+
stack.push(tbody);
|
|
125
|
+
}
|
|
126
|
+
const el = { tag, attrs: parseAttrs(rawAttrs ?? ""), children: [] };
|
|
127
|
+
append(el);
|
|
128
|
+
if (!VOID_TAGS.has(tag)) stack.push(el);
|
|
129
|
+
}
|
|
130
|
+
return root.children;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/react/class-names.ts
|
|
134
|
+
function classNames(...names) {
|
|
135
|
+
return names.filter((name) => typeof name === "string" && name !== "").join(" ");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/react/safe-url.ts
|
|
139
|
+
function safeHttpUrl(url) {
|
|
140
|
+
if (typeof url !== "string" || !/^https?:\/\//i.test(url)) return null;
|
|
141
|
+
for (let i = 0; i < url.length; i += 1) {
|
|
142
|
+
const code = url.charCodeAt(i);
|
|
143
|
+
if (code <= 32 || code === 127) return null;
|
|
144
|
+
}
|
|
145
|
+
return url;
|
|
146
|
+
}
|
|
147
|
+
var ID_RE = /^nbk-[A-Za-z0-9\-_.:/]+$/;
|
|
148
|
+
var SAFE_VALUE = /^[A-Za-z0-9\-_.:/]+$/;
|
|
149
|
+
var IMAGE_PREFIX = "https://assets.st-note.com/";
|
|
150
|
+
var DIGITS = /^\d+$/;
|
|
151
|
+
var REL_TOKENS = /* @__PURE__ */ new Set(["nofollow", "noopener", "noreferrer", "sponsored"]);
|
|
152
|
+
var BODY_CLASS = {
|
|
153
|
+
p: "nbk-body__p",
|
|
154
|
+
h2: "nbk-body__h2",
|
|
155
|
+
h3: "nbk-body__h3",
|
|
156
|
+
h4: "nbk-body__h4",
|
|
157
|
+
a: "nbk-body__a",
|
|
158
|
+
ul: "nbk-body__ul",
|
|
159
|
+
ol: "nbk-body__ol",
|
|
160
|
+
blockquote: "nbk-body__blockquote",
|
|
161
|
+
figure: "nbk-body__figure",
|
|
162
|
+
figcaption: "nbk-body__figcaption",
|
|
163
|
+
img: "nbk-body__img",
|
|
164
|
+
pre: "nbk-body__pre",
|
|
165
|
+
code: "nbk-body__code",
|
|
166
|
+
hr: "nbk-body__hr",
|
|
167
|
+
table: "nbk-body__table",
|
|
168
|
+
th: "nbk-body__th",
|
|
169
|
+
td: "nbk-body__td"
|
|
170
|
+
};
|
|
171
|
+
function toNumber(value) {
|
|
172
|
+
return value !== void 0 && DIGITS.test(value) ? Number(value) : void 0;
|
|
173
|
+
}
|
|
174
|
+
function safeHref(value) {
|
|
175
|
+
if (value === void 0) return null;
|
|
176
|
+
if (!/^mailto:[^\s"<>]+$/i.test(value)) return safeHttpUrl(value);
|
|
177
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
178
|
+
if (value.charCodeAt(i) < 32 || value.charCodeAt(i) === 127) return null;
|
|
179
|
+
}
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
function safeHttpsUrl(value) {
|
|
183
|
+
const url = safeHttpUrl(value);
|
|
184
|
+
return url !== null && /^https:\/\//i.test(url) ? url : null;
|
|
185
|
+
}
|
|
186
|
+
function safeImageUrl(value) {
|
|
187
|
+
const url = safeHttpsUrl(value);
|
|
188
|
+
return url?.toLowerCase().startsWith(IMAGE_PREFIX) ? url : null;
|
|
189
|
+
}
|
|
190
|
+
function collectIds(nodes, ids) {
|
|
191
|
+
for (const node of nodes) {
|
|
192
|
+
if (typeof node === "string") continue;
|
|
193
|
+
if (node.attrs.id !== void 0 && ID_RE.test(node.attrs.id)) ids.add(node.attrs.id);
|
|
194
|
+
collectIds(node.children, ids);
|
|
195
|
+
}
|
|
196
|
+
return ids;
|
|
197
|
+
}
|
|
198
|
+
function DefaultToc({ items, title, linkableIds }) {
|
|
199
|
+
if (items.length === 0) return null;
|
|
200
|
+
const ids = new Set(linkableIds);
|
|
201
|
+
const seen = /* @__PURE__ */ new Map();
|
|
202
|
+
const keyOf = (id) => {
|
|
203
|
+
const count = seen.get(id) ?? 0;
|
|
204
|
+
seen.set(id, count + 1);
|
|
205
|
+
return count === 0 ? id : `${id}:${count}`;
|
|
206
|
+
};
|
|
207
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "nbk-toc", children: [
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-toc__title", children: title }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "nbk-toc__list", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
210
|
+
"li",
|
|
211
|
+
{
|
|
212
|
+
className: item.level === 2 ? "nbk-toc__item nbk-toc__item--h2" : "nbk-toc__item nbk-toc__item--h3",
|
|
213
|
+
children: ids.has(item.id) ? /* @__PURE__ */ jsxRuntime.jsx("a", { className: "nbk-toc__link", href: `#${item.id}`, children: item.text }) : item.text
|
|
214
|
+
},
|
|
215
|
+
keyOf(item.id)
|
|
216
|
+
)) })
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
function renderChildren(nodes, ctx) {
|
|
220
|
+
return nodes.map((node, index) => renderNode(node, ctx, index));
|
|
221
|
+
}
|
|
222
|
+
function renderEmbed(el, ctx, key) {
|
|
223
|
+
const service = el.attrs["data-nbk-embed-service"];
|
|
224
|
+
const embedKey = el.attrs["data-nbk-embed-key"];
|
|
225
|
+
const found = ctx.article.embeds.find((item) => item.key === embedKey);
|
|
226
|
+
const embed = found !== void 0 && safeHttpsUrl(found.url) !== null && SAFE_VALUE.test(found.service) ? found : null;
|
|
227
|
+
const children = renderChildren(el.children, { ...ctx, inEmbed: true });
|
|
228
|
+
const { embed: Embed } = ctx.components;
|
|
229
|
+
if (Embed) {
|
|
230
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Embed, { embed, service, children }, key);
|
|
231
|
+
}
|
|
232
|
+
const url = service === "note" ? safeHttpsUrl(embed?.url ?? el.attrs["data-nbk-embed-url"]) : null;
|
|
233
|
+
const { Link } = ctx;
|
|
234
|
+
return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "nbk-embed", "data-service": service, children: url === null ? children : /* @__PURE__ */ jsxRuntime.jsx(Link, { href: url, className: "nbk-embed__link", children: url }) }, key);
|
|
235
|
+
}
|
|
236
|
+
function renderNode(node, ctx, key) {
|
|
237
|
+
if (typeof node === "string") return node;
|
|
238
|
+
const { tag, attrs } = node;
|
|
239
|
+
const id = attrs.id !== void 0 && ID_RE.test(attrs.id) ? attrs.id : void 0;
|
|
240
|
+
if (tag === "div") {
|
|
241
|
+
if (!Object.hasOwn(attrs, "data-nbk-toc")) return renderChildren(node.children, ctx);
|
|
242
|
+
const Toc = ctx.components.toc ?? DefaultToc;
|
|
243
|
+
const linkableIds = ctx.article.toc.filter((item) => ctx.ids.has(item.id)).map((item) => item.id);
|
|
244
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Toc, { items: ctx.article.toc, linkableIds, title: ctx.tocTitle }, key);
|
|
245
|
+
}
|
|
246
|
+
const service = attrs["data-nbk-embed-service"];
|
|
247
|
+
if (tag === "figure" && service !== void 0 && SAFE_VALUE.test(service)) return renderEmbed(node, ctx, key);
|
|
248
|
+
if (tag === "img") {
|
|
249
|
+
const src = safeImageUrl(attrs.src);
|
|
250
|
+
if (src === null) return null;
|
|
251
|
+
const props2 = { src, alt: attrs.alt ?? "" };
|
|
252
|
+
const width = toNumber(attrs.width);
|
|
253
|
+
const height = toNumber(attrs.height);
|
|
254
|
+
if (width !== void 0) props2.width = width;
|
|
255
|
+
if (height !== void 0) props2.height = height;
|
|
256
|
+
const { img: Img } = ctx.components;
|
|
257
|
+
return Img ? /* @__PURE__ */ jsxRuntime.jsx(Img, { ...props2 }, key) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
258
|
+
"img",
|
|
259
|
+
{
|
|
260
|
+
className: BODY_CLASS.img,
|
|
261
|
+
src: props2.src,
|
|
262
|
+
alt: props2.alt,
|
|
263
|
+
width: props2.width,
|
|
264
|
+
height: props2.height,
|
|
265
|
+
loading: "lazy",
|
|
266
|
+
decoding: "async"
|
|
267
|
+
},
|
|
268
|
+
key
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const children = renderChildren(node.children, ctx);
|
|
272
|
+
if (tag === "h2" || tag === "h3" || tag === "h4") {
|
|
273
|
+
const { heading: Heading } = ctx.components;
|
|
274
|
+
if (Heading) {
|
|
275
|
+
const level = Number(tag[1]);
|
|
276
|
+
return id === void 0 ? /* @__PURE__ */ jsxRuntime.jsx(Heading, { level, children }, key) : /* @__PURE__ */ jsxRuntime.jsx(Heading, { level, id, children }, key);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const props = {};
|
|
280
|
+
if (BODY_CLASS[tag] !== void 0) props.className = BODY_CLASS[tag];
|
|
281
|
+
if (id !== void 0) props.id = id;
|
|
282
|
+
if (tag === "a") {
|
|
283
|
+
if (ctx.inEmbed) props.className = "nbk-embed__link";
|
|
284
|
+
const href = safeHref(attrs.href);
|
|
285
|
+
if (href !== null) props.href = href;
|
|
286
|
+
if (attrs.target === "_blank") props.target = "_blank";
|
|
287
|
+
const rel = (attrs.rel ?? "").split(/\s+/).filter((token) => REL_TOKENS.has(token));
|
|
288
|
+
if (props.target !== void 0) {
|
|
289
|
+
rel.push(...["nofollow", "noopener", "noreferrer"].filter((token) => !rel.includes(token)));
|
|
290
|
+
}
|
|
291
|
+
if (rel.length > 0) props.rel = rel.join(" ");
|
|
292
|
+
} else if (tag === "th" || tag === "td") {
|
|
293
|
+
const colSpan = toNumber(attrs.colspan);
|
|
294
|
+
const rowSpan = toNumber(attrs.rowspan);
|
|
295
|
+
if (colSpan !== void 0) props.colSpan = colSpan;
|
|
296
|
+
if (rowSpan !== void 0) props.rowSpan = rowSpan;
|
|
297
|
+
}
|
|
298
|
+
const Tag = tag;
|
|
299
|
+
if (tag === "br" || tag === "hr") return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...props }, key);
|
|
300
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { ...props, children }, key);
|
|
301
|
+
}
|
|
302
|
+
function NoteArticleBody({
|
|
303
|
+
article,
|
|
304
|
+
components = {},
|
|
305
|
+
readMoreHref,
|
|
306
|
+
linkComponent: Link = "a",
|
|
307
|
+
labels,
|
|
308
|
+
className
|
|
309
|
+
}) {
|
|
310
|
+
const nodes = parseBody(article.bodyHtml);
|
|
311
|
+
const ctx = {
|
|
312
|
+
article,
|
|
313
|
+
components,
|
|
314
|
+
Link,
|
|
315
|
+
tocTitle: labels?.toc ?? "\u76EE\u6B21",
|
|
316
|
+
ids: collectIds(nodes, /* @__PURE__ */ new Set())
|
|
317
|
+
};
|
|
318
|
+
const moreHref = article.isPartial ? readMoreHref ?? safeHttpUrl(article.url) : null;
|
|
319
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames("nbk-body", className), children: [
|
|
320
|
+
renderChildren(nodes, ctx),
|
|
321
|
+
moreHref !== null && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-body__more", children: /* @__PURE__ */ jsxRuntime.jsx(Link, { href: moreHref, className: "nbk-body__more-link", children: labels?.readMore ?? "\u7D9A\u304D\u306F note \u3067" }) })
|
|
322
|
+
] });
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/react/format-date.ts
|
|
326
|
+
var formatter = new Intl.DateTimeFormat("ja-JP", {
|
|
327
|
+
timeZone: "Asia/Tokyo",
|
|
328
|
+
year: "numeric",
|
|
329
|
+
month: "2-digit",
|
|
330
|
+
day: "2-digit"
|
|
331
|
+
});
|
|
332
|
+
function formatNoteDate(iso) {
|
|
333
|
+
const date = new Date(iso);
|
|
334
|
+
return Number.isNaN(date.getTime()) ? iso : formatter.format(date);
|
|
335
|
+
}
|
|
336
|
+
function NoteArticleCard({
|
|
337
|
+
article,
|
|
338
|
+
href,
|
|
339
|
+
linkComponent: Link = "a",
|
|
340
|
+
formatDate = formatNoteDate,
|
|
341
|
+
headingLevel = 2,
|
|
342
|
+
labels,
|
|
343
|
+
className
|
|
344
|
+
}) {
|
|
345
|
+
const Heading = `h${headingLevel}`;
|
|
346
|
+
const linkHref = href ?? safeHttpUrl(article.url);
|
|
347
|
+
const eyecatchUrl = safeHttpUrl(article.eyecatchUrl);
|
|
348
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("article", { className: classNames("nbk-card", className), children: [
|
|
349
|
+
eyecatchUrl !== null && /* @__PURE__ */ jsxRuntime.jsx("img", { className: "nbk-card__eyecatch", src: eyecatchUrl, alt: "", loading: "lazy", decoding: "async" }),
|
|
350
|
+
/* @__PURE__ */ jsxRuntime.jsx(Heading, { className: "nbk-card__title", children: linkHref === null ? article.title : /* @__PURE__ */ jsxRuntime.jsx(Link, { href: linkHref, className: "nbk-card__link", children: article.title }) }),
|
|
351
|
+
/* @__PURE__ */ jsxRuntime.jsx("time", { className: "nbk-card__date", dateTime: article.publishedAt, children: formatDate(article.publishedAt) }),
|
|
352
|
+
article.price !== null && article.price > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "nbk-card__badge", children: labels?.paid ?? "\u6709\u6599" }),
|
|
353
|
+
article.excerpt !== "" && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-card__excerpt", children: article.excerpt }),
|
|
354
|
+
article.hashtags.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "nbk-card__tags", children: article.hashtags.map((tag) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "nbk-card__tag", children: [
|
|
355
|
+
"#",
|
|
356
|
+
tag
|
|
357
|
+
] }, tag)) })
|
|
358
|
+
] });
|
|
359
|
+
}
|
|
360
|
+
function NoteArticleList({
|
|
361
|
+
articles,
|
|
362
|
+
getHref,
|
|
363
|
+
linkComponent,
|
|
364
|
+
formatDate,
|
|
365
|
+
headingLevel,
|
|
366
|
+
renderItem,
|
|
367
|
+
empty = "\u8A18\u4E8B\u304C\u3042\u308A\u307E\u305B\u3093",
|
|
368
|
+
className
|
|
369
|
+
}) {
|
|
370
|
+
if (articles.length === 0) {
|
|
371
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: classNames("nbk-article-list", "nbk-article-list--empty", className), children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "nbk-article-list__empty", children: empty }) });
|
|
372
|
+
}
|
|
373
|
+
const cardProps = {
|
|
374
|
+
...linkComponent !== void 0 && { linkComponent },
|
|
375
|
+
...formatDate !== void 0 && { formatDate },
|
|
376
|
+
...headingLevel !== void 0 && { headingLevel }
|
|
377
|
+
};
|
|
378
|
+
return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: classNames("nbk-article-list", className), children: articles.map((article) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "nbk-article-list__item", children: renderItem !== void 0 ? renderItem(article) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
379
|
+
NoteArticleCard,
|
|
380
|
+
{
|
|
381
|
+
article,
|
|
382
|
+
...getHref !== void 0 && { href: getHref(article) },
|
|
383
|
+
...cardProps
|
|
384
|
+
}
|
|
385
|
+
) }, article.key)) });
|
|
386
|
+
}
|
|
387
|
+
var NOTE_PER_PAGE = 6;
|
|
388
|
+
function NotePagination({
|
|
389
|
+
page,
|
|
390
|
+
isLastPage,
|
|
391
|
+
totalCount = null,
|
|
392
|
+
perPage = NOTE_PER_PAGE,
|
|
393
|
+
getHref,
|
|
394
|
+
linkComponent: Link = "a",
|
|
395
|
+
labels,
|
|
396
|
+
className
|
|
397
|
+
}) {
|
|
398
|
+
const totalPages = totalCount !== null && perPage > 0 ? Math.max(1, Math.ceil(totalCount / perPage)) : null;
|
|
399
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: classNames("nbk-pagination", className), "aria-label": labels?.navigation ?? "\u30DA\u30FC\u30B8\u9001\u308A", children: [
|
|
400
|
+
page > 1 && /* @__PURE__ */ jsxRuntime.jsx(Link, { href: getHref(page - 1), className: "nbk-pagination__prev", children: labels?.previous ?? "\u524D\u3078" }),
|
|
401
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "nbk-pagination__status", "aria-current": "page", children: totalPages === null ? `${page}` : `${page} / ${totalPages}` }),
|
|
402
|
+
!isLastPage && /* @__PURE__ */ jsxRuntime.jsx(Link, { href: getHref(page + 1), className: "nbk-pagination__next", children: labels?.next ?? "\u6B21\u3078" })
|
|
403
|
+
] });
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
exports.NoteArticleBody = NoteArticleBody;
|
|
407
|
+
exports.NoteArticleCard = NoteArticleCard;
|
|
408
|
+
exports.NoteArticleList = NoteArticleList;
|
|
409
|
+
exports.NotePagination = NotePagination;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { NoteArticle, NoteEmbed, NoteTocItem, NoteArticleSummary } from '../index.cjs';
|
|
2
|
+
export { NoteArticlePage, NoteAuthor, NoteEyecatch, NoteSource } from '../index.cjs';
|
|
3
|
+
import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* リンクに使う要素。既定は `'a'`。
|
|
7
|
+
* `href`(文字列)・`className`・`children` を受け取るコンポーネント(Next.js の `Link` など)をそのまま渡せる。
|
|
8
|
+
*
|
|
9
|
+
* Next.js の typedRoutes を有効にしている場合は `Link` の `href` が文字列を受け付けないため、
|
|
10
|
+
* `({ href, ...props }) => <Link href={href as Route} {...props} />` のように包んだコンポーネントを渡す。
|
|
11
|
+
*/
|
|
12
|
+
type NoteLinkComponent = ElementType<{
|
|
13
|
+
href: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}>;
|
|
17
|
+
/** 見出しのレベル(`h2`〜`h6`) */
|
|
18
|
+
type NoteHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
19
|
+
|
|
20
|
+
/** 本文の画像を置き換えるコンポーネントの props */
|
|
21
|
+
interface NoteBodyImageProps {
|
|
22
|
+
/** 画像 URL(note の CDN の https の URL だけが渡される) */
|
|
23
|
+
src: string;
|
|
24
|
+
/** 代替テキスト(空文字は装飾画像) */
|
|
25
|
+
alt: string;
|
|
26
|
+
/** 幅(px)。本文の値が数字だけのときに渡る */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** 高さ(px)。本文の値が数字だけのときに渡る */
|
|
29
|
+
height?: number;
|
|
30
|
+
}
|
|
31
|
+
/** 本文の見出しを置き換えるコンポーネントの props */
|
|
32
|
+
interface NoteBodyHeadingProps {
|
|
33
|
+
/** 見出しのレベル(本文に出るのは h2〜h4。{@link NoteHeadingLevel} とは別) */
|
|
34
|
+
level: 2 | 3 | 4;
|
|
35
|
+
/** 目次のリンク先になる id(nbk- から始まる) */
|
|
36
|
+
id?: string;
|
|
37
|
+
/** 見出しの中身 */
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/** 本文の埋め込みを置き換えるコンポーネントの props */
|
|
41
|
+
interface NoteBodyEmbedProps {
|
|
42
|
+
/** `article.embeds` の中で key が一致するもの。見つからないとき、URL が https でないとき、種類に許可しない文字があるときは null */
|
|
43
|
+
embed: NoteEmbed | null;
|
|
44
|
+
/** 埋め込みの種類(`note`・`external-article` など) */
|
|
45
|
+
service: NoteEmbed['service'];
|
|
46
|
+
/** 既定の中身(外部記事ならリンクカード。note の埋め込みは空) */
|
|
47
|
+
children?: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
/** 目次(本文中の目次の位置)を置き換えるコンポーネントの props */
|
|
50
|
+
interface NoteBodyTocProps {
|
|
51
|
+
/** `article.toc`(有料記事では有料部分の見出しも含む) */
|
|
52
|
+
items: NoteTocItem[];
|
|
53
|
+
/** 本文に見出しがある項目の id(ページ内リンクにできるもの) */
|
|
54
|
+
linkableIds: string[];
|
|
55
|
+
/** 見出しの文言(`labels.toc`、既定は「目次」) */
|
|
56
|
+
title: ReactNode;
|
|
57
|
+
}
|
|
58
|
+
/** {@link NoteArticleBody} で置き換えられる要素 */
|
|
59
|
+
interface NoteBodyComponents {
|
|
60
|
+
/** 画像。置き換えると既定のクラス名と遅延読み込み(loading・decoding)は付かない */
|
|
61
|
+
img?: ComponentType<NoteBodyImageProps>;
|
|
62
|
+
/** 見出し(h2〜h4)。置き換えると既定のクラス名は付かない */
|
|
63
|
+
heading?: ComponentType<NoteBodyHeadingProps>;
|
|
64
|
+
/** 埋め込み(note の記事・外部記事など) */
|
|
65
|
+
embed?: ComponentType<NoteBodyEmbedProps>;
|
|
66
|
+
/** 本文中の目次の位置に出すもの */
|
|
67
|
+
toc?: ComponentType<NoteBodyTocProps>;
|
|
68
|
+
}
|
|
69
|
+
/** {@link NoteArticleBody} の props */
|
|
70
|
+
interface NoteArticleBodyProps {
|
|
71
|
+
/** 表示する記事(`getArticle` で取得したもの) */
|
|
72
|
+
article: NoteArticle;
|
|
73
|
+
/** 本文の要素を任意のコンポーネントに置き換える */
|
|
74
|
+
components?: NoteBodyComponents;
|
|
75
|
+
/**
|
|
76
|
+
* 「続きは note で」のリンク先。既定は `article.url`(http(s) でなければ出さない)。`isPartial` でなければ使わない。
|
|
77
|
+
* 利用者が渡す値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を渡さないこと。
|
|
78
|
+
* React 18 はこうした値をブロックしない
|
|
79
|
+
*/
|
|
80
|
+
readMoreHref?: string;
|
|
81
|
+
/** 「続きは note で」と note の埋め込みのリンクに使う要素。既定は `'a'` */
|
|
82
|
+
linkComponent?: NoteLinkComponent;
|
|
83
|
+
/** 文言の差し替え。既定は「続きは note で」「目次」 */
|
|
84
|
+
labels?: {
|
|
85
|
+
readMore?: ReactNode;
|
|
86
|
+
toc?: ReactNode;
|
|
87
|
+
};
|
|
88
|
+
/** 既定のクラス名(`nbk-body`)に追加するクラス名 */
|
|
89
|
+
className?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 記事の本文。`getArticle` が返すサニタイズ済みの `bodyHtml` を React 要素として描画する
|
|
93
|
+
* (`dangerouslySetInnerHTML` は使わず、ここでも許可したタグ・属性だけを描画する)。
|
|
94
|
+
* 有料記事(`isPartial`)では、本文の後に「続きは note で」リンクを出す。
|
|
95
|
+
* 見た目は持たず、`nbk-body` から始まるクラス名を付ける。フックを使わないため、Server Component としても使える。
|
|
96
|
+
*/
|
|
97
|
+
declare function NoteArticleBody({ article, components, readMoreHref, linkComponent: Link, labels, className, }: NoteArticleBodyProps): ReactElement;
|
|
98
|
+
|
|
99
|
+
/** {@link NoteArticleCard} の props */
|
|
100
|
+
interface NoteArticleCardProps {
|
|
101
|
+
/** 表示する記事(`listArticles` などで取得したもの) */
|
|
102
|
+
article: NoteArticleSummary;
|
|
103
|
+
/**
|
|
104
|
+
* リンク先。既定は `article.url`(note の記事 URL。http(s) でなければリンクにしない)。
|
|
105
|
+
* 利用者が渡す値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を渡さないこと。
|
|
106
|
+
* React 18 はこうした値をブロックしない。
|
|
107
|
+
*/
|
|
108
|
+
href?: string;
|
|
109
|
+
/** リンクに使う要素。既定は `'a'` */
|
|
110
|
+
linkComponent?: NoteLinkComponent;
|
|
111
|
+
/** 日付の表示。既定は Asia/Tokyo の `YYYY/MM/DD` */
|
|
112
|
+
formatDate?: (iso: string) => string;
|
|
113
|
+
/** タイトルの見出しレベル。既定は 2(`h2`)。一覧を `h2` の節の中に置くなら 3 にする */
|
|
114
|
+
headingLevel?: NoteHeadingLevel;
|
|
115
|
+
/** 文言の差し替え。既定は「有料」 */
|
|
116
|
+
labels?: {
|
|
117
|
+
paid?: ReactNode;
|
|
118
|
+
};
|
|
119
|
+
/** 既定のクラス名(`nbk-card`)に追加するクラス名 */
|
|
120
|
+
className?: string;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 記事1件のカード。見た目は持たず、`nbk-card` から始まるクラス名を付ける。
|
|
124
|
+
* フックを使わないため、Server Component としても使える。
|
|
125
|
+
*/
|
|
126
|
+
declare function NoteArticleCard({ article, href, linkComponent: Link, formatDate, headingLevel, labels, className, }: NoteArticleCardProps): ReactElement;
|
|
127
|
+
|
|
128
|
+
/** {@link NoteArticleList} の props */
|
|
129
|
+
interface NoteArticleListProps {
|
|
130
|
+
/** 表示する記事の一覧(`listArticles` の `articles` など) */
|
|
131
|
+
articles: readonly NoteArticleSummary[];
|
|
132
|
+
/**
|
|
133
|
+
* 各記事のリンク先。既定は `article.url`(note の記事 URL)。
|
|
134
|
+
* 戻り値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を返さないこと。
|
|
135
|
+
*/
|
|
136
|
+
getHref?: (article: NoteArticleSummary) => string;
|
|
137
|
+
/** リンクに使う要素。既定は `'a'` */
|
|
138
|
+
linkComponent?: NoteLinkComponent;
|
|
139
|
+
/** 日付の表示。既定は Asia/Tokyo の `YYYY/MM/DD` */
|
|
140
|
+
formatDate?: (iso: string) => string;
|
|
141
|
+
/** 各カードのタイトルの見出しレベル。既定は 2 */
|
|
142
|
+
headingLevel?: NoteHeadingLevel;
|
|
143
|
+
/** 各記事の描画を丸ごと差し替える。既定は {@link NoteArticleCard} */
|
|
144
|
+
renderItem?: (article: NoteArticleSummary) => ReactNode;
|
|
145
|
+
/** 記事が0件のときの表示。既定は「記事がありません」 */
|
|
146
|
+
empty?: ReactNode;
|
|
147
|
+
/** 既定のクラス名(`nbk-article-list`)に追加するクラス名。0件のときも同じ要素に付く */
|
|
148
|
+
className?: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 記事の一覧。見た目は持たず、`nbk-article-list` から始まるクラス名を付ける。
|
|
152
|
+
* 記事があれば `ul.nbk-article-list`、0件なら `div.nbk-article-list.nbk-article-list--empty` を出す。
|
|
153
|
+
* フックを使わないため、Server Component としても使える。
|
|
154
|
+
*/
|
|
155
|
+
declare function NoteArticleList({ articles, getHref, linkComponent, formatDate, headingLevel, renderItem, empty, className, }: NoteArticleListProps): ReactElement;
|
|
156
|
+
|
|
157
|
+
/** {@link NotePagination} の props */
|
|
158
|
+
interface NotePaginationProps {
|
|
159
|
+
/** 現在のページ(1 始まり) */
|
|
160
|
+
page: number;
|
|
161
|
+
/** 最終ページかどうか(`listArticles` の戻り値の `isLastPage`) */
|
|
162
|
+
isLastPage: boolean;
|
|
163
|
+
/** 総件数。分かれば「3 / 40」のように総ページ数も表示する。RSS では null */
|
|
164
|
+
totalCount?: number | null;
|
|
165
|
+
/** 1ページの件数。総ページ数の計算に使う。既定は 6(note の一覧 API の件数) */
|
|
166
|
+
perPage?: number;
|
|
167
|
+
/**
|
|
168
|
+
* ページ番号からリンク先を作る。
|
|
169
|
+
* 戻り値はそのまま `href` に入るため、信頼できない値(`javascript:` など)を返さないこと。
|
|
170
|
+
*/
|
|
171
|
+
getHref: (page: number) => string;
|
|
172
|
+
/** リンクに使う要素。既定は `'a'` */
|
|
173
|
+
linkComponent?: NoteLinkComponent;
|
|
174
|
+
/** 文言の差し替え。既定は「前へ」「次へ」、nav の aria-label は「ページ送り」 */
|
|
175
|
+
labels?: {
|
|
176
|
+
previous?: ReactNode;
|
|
177
|
+
next?: ReactNode;
|
|
178
|
+
navigation?: string;
|
|
179
|
+
};
|
|
180
|
+
/** 既定のクラス名(`nbk-pagination`)に追加するクラス名 */
|
|
181
|
+
className?: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 前後のページへのリンク。見た目は持たず、`nbk-pagination` から始まるクラス名を付ける。
|
|
185
|
+
* フックを使わないため、Server Component としても使える。
|
|
186
|
+
*/
|
|
187
|
+
declare function NotePagination({ page, isLastPage, totalCount, perPage, getHref, linkComponent: Link, labels, className, }: NotePaginationProps): ReactElement;
|
|
188
|
+
|
|
189
|
+
export { NoteArticle, NoteArticleBody, NoteArticleCard, NoteArticleList, NoteArticleSummary, NoteEmbed, NotePagination, NoteTocItem };
|
|
190
|
+
export type { NoteArticleBodyProps, NoteArticleCardProps, NoteArticleListProps, NoteBodyComponents, NoteBodyEmbedProps, NoteBodyHeadingProps, NoteBodyImageProps, NoteBodyTocProps, NoteHeadingLevel, NoteLinkComponent, NotePaginationProps };
|