@mdsvex/plugin-page-data 0.1.0 → 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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +162 -208
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Facts about each [mdsvex](https://mdsvex.pngwn.io) document, for its template and for pages that list documents: a reading time and word count, an excerpt, a title read from the first heading, an edit url, and the date it was last changed.
4
4
 
5
5
  ```bash
6
- pnpm add --save-dev @mdsvex/plugin-page-data@next
6
+ pnpm add --save-dev @mdsvex/plugin-page-data
7
7
  ```
8
8
 
9
9
  ```js
@@ -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 I() {
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 n = e instanceof Date ? e : typeof e == "string" ? new Date(e) : void 0;
10
- if (n === void 0 || Number.isNaN(n.getTime()))
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 n.toISOString();
12
+ return i.toISOString();
13
13
  }
14
- async function v() {
15
- const [e, t, n] = await Promise.all([
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: n };
20
+ return { child_process: e, fs: t, path: i };
21
21
  }
22
- async function J(e, t) {
22
+ async function I(e, t) {
23
23
  try {
24
24
  return await e.fs.realpath(t);
25
- } catch (n) {
26
- if (n.code === "ENOENT")
25
+ } catch (i) {
26
+ if (i.code === "ENOENT")
27
27
  return;
28
- throw n;
28
+ throw i;
29
29
  }
30
30
  }
31
- class j extends Error {
32
- constructor(t, n) {
33
- super(n), this.status = t, this.stderr = n;
31
+ class J extends Error {
32
+ constructor(t, i) {
33
+ super(i), this.status = t, this.stderr = i;
34
34
  }
35
35
  }
36
- function w(e, t, n) {
37
- return new Promise((i, r) => {
38
- const s = e.child_process.spawn("git", n, {
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 o = "", d = "";
43
- s.stdout.setEncoding("utf8"), s.stderr.setEncoding("utf8"), s.stdout.on("data", (u) => o += u), s.stderr.on("data", (u) => d += u), s.on("error", r), s.on("close", (u) => {
44
- u === 0 ? i(o) : r(new j(u, d.trim()));
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 M(e, t, n) {
50
- const i = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set();
51
- if (await w(e, t, [
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: i, cut: r };
58
- const [o, d] = await Promise.all([
59
- w(e, t, [
57
+ return { dates: n, cut: s };
58
+ const [a, d] = await Promise.all([
59
+ b(e, t, [
60
60
  "log",
61
- `--format=${$}%H %cI %P`,
61
+ `--format=${k}%H %cI %P`,
62
62
  "--name-only",
63
63
  "--no-renames",
64
64
  "-z"
65
65
  ]),
66
- w(e, t, ["rev-parse", "--git-path", "shallow"]).then((a) => e.fs.readFile(e.path.resolve(t, a.trim()), "utf8").then((c) => new Set(c.split(`
67
- `).filter((f) => f !== "")), () => /* @__PURE__ */ new Set()))
68
- ]).catch((a) => {
69
- throw n("git", `last_modified is 'git' and git could not read the history of ${t}: ${a.message}`);
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 u = "", m = !1;
72
- for (const a of o.split("\0")) {
73
- if (a.startsWith($)) {
74
- const [f, p] = a.slice(1).split(" ");
75
- u = new Date(p).toISOString(), m = d.has(f);
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 c = a.startsWith(`
79
- `) ? a.slice(1) : a;
80
- c === "" || i.has(c) || (i.set(c, u), m && r.add(c));
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: i, cut: r };
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 T(e) {
88
- return async (t, n) => {
89
- const i = await v(), r = await J(i, t);
90
- if (r === void 0)
91
- return A(t, n);
92
- const s = i.path.dirname(r), o = await n.cached(`git_root:${s}`, () => w(i, s, ["rev-parse", "--show-toplevel"]).then((a) => a.trim(), (a) => {
93
- throw e("git", a.code === "ENOENT" ? `last_modified is 'git' and git could not be run: ${a.message}` : `last_modified is 'git' and ${t} is not inside a git repository: ${a.message}`);
94
- })), { dates: d, cut: u } = await n.cached(`git_log:${o}`, () => M(i, o, e)), m = i.path.relative(o, r).split(i.path.sep).join("/");
95
- if (u.has(m)) {
96
- n.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)`);
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 F() {
102
+ function M() {
103
103
  return async (e, t) => {
104
- const n = await v();
104
+ const i = await O();
105
105
  try {
106
- return (await n.fs.stat(e)).mtime.toISOString();
107
- } catch (i) {
108
- if (i.code !== "ENOENT")
109
- throw i;
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 H(e, t) {
114
+ function T(e, t) {
115
115
  if (!(e === void 0 || e === !1)) {
116
116
  if (typeof e == "function") {
117
- const n = e;
118
- return async (i) => D(await n(i), t);
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 (!I())
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" ? T(t) : F();
124
+ return e === "git" ? C(t) : M();
125
125
  }
126
126
  }
127
- function q(e) {
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 R(e) {
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 z(e) {
135
- let t = 0, n = !1, i = !1;
136
- for (const r of e) {
137
- const s = r.codePointAt(0);
138
- if (q(s))
139
- t++, n = !1, i = !0;
140
- else if (W.test(r))
141
- n = !1;
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 (i && R(s))
143
+ if (n && F(r))
144
144
  continue;
145
- i = !1, n || (t++, n = !0);
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, n = "option") {
153
- super(`[${G}] ${t}`), this.name = "PageDataError", this.code = n;
152
+ constructor(t, i = "option") {
153
+ super(`[${G}] ${t}`), this.name = "PageDataError", this.code = i;
154
154
  }
155
155
  }
156
- function C(e) {
156
+ function P(e) {
157
157
  return typeof e == "object" && e !== null && !Array.isArray(e);
158
158
  }
159
- function E(e, t) {
159
+ function N(e, t) {
160
160
  if (t !== !1) {
161
161
  if (t === void 0 || t === !0)
162
162
  return {};
163
- if (C(t))
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 U = /&(?:#(\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|(amp|lt|gt|quot|apos|nbsp));/g, X = {
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 n = t.replace(V, " ").trim();
221
- n !== "" && (e.count && (e.words += z(n)), !(e.before === void 0 || e.heading || e.table > 0) && (e.more || e.before.push(n), e.first === void 0 && e.paragraph && (e.first = n)));
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 b(e, t) {
177
+ function w(e, t, i) {
224
178
  for (let n = e.first_child; n !== null; n = n.next) {
225
- const i = n.type;
226
- switch (i) {
179
+ const s = n.type;
180
+ switch (s) {
227
181
  case "text":
228
- t.run += P(n.text_content);
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" && b(n, t);
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 = x(n).trim();
214
+ const r = i.text(n).trim();
261
215
  r !== "" && (t.title = r);
262
216
  }
263
- t.heading = !0, b(n, t), g(t), t.heading = !1;
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, b(n, t), g(t), t.paragraph = !1;
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), b(n, t), 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 = i === "table" || i === "footnote_definition";
282
- g(t), t.nested++, r && t.table++, b(n, t), g(t), r && t.table--, t.nested--;
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
- b(n, t);
241
+ w(n, t, i);
288
242
  }
289
243
  }
290
244
  }
291
- const Y = "…", y = /\s/, N = /[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u;
292
- function Z(e, t, n) {
293
- const i = Array.from(e);
294
- if (i.length <= t)
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 s = Math.max(0, t - Array.from(n).length);
297
- if (!(s === 0 || y.test(i[s]) || N.test(i[s]) || N.test(i[s - 1]))) {
298
- let d = s;
299
- for (; d > 0 && !y.test(i[d - 1]); )
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 && (s = d);
255
+ d > 0 && (r = d);
302
256
  }
303
- for (; s > 0 && y.test(i[s - 1]); )
304
- s--;
305
- return i.slice(0, s).join("") + n;
257
+ for (; r > 0 && y.test(n[r - 1]); )
258
+ r--;
259
+ return n.slice(0, r).join("") + i;
306
260
  }
307
- function O(e) {
261
+ function x(e) {
308
262
  return e.replace(/\\/g, "/");
309
263
  }
310
- function ee(e) {
264
+ function B(e) {
311
265
  if (e === void 0)
312
266
  return;
313
267
  if (typeof e == "function")
314
- return (r, s) => {
315
- if (r === void 0)
316
- return k(s);
317
- const o = e(r);
318
- if (o === void 0 || typeof o == "string")
319
- return o;
320
- throw new _(`edit_url must return a string or undefined, it returned ${JSON.stringify(o)}`);
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 (!C(t) || typeof t.base != "string" || t.base === "" || t.root !== void 0 && typeof t.root != "string")
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 n = t.base.replace(/\/+$/, "") + "/", i = t.root;
326
- return (r, s) => {
279
+ const i = t.base.replace(/\/+$/, "") + "/", n = t.root;
280
+ return (s, r) => {
327
281
  var m;
328
- if (r === void 0)
329
- return k(s);
330
- const o = i ?? ((m = globalThis.process) == null ? void 0 : m.cwd()), d = O(r);
331
- let u = d;
332
- if (o !== void 0) {
333
- const a = O(o).replace(/\/+$/, "") + "/";
334
- if (!d.startsWith(a)) {
335
- s.warn("outside_root", `${r} is not inside ${o}, so it has no edit url, set the root of edit_url`);
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
- u = d.slice(a.length);
292
+ c = d.slice(f.length);
339
293
  }
340
- return n + encodeURI(u.replace(/^\/+/, ""));
294
+ return i + encodeURI(c.replace(/^\/+/, ""));
341
295
  };
342
296
  }
343
- function k(e, t = "edit url") {
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 te(e = {}) {
347
- const t = E("reading_time", e.reading_time), n = (t == null ? void 0 : t.words_per_minute) ?? 200;
348
- if (typeof n != "number" || !Number.isFinite(n) || n <= 0)
349
- throw new _(`reading_time.words_per_minute must be a number above 0, got ${JSON.stringify(n)}`);
350
- const i = E("excerpt", e.excerpt), r = i == null ? void 0 : i.max_length;
351
- if (r !== void 0 && (typeof r != "number" || !Number.isInteger(r) || r < 1))
352
- throw new _(`excerpt.max_length must be a whole number above 0, got ${JSON.stringify(r)}`);
353
- const s = (i == null ? void 0 : i.ellipsis) ?? Y;
354
- if (typeof s != "string")
355
- throw new _(`excerpt.ellipsis must be a string, got ${JSON.stringify(s)}`);
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 o = e.title !== !1, d = ee(e.edit_url), u = H(e.last_modified, (c, f) => new _(f, c));
359
- function m(c, f) {
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 = c.first_child;
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: i === void 0 ? void 0 : [],
328
+ before: n === void 0 ? void 0 : [],
375
329
  more: !1,
376
330
  first: void 0,
377
- title: o ? void 0 : null
331
+ title: a ? void 0 : null
378
332
  };
379
- if (b(c, l), g(l), typeof l.title == "string") {
380
- const h = (S = f.frontmatter) == null ? void 0 : S.title;
381
- (h == null || h === "") && f.set("title", l.title);
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 !== "" && f.set("excerpt", r === void 0 ? h : Z(h, r, s));
339
+ h !== void 0 && h !== "" && o.set("excerpt", s === void 0 ? h : U(h, s, r));
386
340
  }
387
- if (l.count && (f.set("words", l.words), f.set("minutes", Math.ceil(Number((l.words / n).toFixed(2))))), d !== void 0) {
388
- const h = d(f.filename, f);
389
- h !== void 0 && f.set("edit_url", h);
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 a(c) {
393
- const f = c.filename;
394
- if (f === void 0)
395
- return k(c, "last modified date");
396
- const p = await u(f, c);
397
- p !== void 0 && c.set("last_modified", p);
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(c, f) {
404
- if (m(c, f), u !== void 0)
405
- return a(f);
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
- z as count_words,
413
- te as page_data
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.0",
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.0.0-next.2"
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.0"
52
+ "mdsvex": "^1.1.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "run-s build:tsc build:vite build:copy-dts",