@mdsvex/plugin-page-data 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +162 -208
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ and this one are the excerpt.
|
|
|
114
114
|
This one is not.
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
- **It is plain text.** A parse plugin sees the document before it is rendered, so there is no HTML to give. Emphasis, links and code are their text, a character reference such as `&` is its character, and the lines of a paragraph are joined with a space. For a rendered excerpt, render the start of the document in the template instead.
|
|
117
|
+
- **It is plain text.** A parse plugin sees the document before it is rendered, so there is no HTML to give. Emphasis, links and code are their text, a character reference such as `&` is its character, and the lines of a paragraph are joined with a space. With the `smart_punctuation` option of mdsvex on, the quotes, dashes and ellipses are the ones the page shows. For a rendered excerpt, render the start of the document in the template instead.
|
|
118
118
|
- **The first paragraph** is the first one with text that is not inside a block quote, a list, a table, a footnote, a container directive or a Svelte block. A paragraph that only holds an image, a component or an expression is passed over.
|
|
119
119
|
- **Before `<!-- more -->`** it is every block of prose, joined with spaces. Headings, code blocks, tables and footnotes are left out. The comment can be on a line of its own or inside a paragraph, which is then cut there. Only the first one counts.
|
|
120
120
|
- **`max_length`** is the most characters the excerpt has. A longer one is cut where a word ends and gets the `ellipsis`, which counts toward the length. Text with no spaces, such as Japanese, is cut between two characters.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function v() {
|
|
2
2
|
var t;
|
|
3
3
|
const e = (t = globalThis.process) == null ? void 0 : t.versions;
|
|
4
4
|
return typeof (e == null ? void 0 : e.node) == "string";
|
|
@@ -6,226 +6,180 @@ function I() {
|
|
|
6
6
|
function D(e, t) {
|
|
7
7
|
if (e === void 0)
|
|
8
8
|
return;
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
9
|
+
const i = e instanceof Date ? e : typeof e == "string" ? new Date(e) : void 0;
|
|
10
|
+
if (i === void 0 || Number.isNaN(i.getTime()))
|
|
11
11
|
throw t("option", `last_modified must give a date, a string a Date can read or undefined, it gave ${e instanceof Date ? "an invalid Date" : JSON.stringify(e)}`);
|
|
12
|
-
return
|
|
12
|
+
return i.toISOString();
|
|
13
13
|
}
|
|
14
|
-
async function
|
|
15
|
-
const [e, t,
|
|
14
|
+
async function O() {
|
|
15
|
+
const [e, t, i] = await Promise.all([
|
|
16
16
|
import("node:child_process"),
|
|
17
17
|
import("node:fs/promises"),
|
|
18
18
|
import("node:path")
|
|
19
19
|
]);
|
|
20
|
-
return { child_process: e, fs: t, path:
|
|
20
|
+
return { child_process: e, fs: t, path: i };
|
|
21
21
|
}
|
|
22
|
-
async function
|
|
22
|
+
async function I(e, t) {
|
|
23
23
|
try {
|
|
24
24
|
return await e.fs.realpath(t);
|
|
25
|
-
} catch (
|
|
26
|
-
if (
|
|
25
|
+
} catch (i) {
|
|
26
|
+
if (i.code === "ENOENT")
|
|
27
27
|
return;
|
|
28
|
-
throw
|
|
28
|
+
throw i;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
class
|
|
32
|
-
constructor(t,
|
|
33
|
-
super(
|
|
31
|
+
class J extends Error {
|
|
32
|
+
constructor(t, i) {
|
|
33
|
+
super(i), this.status = t, this.stderr = i;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
return new Promise((
|
|
38
|
-
const
|
|
36
|
+
function b(e, t, i) {
|
|
37
|
+
return new Promise((n, s) => {
|
|
38
|
+
const r = e.child_process.spawn("git", i, {
|
|
39
39
|
cwd: t,
|
|
40
40
|
stdio: ["ignore", "pipe", "pipe"]
|
|
41
41
|
});
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
let a = "", d = "";
|
|
43
|
+
r.stdout.setEncoding("utf8"), r.stderr.setEncoding("utf8"), r.stdout.on("data", (c) => a += c), r.stderr.on("data", (c) => d += c), r.on("error", s), r.on("close", (c) => {
|
|
44
|
+
c === 0 ? n(a) : s(new J(c, d.trim()));
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
const
|
|
49
|
-
async function
|
|
50
|
-
const
|
|
51
|
-
if (await
|
|
48
|
+
const k = "";
|
|
49
|
+
async function j(e, t, i) {
|
|
50
|
+
const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
|
|
51
|
+
if (await b(e, t, [
|
|
52
52
|
"rev-parse",
|
|
53
53
|
"-q",
|
|
54
54
|
"--verify",
|
|
55
55
|
"HEAD"
|
|
56
56
|
]).then(() => !1, () => !0))
|
|
57
|
-
return { dates:
|
|
58
|
-
const [
|
|
59
|
-
|
|
57
|
+
return { dates: n, cut: s };
|
|
58
|
+
const [a, d] = await Promise.all([
|
|
59
|
+
b(e, t, [
|
|
60
60
|
"log",
|
|
61
|
-
`--format=${
|
|
61
|
+
`--format=${k}%H %cI %P`,
|
|
62
62
|
"--name-only",
|
|
63
63
|
"--no-renames",
|
|
64
64
|
"-z"
|
|
65
65
|
]),
|
|
66
|
-
|
|
67
|
-
`).filter((
|
|
68
|
-
]).catch((
|
|
69
|
-
throw
|
|
66
|
+
b(e, t, ["rev-parse", "--git-path", "shallow"]).then((f) => e.fs.readFile(e.path.resolve(t, f.trim()), "utf8").then((u) => new Set(u.split(`
|
|
67
|
+
`).filter((o) => o !== "")), () => /* @__PURE__ */ new Set()))
|
|
68
|
+
]).catch((f) => {
|
|
69
|
+
throw i("git", `last_modified is 'git' and git could not read the history of ${t}: ${f.message}`);
|
|
70
70
|
});
|
|
71
|
-
let
|
|
72
|
-
for (const
|
|
73
|
-
if (
|
|
74
|
-
const [
|
|
75
|
-
|
|
71
|
+
let c = "", m = !1;
|
|
72
|
+
for (const f of a.split("\0")) {
|
|
73
|
+
if (f.startsWith(k)) {
|
|
74
|
+
const [o, p] = f.slice(1).split(" ");
|
|
75
|
+
c = new Date(p).toISOString(), m = d.has(o);
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
`) ?
|
|
80
|
-
|
|
78
|
+
const u = f.startsWith(`
|
|
79
|
+
`) ? f.slice(1) : f;
|
|
80
|
+
u === "" || n.has(u) || (n.set(u, c), m && s.add(u));
|
|
81
81
|
}
|
|
82
|
-
return { dates:
|
|
82
|
+
return { dates: n, cut: s };
|
|
83
83
|
}
|
|
84
84
|
function A(e, t) {
|
|
85
85
|
t.warn("not_found", `${e} is not a file, so it has no last modified date`);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return async (t,
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
return A(t,
|
|
92
|
-
const
|
|
93
|
-
throw e("git",
|
|
94
|
-
})), { dates: d, cut:
|
|
95
|
-
if (
|
|
96
|
-
|
|
87
|
+
function C(e) {
|
|
88
|
+
return async (t, i) => {
|
|
89
|
+
const n = await O(), s = await I(n, t);
|
|
90
|
+
if (s === void 0)
|
|
91
|
+
return A(t, i);
|
|
92
|
+
const r = n.path.dirname(s), a = await i.cached(`git_root:${r}`, () => b(n, r, ["rev-parse", "--show-toplevel"]).then((f) => f.trim(), (f) => {
|
|
93
|
+
throw e("git", f.code === "ENOENT" ? `last_modified is 'git' and git could not be run: ${f.message}` : `last_modified is 'git' and ${t} is not inside a git repository: ${f.message}`);
|
|
94
|
+
})), { dates: d, cut: c } = await i.cached(`git_log:${a}`, () => j(n, a, e)), m = n.path.relative(a, s).split(n.path.sep).join("/");
|
|
95
|
+
if (c.has(m)) {
|
|
96
|
+
i.warn("shallow_history", `the history of ${t} was cut by a shallow clone, so the date of its last commit is not known, fetch the whole history (fetch-depth: 0)`);
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
return d.get(m);
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function M() {
|
|
103
103
|
return async (e, t) => {
|
|
104
|
-
const
|
|
104
|
+
const i = await O();
|
|
105
105
|
try {
|
|
106
|
-
return (await
|
|
107
|
-
} catch (
|
|
108
|
-
if (
|
|
109
|
-
throw
|
|
106
|
+
return (await i.fs.stat(e)).mtime.toISOString();
|
|
107
|
+
} catch (n) {
|
|
108
|
+
if (n.code !== "ENOENT")
|
|
109
|
+
throw n;
|
|
110
110
|
return A(e, t);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function T(e, t) {
|
|
115
115
|
if (!(e === void 0 || e === !1)) {
|
|
116
116
|
if (typeof e == "function") {
|
|
117
|
-
const
|
|
118
|
-
return async (
|
|
117
|
+
const i = e;
|
|
118
|
+
return async (n) => D(await i(n), t);
|
|
119
119
|
}
|
|
120
120
|
if (e !== "git" && e !== "fs")
|
|
121
121
|
throw t("option", `last_modified must be 'git', 'fs' or a function, got ${JSON.stringify(e)}`);
|
|
122
|
-
if (!
|
|
122
|
+
if (!v())
|
|
123
123
|
throw t("node", `last_modified is '${e}', which needs node, give last_modified a function to find the date here`);
|
|
124
|
-
return e === "git" ?
|
|
124
|
+
return e === "git" ? C(t) : M();
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function H(e) {
|
|
128
128
|
return e >= 12352 && e <= 12447 || e >= 19968 && e <= 40959 || e >= 44032 && e <= 55203 || e >= 131072 && e <= 191456;
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function F(e) {
|
|
131
131
|
return e >= 33 && e <= 47 || e >= 58 && e <= 64 || e >= 91 && e <= 96 || e >= 123 && e <= 126 || e >= 12288 && e <= 12351 || e >= 65280 && e <= 65519;
|
|
132
132
|
}
|
|
133
133
|
const W = /\s/;
|
|
134
|
-
function
|
|
135
|
-
let t = 0,
|
|
136
|
-
for (const
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
t++,
|
|
140
|
-
else if (W.test(
|
|
141
|
-
|
|
134
|
+
function q(e) {
|
|
135
|
+
let t = 0, i = !1, n = !1;
|
|
136
|
+
for (const s of e) {
|
|
137
|
+
const r = s.codePointAt(0);
|
|
138
|
+
if (H(r))
|
|
139
|
+
t++, i = !1, n = !0;
|
|
140
|
+
else if (W.test(s))
|
|
141
|
+
i = !1;
|
|
142
142
|
else {
|
|
143
|
-
if (
|
|
143
|
+
if (n && F(r))
|
|
144
144
|
continue;
|
|
145
|
-
|
|
145
|
+
n = !1, i || (t++, i = !0);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
return t;
|
|
149
149
|
}
|
|
150
150
|
const G = "@mdsvex/plugin-page-data", K = "page", L = "more";
|
|
151
151
|
class _ extends Error {
|
|
152
|
-
constructor(t,
|
|
153
|
-
super(`[${G}] ${t}`), this.name = "PageDataError", this.code =
|
|
152
|
+
constructor(t, i = "option") {
|
|
153
|
+
super(`[${G}] ${t}`), this.name = "PageDataError", this.code = i;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function P(e) {
|
|
157
157
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function N(e, t) {
|
|
160
160
|
if (t !== !1) {
|
|
161
161
|
if (t === void 0 || t === !0)
|
|
162
162
|
return {};
|
|
163
|
-
if (
|
|
163
|
+
if (P(t))
|
|
164
164
|
return t;
|
|
165
165
|
throw new _(`${e} must be true, false or an object of options, got ${JSON.stringify(t)}`);
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
const
|
|
169
|
-
amp: "&",
|
|
170
|
-
lt: "<",
|
|
171
|
-
gt: ">",
|
|
172
|
-
quot: '"',
|
|
173
|
-
apos: "'",
|
|
174
|
-
nbsp: " "
|
|
175
|
-
};
|
|
176
|
-
function B(e, t, n, i) {
|
|
177
|
-
if (i !== void 0)
|
|
178
|
-
return X[i];
|
|
179
|
-
const r = t !== void 0 ? parseInt(t, 10) : parseInt(n, 16);
|
|
180
|
-
return r === 0 || r > 1114111 || r >= 55296 && r <= 57343 ? "�" : String.fromCodePoint(r);
|
|
181
|
-
}
|
|
182
|
-
function P(e) {
|
|
183
|
-
return e.indexOf("&") === -1 ? e : e.replace(U, B);
|
|
184
|
-
}
|
|
185
|
-
const Q = /^[a-z][^.:]*$/;
|
|
186
|
-
function x(e) {
|
|
187
|
-
let t = "";
|
|
188
|
-
for (let n = e.first_child; n !== null; n = n.next)
|
|
189
|
-
switch (n.type) {
|
|
190
|
-
case "text":
|
|
191
|
-
t += P(n.text_content);
|
|
192
|
-
break;
|
|
193
|
-
case "code_span":
|
|
194
|
-
t += n.text_content;
|
|
195
|
-
break;
|
|
196
|
-
case "mustache":
|
|
197
|
-
case "svelte_tag":
|
|
198
|
-
case "svelte_block":
|
|
199
|
-
case "html_comment":
|
|
200
|
-
case "directive_inline":
|
|
201
|
-
case "directive_leaf":
|
|
202
|
-
case "directive_container":
|
|
203
|
-
break;
|
|
204
|
-
case "html": {
|
|
205
|
-
const i = n.attrs.tag;
|
|
206
|
-
typeof i == "string" && Q.test(i) && (t += x(n));
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
default:
|
|
210
|
-
t += x(n);
|
|
211
|
-
}
|
|
212
|
-
return t;
|
|
213
|
-
}
|
|
214
|
-
const V = /\s+/g;
|
|
168
|
+
const R = /\s+/g;
|
|
215
169
|
function g(e) {
|
|
216
170
|
const t = e.run;
|
|
217
171
|
if (t === "")
|
|
218
172
|
return;
|
|
219
173
|
e.run = "";
|
|
220
|
-
const
|
|
221
|
-
|
|
174
|
+
const i = t.replace(R, " ").trim();
|
|
175
|
+
i !== "" && (e.count && (e.words += q(i)), !(e.before === void 0 || e.heading || e.table > 0) && (e.more || e.before.push(i), e.first === void 0 && e.paragraph && (e.first = i)));
|
|
222
176
|
}
|
|
223
|
-
function
|
|
177
|
+
function w(e, t, i) {
|
|
224
178
|
for (let n = e.first_child; n !== null; n = n.next) {
|
|
225
|
-
const
|
|
226
|
-
switch (
|
|
179
|
+
const s = n.type;
|
|
180
|
+
switch (s) {
|
|
227
181
|
case "text":
|
|
228
|
-
t.run +=
|
|
182
|
+
t.run += i.text(n);
|
|
229
183
|
break;
|
|
230
184
|
// read as part of its sentence
|
|
231
185
|
case "code_span":
|
|
@@ -252,25 +206,25 @@ function b(e, t) {
|
|
|
252
206
|
break;
|
|
253
207
|
case "html": {
|
|
254
208
|
const r = n.attrs.tag;
|
|
255
|
-
r !== "script" && r !== "style" &&
|
|
209
|
+
r !== "script" && r !== "style" && w(n, t, i);
|
|
256
210
|
break;
|
|
257
211
|
}
|
|
258
212
|
case "heading":
|
|
259
213
|
if (g(t), t.title === void 0 && t.nested === 0 && n.depth === 1) {
|
|
260
|
-
const r =
|
|
214
|
+
const r = i.text(n).trim();
|
|
261
215
|
r !== "" && (t.title = r);
|
|
262
216
|
}
|
|
263
|
-
t.heading = !0,
|
|
217
|
+
t.heading = !0, w(n, t, i), g(t), t.heading = !1;
|
|
264
218
|
break;
|
|
265
219
|
case "paragraph":
|
|
266
|
-
g(t), t.paragraph = t.nested === 0,
|
|
220
|
+
g(t), t.paragraph = t.nested === 0, w(n, t, i), g(t), t.paragraph = !1;
|
|
267
221
|
break;
|
|
268
222
|
case "list_item":
|
|
269
223
|
case "table_cell":
|
|
270
224
|
case "directive_leaf":
|
|
271
225
|
case "directive_label":
|
|
272
226
|
case "svelte_branch":
|
|
273
|
-
g(t),
|
|
227
|
+
g(t), w(n, t, i), g(t);
|
|
274
228
|
break;
|
|
275
229
|
case "block_quote":
|
|
276
230
|
case "list":
|
|
@@ -278,87 +232,87 @@ function b(e, t) {
|
|
|
278
232
|
case "footnote_definition":
|
|
279
233
|
case "directive_container":
|
|
280
234
|
case "svelte_block": {
|
|
281
|
-
const r =
|
|
282
|
-
g(t), t.nested++, r && t.table++,
|
|
235
|
+
const r = s === "table" || s === "footnote_definition";
|
|
236
|
+
g(t), t.nested++, r && t.table++, w(n, t, i), g(t), r && t.table--, t.nested--;
|
|
283
237
|
break;
|
|
284
238
|
}
|
|
285
239
|
// emphasis, links, inline directives and whatever a plugin made
|
|
286
240
|
default:
|
|
287
|
-
|
|
241
|
+
w(n, t, i);
|
|
288
242
|
}
|
|
289
243
|
}
|
|
290
244
|
}
|
|
291
|
-
const
|
|
292
|
-
function
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
245
|
+
const z = "…", y = /\s/, E = /[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u;
|
|
246
|
+
function U(e, t, i) {
|
|
247
|
+
const n = Array.from(e);
|
|
248
|
+
if (n.length <= t)
|
|
295
249
|
return e;
|
|
296
|
-
let
|
|
297
|
-
if (!(
|
|
298
|
-
let d =
|
|
299
|
-
for (; d > 0 && !y.test(
|
|
250
|
+
let r = Math.max(0, t - Array.from(i).length);
|
|
251
|
+
if (!(r === 0 || y.test(n[r]) || E.test(n[r]) || E.test(n[r - 1]))) {
|
|
252
|
+
let d = r;
|
|
253
|
+
for (; d > 0 && !y.test(n[d - 1]); )
|
|
300
254
|
d--;
|
|
301
|
-
d > 0 && (
|
|
255
|
+
d > 0 && (r = d);
|
|
302
256
|
}
|
|
303
|
-
for (;
|
|
304
|
-
|
|
305
|
-
return
|
|
257
|
+
for (; r > 0 && y.test(n[r - 1]); )
|
|
258
|
+
r--;
|
|
259
|
+
return n.slice(0, r).join("") + i;
|
|
306
260
|
}
|
|
307
|
-
function
|
|
261
|
+
function x(e) {
|
|
308
262
|
return e.replace(/\\/g, "/");
|
|
309
263
|
}
|
|
310
|
-
function
|
|
264
|
+
function B(e) {
|
|
311
265
|
if (e === void 0)
|
|
312
266
|
return;
|
|
313
267
|
if (typeof e == "function")
|
|
314
|
-
return (
|
|
315
|
-
if (
|
|
316
|
-
return
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
return
|
|
320
|
-
throw new _(`edit_url must return a string or undefined, it returned ${JSON.stringify(
|
|
268
|
+
return (s, r) => {
|
|
269
|
+
if (s === void 0)
|
|
270
|
+
return $(r);
|
|
271
|
+
const a = e(s);
|
|
272
|
+
if (a === void 0 || typeof a == "string")
|
|
273
|
+
return a;
|
|
274
|
+
throw new _(`edit_url must return a string or undefined, it returned ${JSON.stringify(a)}`);
|
|
321
275
|
};
|
|
322
276
|
const t = typeof e == "string" ? { base: e } : e;
|
|
323
|
-
if (!
|
|
277
|
+
if (!P(t) || typeof t.base != "string" || t.base === "" || t.root !== void 0 && typeof t.root != "string")
|
|
324
278
|
throw new _(`edit_url must be a base url, an object with a base and a root, or a function, got ${JSON.stringify(e)}`);
|
|
325
|
-
const
|
|
326
|
-
return (
|
|
279
|
+
const i = t.base.replace(/\/+$/, "") + "/", n = t.root;
|
|
280
|
+
return (s, r) => {
|
|
327
281
|
var m;
|
|
328
|
-
if (
|
|
329
|
-
return
|
|
330
|
-
const
|
|
331
|
-
let
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
if (!d.startsWith(
|
|
335
|
-
|
|
282
|
+
if (s === void 0)
|
|
283
|
+
return $(r);
|
|
284
|
+
const a = n ?? ((m = globalThis.process) == null ? void 0 : m.cwd()), d = x(s);
|
|
285
|
+
let c = d;
|
|
286
|
+
if (a !== void 0) {
|
|
287
|
+
const f = x(a).replace(/\/+$/, "") + "/";
|
|
288
|
+
if (!d.startsWith(f)) {
|
|
289
|
+
r.warn("outside_root", `${s} is not inside ${a}, so it has no edit url, set the root of edit_url`);
|
|
336
290
|
return;
|
|
337
291
|
}
|
|
338
|
-
|
|
292
|
+
c = d.slice(f.length);
|
|
339
293
|
}
|
|
340
|
-
return
|
|
294
|
+
return i + encodeURI(c.replace(/^\/+/, ""));
|
|
341
295
|
};
|
|
342
296
|
}
|
|
343
|
-
function
|
|
297
|
+
function $(e, t = "edit url") {
|
|
344
298
|
e.warn("no_filename", `the compile was given no filename, so the document has no ${t}`);
|
|
345
299
|
}
|
|
346
|
-
function
|
|
347
|
-
const t =
|
|
348
|
-
if (typeof
|
|
349
|
-
throw new _(`reading_time.words_per_minute must be a number above 0, got ${JSON.stringify(
|
|
350
|
-
const
|
|
351
|
-
if (
|
|
352
|
-
throw new _(`excerpt.max_length must be a whole number above 0, got ${JSON.stringify(
|
|
353
|
-
const
|
|
354
|
-
if (typeof
|
|
355
|
-
throw new _(`excerpt.ellipsis must be a string, got ${JSON.stringify(
|
|
300
|
+
function Q(e = {}) {
|
|
301
|
+
const t = N("reading_time", e.reading_time), i = (t == null ? void 0 : t.words_per_minute) ?? 200;
|
|
302
|
+
if (typeof i != "number" || !Number.isFinite(i) || i <= 0)
|
|
303
|
+
throw new _(`reading_time.words_per_minute must be a number above 0, got ${JSON.stringify(i)}`);
|
|
304
|
+
const n = N("excerpt", e.excerpt), s = n == null ? void 0 : n.max_length;
|
|
305
|
+
if (s !== void 0 && (typeof s != "number" || !Number.isInteger(s) || s < 1))
|
|
306
|
+
throw new _(`excerpt.max_length must be a whole number above 0, got ${JSON.stringify(s)}`);
|
|
307
|
+
const r = (n == null ? void 0 : n.ellipsis) ?? z;
|
|
308
|
+
if (typeof r != "string")
|
|
309
|
+
throw new _(`excerpt.ellipsis must be a string, got ${JSON.stringify(r)}`);
|
|
356
310
|
if (e.title !== void 0 && typeof e.title != "boolean")
|
|
357
311
|
throw new _(`title must be true or false, got ${JSON.stringify(e.title)}`);
|
|
358
|
-
const
|
|
359
|
-
function m(
|
|
312
|
+
const a = e.title !== !1, d = B(e.edit_url), c = T(e.last_modified, (u, o) => new _(o, u));
|
|
313
|
+
function m(u, o) {
|
|
360
314
|
var S;
|
|
361
|
-
let p =
|
|
315
|
+
let p = u.first_child;
|
|
362
316
|
for (; p !== null && p.type === "line_break"; )
|
|
363
317
|
p = p.next;
|
|
364
318
|
if (p === null)
|
|
@@ -371,44 +325,44 @@ function te(e = {}) {
|
|
|
371
325
|
table: 0,
|
|
372
326
|
paragraph: !1,
|
|
373
327
|
nested: 0,
|
|
374
|
-
before:
|
|
328
|
+
before: n === void 0 ? void 0 : [],
|
|
375
329
|
more: !1,
|
|
376
330
|
first: void 0,
|
|
377
|
-
title:
|
|
331
|
+
title: a ? void 0 : null
|
|
378
332
|
};
|
|
379
|
-
if (
|
|
380
|
-
const h = (S =
|
|
381
|
-
(h == null || h === "") &&
|
|
333
|
+
if (w(u, l, o), g(l), typeof l.title == "string") {
|
|
334
|
+
const h = (S = o.frontmatter) == null ? void 0 : S.title;
|
|
335
|
+
(h == null || h === "") && o.set("title", l.title);
|
|
382
336
|
}
|
|
383
337
|
if (l.before !== void 0) {
|
|
384
338
|
const h = l.more ? l.before.join(" ") : l.first;
|
|
385
|
-
h !== void 0 && h !== "" &&
|
|
339
|
+
h !== void 0 && h !== "" && o.set("excerpt", s === void 0 ? h : U(h, s, r));
|
|
386
340
|
}
|
|
387
|
-
if (l.count && (
|
|
388
|
-
const h = d(
|
|
389
|
-
h !== void 0 &&
|
|
341
|
+
if (l.count && (o.set("words", l.words), o.set("minutes", Math.ceil(Number((l.words / i).toFixed(2))))), d !== void 0) {
|
|
342
|
+
const h = d(o.filename, o);
|
|
343
|
+
h !== void 0 && o.set("edit_url", h);
|
|
390
344
|
}
|
|
391
345
|
}
|
|
392
|
-
async function
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
return
|
|
396
|
-
const p = await
|
|
397
|
-
p !== void 0 &&
|
|
346
|
+
async function f(u) {
|
|
347
|
+
const o = u.filename;
|
|
348
|
+
if (o === void 0)
|
|
349
|
+
return $(u, "last modified date");
|
|
350
|
+
const p = await c(o, u);
|
|
351
|
+
p !== void 0 && u.set("last_modified", p);
|
|
398
352
|
}
|
|
399
353
|
return {
|
|
400
354
|
name: K,
|
|
401
355
|
parse: {
|
|
402
356
|
// once the tree is settled, a count kept while nodes are revoked is not exact
|
|
403
|
-
document(
|
|
404
|
-
if (m(
|
|
405
|
-
return
|
|
357
|
+
document(u, o) {
|
|
358
|
+
if (m(u, o), c !== void 0)
|
|
359
|
+
return f(o);
|
|
406
360
|
}
|
|
407
361
|
}
|
|
408
362
|
};
|
|
409
363
|
}
|
|
410
364
|
export {
|
|
411
365
|
_ as PageDataError,
|
|
412
|
-
|
|
413
|
-
|
|
366
|
+
q as count_words,
|
|
367
|
+
Q as page_data
|
|
414
368
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdsvex/plugin-page-data",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Page data for mdsvex, the reading time, excerpt, inferred title, edit url and last modified date of a document",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"author": "pngwn <hello@pngwn.io>",
|
|
44
44
|
"license": "MIT",
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"mdsvex": "^1.
|
|
46
|
+
"mdsvex": "^1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^22.15.2",
|
|
50
50
|
"npm-run-all2": "^7.0.2",
|
|
51
51
|
"shx": "^0.3.4",
|
|
52
|
-
"mdsvex": "^1.0
|
|
52
|
+
"mdsvex": "^1.1.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "run-s build:tsc build:vite build:copy-dts",
|