@k34a/blog 0.0.16 → 0.0.18
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.
|
@@ -1,14 +1,166 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { Box as
|
|
4
|
-
import { IconHash as
|
|
5
|
-
import { BannerImage as
|
|
6
|
-
import
|
|
7
|
-
function
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { jsx as u, jsxs as y } from "react/jsx-runtime";
|
|
3
|
+
import { Box as S, Stack as M, Title as R, Text as D, Flex as P, Badge as B } from "@mantine/core";
|
|
4
|
+
import { IconHash as $ } from "@tabler/icons-react";
|
|
5
|
+
import { BannerImage as q } from "./banner-image.js";
|
|
6
|
+
import A from "./description.js";
|
|
7
|
+
function C(e) {
|
|
8
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
9
|
+
}
|
|
10
|
+
function I(e) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
|
|
12
|
+
var o = e.default;
|
|
13
|
+
if (typeof o == "function") {
|
|
14
|
+
var a = function r() {
|
|
15
|
+
var n = !1;
|
|
16
|
+
try {
|
|
17
|
+
n = this instanceof r;
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
return n ? Reflect.construct(o, arguments, this.constructor) : o.apply(this, arguments);
|
|
21
|
+
};
|
|
22
|
+
a.prototype = o.prototype;
|
|
23
|
+
} else a = {};
|
|
24
|
+
return Object.defineProperty(a, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
|
|
25
|
+
var n = Object.getOwnPropertyDescriptor(e, r);
|
|
26
|
+
Object.defineProperty(a, r, n.get ? n : {
|
|
27
|
+
enumerable: !0,
|
|
28
|
+
get: function() {
|
|
29
|
+
return e[r];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}), a;
|
|
33
|
+
}
|
|
34
|
+
var l = { exports: {} };
|
|
35
|
+
/*!
|
|
36
|
+
* reading-time
|
|
37
|
+
* Copyright (c) Nicolas Gryman <ngryman@gmail.com>
|
|
38
|
+
* MIT Licensed
|
|
39
|
+
*/
|
|
40
|
+
var x, w;
|
|
41
|
+
function v() {
|
|
42
|
+
if (w) return x;
|
|
43
|
+
w = 1;
|
|
44
|
+
function e(t, s) {
|
|
45
|
+
return s.some(
|
|
46
|
+
([i, f]) => i <= t && t <= f
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function o(t) {
|
|
50
|
+
if (typeof t != "string")
|
|
51
|
+
return !1;
|
|
52
|
+
const s = t.charCodeAt(0);
|
|
53
|
+
return e(
|
|
54
|
+
s,
|
|
55
|
+
[
|
|
56
|
+
// Hiragana (Katakana not included on purpose,
|
|
57
|
+
// context: https://github.com/ngryman/reading-time/pull/35#issuecomment-853364526)
|
|
58
|
+
// If you think Katakana should be included and have solid reasons, improvement is welcomed
|
|
59
|
+
[12352, 12447],
|
|
60
|
+
// CJK Unified ideographs
|
|
61
|
+
[19968, 40959],
|
|
62
|
+
// Hangul
|
|
63
|
+
[44032, 55203],
|
|
64
|
+
// CJK extensions
|
|
65
|
+
[131072, 191456]
|
|
66
|
+
]
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
function a(t) {
|
|
70
|
+
return `
|
|
71
|
+
\r `.includes(t);
|
|
72
|
+
}
|
|
73
|
+
function r(t) {
|
|
74
|
+
if (typeof t != "string")
|
|
75
|
+
return !1;
|
|
76
|
+
const s = t.charCodeAt(0);
|
|
77
|
+
return e(
|
|
78
|
+
s,
|
|
79
|
+
[
|
|
80
|
+
[33, 47],
|
|
81
|
+
[58, 64],
|
|
82
|
+
[91, 96],
|
|
83
|
+
[123, 126],
|
|
84
|
+
// CJK Symbols and Punctuation
|
|
85
|
+
[12288, 12351],
|
|
86
|
+
// Full-width ASCII punctuation variants
|
|
87
|
+
[65280, 65519]
|
|
88
|
+
]
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
function n(t, s = {}) {
|
|
92
|
+
let i = 0, f = 0, h = t.length - 1;
|
|
93
|
+
const j = s.wordsPerMinute || 200, m = s.wordBound || a;
|
|
94
|
+
for (; m(t[f]); ) f++;
|
|
95
|
+
for (; m(t[h]); ) h--;
|
|
96
|
+
const d = `${t}
|
|
97
|
+
`;
|
|
98
|
+
for (let c = f; c <= h; c++)
|
|
99
|
+
if ((o(d[c]) || !m(d[c]) && (m(d[c + 1]) || o(d[c + 1]))) && i++, o(d[c]))
|
|
100
|
+
for (; c <= h && (r(d[c + 1]) || m(d[c + 1])); )
|
|
101
|
+
c++;
|
|
102
|
+
const g = i / j, O = Math.round(g * 60 * 1e3);
|
|
103
|
+
return {
|
|
104
|
+
text: Math.ceil(g.toFixed(2)) + " min read",
|
|
105
|
+
minutes: g,
|
|
106
|
+
time: O,
|
|
107
|
+
words: i
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return x = n, x;
|
|
111
|
+
}
|
|
112
|
+
const z = {}, E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
113
|
+
__proto__: null,
|
|
114
|
+
default: z
|
|
115
|
+
}, Symbol.toStringTag, { value: "Module" })), T = /* @__PURE__ */ I(E);
|
|
116
|
+
/*!
|
|
117
|
+
* reading-time
|
|
118
|
+
* Copyright (c) Nicolas Gryman <ngryman@gmail.com>
|
|
119
|
+
* MIT Licensed
|
|
120
|
+
*/
|
|
121
|
+
var p, _;
|
|
122
|
+
function F() {
|
|
123
|
+
if (_) return p;
|
|
124
|
+
_ = 1;
|
|
125
|
+
const e = v(), o = T.Transform, a = T;
|
|
126
|
+
function r(n) {
|
|
127
|
+
if (!(this instanceof r))
|
|
128
|
+
return new r(n);
|
|
129
|
+
o.call(this, { objectMode: !0 }), this.options = n || {}, this.stats = {
|
|
130
|
+
minutes: 0,
|
|
131
|
+
time: 0,
|
|
132
|
+
words: 0
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return a.inherits(r, o), r.prototype._transform = function(n, t, s) {
|
|
136
|
+
const i = e(n.toString(t), this.options);
|
|
137
|
+
this.stats.minutes += i.minutes, this.stats.time += i.time, this.stats.words += i.words, s();
|
|
138
|
+
}, r.prototype._flush = function(n) {
|
|
139
|
+
this.stats.text = Math.ceil(this.stats.minutes.toFixed(2)) + " min read", this.push(this.stats), n();
|
|
140
|
+
}, p = r, p;
|
|
141
|
+
}
|
|
142
|
+
var b;
|
|
143
|
+
function U() {
|
|
144
|
+
return b || (b = 1, l.exports.default = l.exports = v(), l.exports.readingTimeStream = F()), l.exports;
|
|
145
|
+
}
|
|
146
|
+
var W = U();
|
|
147
|
+
const k = /* @__PURE__ */ C(W);
|
|
148
|
+
function Q(e) {
|
|
149
|
+
const o = new Date(e.created_at), a = new Date(e.updated_at), r = (i) => i.toLocaleDateString("en-US", {
|
|
150
|
+
year: "numeric",
|
|
151
|
+
month: "long",
|
|
152
|
+
day: "numeric"
|
|
153
|
+
}), n = e.description.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim(), t = k(n), s = a.getTime() !== o.getTime();
|
|
154
|
+
return /* @__PURE__ */ u(S, { maw: 800, mx: "auto", px: "sm", py: "lg", children: /* @__PURE__ */ y(M, { gap: "md", children: [
|
|
155
|
+
/* @__PURE__ */ u(R, { order: 1, children: e.title }),
|
|
156
|
+
/* @__PURE__ */ y(D, { size: "sm", c: "dimmed", children: [
|
|
157
|
+
t.text,
|
|
158
|
+
" · Written on ",
|
|
159
|
+
r(o),
|
|
160
|
+
s && ` · Updated on ${r(a)}`
|
|
161
|
+
] }),
|
|
162
|
+
e.banner_image && /* @__PURE__ */ u(
|
|
163
|
+
q,
|
|
12
164
|
{
|
|
13
165
|
id: e.id,
|
|
14
166
|
src: e.banner_image,
|
|
@@ -16,27 +168,27 @@ function b(e) {
|
|
|
16
168
|
config: e.config
|
|
17
169
|
}
|
|
18
170
|
),
|
|
19
|
-
/* @__PURE__ */
|
|
20
|
-
|
|
171
|
+
/* @__PURE__ */ u(
|
|
172
|
+
A,
|
|
21
173
|
{
|
|
22
174
|
articleId: e.id,
|
|
23
175
|
html: e.description,
|
|
24
176
|
config: e.config
|
|
25
177
|
}
|
|
26
178
|
),
|
|
27
|
-
/* @__PURE__ */
|
|
28
|
-
|
|
179
|
+
/* @__PURE__ */ u(P, { wrap: "wrap", gap: "md", align: "center", mb: "lg", children: e.tags.map((i) => /* @__PURE__ */ u("a", { href: i.href, children: /* @__PURE__ */ u(
|
|
180
|
+
B,
|
|
29
181
|
{
|
|
30
182
|
size: "md",
|
|
31
183
|
color: "sky.5",
|
|
32
184
|
variant: "outline",
|
|
33
|
-
leftSection: /* @__PURE__ */
|
|
185
|
+
leftSection: /* @__PURE__ */ u($, { size: 14 }),
|
|
34
186
|
style: { cursor: "pointer" },
|
|
35
|
-
children:
|
|
187
|
+
children: i.name
|
|
36
188
|
}
|
|
37
|
-
) },
|
|
189
|
+
) }, i.name)) })
|
|
38
190
|
] }) });
|
|
39
191
|
}
|
|
40
192
|
export {
|
|
41
|
-
|
|
193
|
+
Q as default
|
|
42
194
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { articleSortByVsQuery as
|
|
1
|
+
import { articleSortByVsQuery as h } from "./search-params.js";
|
|
2
2
|
import "zod";
|
|
3
|
-
import { PAGE_SIZE as
|
|
4
|
-
class
|
|
3
|
+
import { PAGE_SIZE as p } from "../cfg.js";
|
|
4
|
+
class q {
|
|
5
5
|
db;
|
|
6
6
|
constructor(e) {
|
|
7
7
|
this.db = e;
|
|
@@ -11,25 +11,25 @@ class y {
|
|
|
11
11
|
* Includes its tags.
|
|
12
12
|
*/
|
|
13
13
|
async getBySlug(e) {
|
|
14
|
-
const { data: t, error:
|
|
15
|
-
if (
|
|
16
|
-
return console.error("Error fetching article details:",
|
|
17
|
-
const { data:
|
|
18
|
-
if (
|
|
14
|
+
const { data: t, error: r } = await this.db.from("articles").select("*").eq("slug", e).eq("status", "Published").single();
|
|
15
|
+
if (r)
|
|
16
|
+
return console.error("Error fetching article details:", r.message), null;
|
|
17
|
+
const { data: g, error: s } = await this.db.from("tag_articles").select("tag_id").eq("article_id", t.id);
|
|
18
|
+
if (s)
|
|
19
19
|
return console.error(
|
|
20
20
|
"Error fetching article tag links:",
|
|
21
|
-
|
|
21
|
+
s.message
|
|
22
22
|
), { ...t, tags: [] };
|
|
23
|
-
const n =
|
|
24
|
-
let
|
|
23
|
+
const n = g?.map((c) => c.tag_id) || [];
|
|
24
|
+
let o = [];
|
|
25
25
|
if (n.length > 0) {
|
|
26
|
-
const { data:
|
|
27
|
-
|
|
26
|
+
const { data: c, error: l } = await this.db.from("tags").select("name").in("id", n);
|
|
27
|
+
l ? console.error(
|
|
28
28
|
"Error fetching article tag names:",
|
|
29
|
-
|
|
30
|
-
) :
|
|
29
|
+
l.message
|
|
30
|
+
) : o = c.map((d) => d.name);
|
|
31
31
|
}
|
|
32
|
-
return { ...t, tags:
|
|
32
|
+
return { ...t, tags: o };
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* Get total number of articles.
|
|
@@ -46,45 +46,51 @@ class y {
|
|
|
46
46
|
*/
|
|
47
47
|
async getTagNames() {
|
|
48
48
|
const { data: e, error: t } = await this.db.from("tags").select("name");
|
|
49
|
-
return t ? (console.error("Error fetching tags:", t.message), []) : e?.map((
|
|
49
|
+
return t ? (console.error("Error fetching tags:", t.message), []) : e?.map((r) => r.name) ?? [];
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Paginated list of articles with filters and sorting.
|
|
53
53
|
*/
|
|
54
54
|
async list(e) {
|
|
55
|
-
const { page: t, search:
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
const { page: t, search: r, sortBy: g, tags: s } = e, n = h[g] ?? h.latest;
|
|
56
|
+
let o = this.db.from("article_with_tags").select("id").eq("status", "Published");
|
|
57
|
+
r && (o = o.ilike("title", `%${r}%`)), s && s.length > 0 && (o = o.in("tag", s));
|
|
58
|
+
const { data: c, error: l } = await o;
|
|
59
|
+
if (l)
|
|
60
|
+
return console.error("Count failed:", l), { items: [], total: 0 };
|
|
61
|
+
const d = new Set(c?.map((a) => a.id)).size;
|
|
62
|
+
let i = this.db.from("article_with_tags").select("*").eq("status", "Published");
|
|
63
|
+
r && (i = i.ilike("title", `%${r}%`)), s && s.length > 0 && (i = i.in("tag", s)), i = i.order(n.column, { ascending: n.ascending });
|
|
64
|
+
const u = t * p, _ = u + p - 1;
|
|
65
|
+
i = i.range(u, _);
|
|
66
|
+
const { data: b, error: f } = await i;
|
|
67
|
+
if (f)
|
|
68
|
+
return console.error("Error fetching paginated articles:", f), { items: [], total: 0 };
|
|
69
|
+
const m = /* @__PURE__ */ new Map();
|
|
70
|
+
for (const a of b ?? [])
|
|
71
|
+
m.has(a.id) || m.set(a.id, {
|
|
72
|
+
id: a.id,
|
|
73
|
+
title: a.title,
|
|
74
|
+
description: a.description,
|
|
75
|
+
slug: a.slug,
|
|
76
|
+
created_at: a.created_at,
|
|
77
|
+
banner_image: a.banner_image
|
|
72
78
|
});
|
|
73
79
|
return {
|
|
74
|
-
items: [...
|
|
75
|
-
total:
|
|
80
|
+
items: [...m.values()],
|
|
81
|
+
total: d
|
|
76
82
|
};
|
|
77
83
|
}
|
|
78
84
|
async getDescription(e) {
|
|
79
|
-
const { data: t, error:
|
|
80
|
-
return
|
|
85
|
+
const { data: t, error: r } = await this.db.storage.from("content").download(`articles/${e}/description.html`);
|
|
86
|
+
return r ? (console.error(
|
|
81
87
|
`Error fetching article description for article ID "${e}":`,
|
|
82
|
-
|
|
88
|
+
r.message
|
|
83
89
|
), null) : t ? await t.text() : (console.warn(
|
|
84
90
|
`No article description file found for article ID: ${e}`
|
|
85
91
|
), null);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
export {
|
|
89
|
-
|
|
95
|
+
q as ArticleService
|
|
90
96
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@k34a/blog",
|
|
3
3
|
"description": "Create and share articles with your audience.",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.18",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"dom-serializer": "^2.0.0",
|
|
59
|
-
"htmlparser2": "^10.0.0"
|
|
59
|
+
"htmlparser2": "^10.0.0",
|
|
60
|
+
"reading-time": "^1.5.0"
|
|
60
61
|
}
|
|
61
62
|
}
|