@k34a/blog 0.0.11 → 0.0.13
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
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
/* @__PURE__ */
|
|
11
|
-
|
|
12
|
-
h,
|
|
2
|
+
import { jsx as i, jsxs as r } from "react/jsx-runtime";
|
|
3
|
+
import { Box as t, Stack as a, Title as c, Flex as l, Badge as m } from "@mantine/core";
|
|
4
|
+
import { IconHash as o } from "@tabler/icons-react";
|
|
5
|
+
import { BannerImage as d } from "./banner-image.js";
|
|
6
|
+
import f from "./description.js";
|
|
7
|
+
function b(e) {
|
|
8
|
+
return /* @__PURE__ */ i(t, { maw: 800, mx: "auto", px: "sm", py: "lg", children: /* @__PURE__ */ r(a, { gap: "md", children: [
|
|
9
|
+
/* @__PURE__ */ i(c, { order: 1, children: e.title }),
|
|
10
|
+
e.banner_image && /* @__PURE__ */ i(
|
|
11
|
+
d,
|
|
13
12
|
{
|
|
14
|
-
id:
|
|
15
|
-
src:
|
|
16
|
-
title:
|
|
17
|
-
config:
|
|
13
|
+
id: e.id,
|
|
14
|
+
src: e.banner_image,
|
|
15
|
+
title: e.title,
|
|
16
|
+
config: e.config
|
|
18
17
|
}
|
|
19
18
|
),
|
|
20
|
-
/* @__PURE__ */
|
|
21
|
-
|
|
19
|
+
/* @__PURE__ */ i(
|
|
20
|
+
f,
|
|
22
21
|
{
|
|
23
|
-
articleId:
|
|
24
|
-
html:
|
|
25
|
-
config:
|
|
22
|
+
articleId: e.id,
|
|
23
|
+
html: e.description,
|
|
24
|
+
config: e.config
|
|
26
25
|
}
|
|
27
26
|
),
|
|
28
|
-
/* @__PURE__ */
|
|
29
|
-
|
|
27
|
+
/* @__PURE__ */ i(l, { wrap: "wrap", gap: "md", align: "center", mb: "lg", children: e.tags.map((n) => /* @__PURE__ */ i("a", { href: n.href, children: /* @__PURE__ */ i(
|
|
28
|
+
m,
|
|
30
29
|
{
|
|
31
30
|
size: "md",
|
|
32
31
|
color: "sky.5",
|
|
33
32
|
variant: "outline",
|
|
34
|
-
leftSection: /* @__PURE__ */
|
|
33
|
+
leftSection: /* @__PURE__ */ i(o, { size: 14 }),
|
|
35
34
|
style: { cursor: "pointer" },
|
|
36
|
-
children: n
|
|
35
|
+
children: n.name
|
|
37
36
|
}
|
|
38
|
-
) }, n)) })
|
|
37
|
+
) }, n.name)) })
|
|
39
38
|
] }) });
|
|
40
39
|
}
|
|
41
40
|
export {
|
|
42
|
-
|
|
41
|
+
b as default
|
|
43
42
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { articleSortByVsQuery as
|
|
1
|
+
import { articleSortByVsQuery as _ } from "./search-params.js";
|
|
2
2
|
import "zod";
|
|
3
|
-
import { PAGE_SIZE as
|
|
3
|
+
import { PAGE_SIZE as E } from "../cfg.js";
|
|
4
4
|
class D {
|
|
5
5
|
db;
|
|
6
6
|
constructor(r) {
|
|
@@ -14,20 +14,20 @@ class D {
|
|
|
14
14
|
const { data: t, error: a } = await this.db.from("articles").select("*").eq("slug", r).eq("status", "Published").single();
|
|
15
15
|
if (a)
|
|
16
16
|
return console.error("Error fetching article details:", a.message), null;
|
|
17
|
-
const { data:
|
|
17
|
+
const { data: l, error: s } = await this.db.from("tag_articles").select("tag_id").eq("article_id", t.id);
|
|
18
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
|
|
23
|
+
const i = l?.map((o) => o.tag_id) || [];
|
|
24
24
|
let e = [];
|
|
25
|
-
if (
|
|
26
|
-
const { data:
|
|
25
|
+
if (i.length > 0) {
|
|
26
|
+
const { data: o, error: n } = await this.db.from("tags").select("name").in("id", i);
|
|
27
27
|
n ? console.error(
|
|
28
28
|
"Error fetching article tag names:",
|
|
29
29
|
n.message
|
|
30
|
-
) : e =
|
|
30
|
+
) : e = o.map((c) => c.name);
|
|
31
31
|
}
|
|
32
32
|
return { ...t, tags: e };
|
|
33
33
|
}
|
|
@@ -52,32 +52,32 @@ class D {
|
|
|
52
52
|
* Paginated list of articles with filters and sorting.
|
|
53
53
|
*/
|
|
54
54
|
async list(r) {
|
|
55
|
-
const { page: t, search: a, sortBy:
|
|
55
|
+
const { page: t, search: a, sortBy: l, tags: s } = r, i = _[l] ?? _.latest;
|
|
56
56
|
let e = this.db.from("articles").select("*", { count: "exact" }).eq("status", "Published");
|
|
57
57
|
if (a && (e = e.ilike("title", `%${a}%`)), s && s.length > 0) {
|
|
58
|
-
const { data:
|
|
59
|
-
if (
|
|
60
|
-
return console.error("Error fetching tag IDs:",
|
|
61
|
-
const w =
|
|
62
|
-
if (
|
|
58
|
+
const { data: f, error: u } = await this.db.from("tags").select("id").in("name", s);
|
|
59
|
+
if (u || !f?.length)
|
|
60
|
+
return console.error("Error fetching tag IDs:", u?.message), { items: [], total: 0 };
|
|
61
|
+
const w = f.map((m) => m.id), { data: h, error: b } = await this.db.from("tag_articles").select("article_id").in("tag_id", w);
|
|
62
|
+
if (b || !h?.length)
|
|
63
63
|
return console.error(
|
|
64
64
|
"Error fetching articles by tags:",
|
|
65
|
-
|
|
65
|
+
b?.message
|
|
66
66
|
), { items: [], total: 0 };
|
|
67
|
-
const
|
|
68
|
-
new Set(
|
|
67
|
+
const p = Array.from(
|
|
68
|
+
new Set(h.map((m) => m.article_id))
|
|
69
69
|
);
|
|
70
|
-
if (
|
|
70
|
+
if (p.length === 0)
|
|
71
71
|
return { items: [], total: 0 };
|
|
72
|
-
e = e.in("id",
|
|
72
|
+
e = e.in("id", p);
|
|
73
73
|
}
|
|
74
|
-
e = e.order(
|
|
75
|
-
const
|
|
76
|
-
e = e.range(
|
|
77
|
-
const { data:
|
|
78
|
-
return
|
|
79
|
-
items:
|
|
80
|
-
total:
|
|
74
|
+
e = e.order(i.column, { ascending: i.ascending });
|
|
75
|
+
const o = t * E, n = o + E - 1;
|
|
76
|
+
e = e.range(o, n);
|
|
77
|
+
const { data: c, error: g, count: d } = await e;
|
|
78
|
+
return console.log({ data: c, error: g, count: d }), g ? (console.error("Error fetching articles:", g), { items: [], total: 0 }) : {
|
|
79
|
+
items: c || [],
|
|
80
|
+
total: d || 0
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
async getDescription(r) {
|