@k34a/blog 0.0.15 → 0.0.17

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/dist/cfg.js CHANGED
@@ -1,5 +1,4 @@
1
- "use client";
2
- const e = 12;
1
+ const o = 12;
3
2
  export {
4
- e as PAGE_SIZE
3
+ o as PAGE_SIZE
5
4
  };
@@ -1,7 +1,7 @@
1
- import { articleSortByVsQuery as u } from "./search-params.js";
1
+ import { articleSortByVsQuery as h } from "./search-params.js";
2
2
  import "zod";
3
- import { PAGE_SIZE as f } from "../cfg.js";
4
- class y {
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: a } = await this.db.from("articles").select("*").eq("slug", e).eq("status", "Published").single();
15
- if (a)
16
- return console.error("Error fetching article details:", a.message), null;
17
- const { data: d, error: i } = await this.db.from("tag_articles").select("tag_id").eq("article_id", t.id);
18
- if (i)
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
- i.message
21
+ s.message
22
22
  ), { ...t, tags: [] };
23
- const n = d?.map((o) => o.tag_id) || [];
24
- let r = [];
23
+ const n = g?.map((c) => c.tag_id) || [];
24
+ let o = [];
25
25
  if (n.length > 0) {
26
- const { data: o, error: c } = await this.db.from("tags").select("name").in("id", n);
27
- c ? console.error(
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
- c.message
30
- ) : r = o.map((l) => l.name);
29
+ l.message
30
+ ) : o = c.map((d) => d.name);
31
31
  }
32
- return { ...t, tags: r };
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((a) => a.name) ?? [];
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: a, sortBy: d, tags: i } = e, n = u[d] ?? u.latest;
56
- let r = this.db.from("article_with_tags").select("*", { count: "exact" }).eq("status", "Published");
57
- a && (r = r.ilike("title", `%${a}%`)), i && i.length > 0 && (r = r.in("tag", i)), r = r.order(n.column, { ascending: n.ascending });
58
- const o = t * f, c = o + f - 1;
59
- console.log({ from: o, to: c }), r = r.range(o, c);
60
- const { data: l, error: m, count: h } = await r;
61
- if (console.log({ data: l, error: m, count: h }), m)
62
- return console.error("Error fetching articles:", m), { items: [], total: 0 };
63
- const g = /* @__PURE__ */ new Map();
64
- for (const s of l ?? [])
65
- g.has(s.id) || g.set(s.id, {
66
- id: s.id,
67
- title: s.title,
68
- description: s.description,
69
- slug: s.slug,
70
- created_at: s.created_at,
71
- banner_image: s.banner_image
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: [...g.values()],
75
- total: Object.keys(g).length
80
+ items: [...m.values()],
81
+ total: d
76
82
  };
77
83
  }
78
84
  async getDescription(e) {
79
- const { data: t, error: a } = await this.db.storage.from("content").download(`articles/${e}/description.html`);
80
- return a ? (console.error(
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
- a.message
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
- y as ArticleService
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.15",
5
+ "version": "0.0.17",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {