@k34a/blog 0.0.12 → 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.
@@ -1,6 +1,6 @@
1
- import { articleSortByVsQuery as p } from "./search-params.js";
1
+ import { articleSortByVsQuery as _ } from "./search-params.js";
2
2
  import "zod";
3
- import { PAGE_SIZE as _ } from "../cfg.js";
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: c, error: s } = await this.db.from("tag_articles").select("tag_id").eq("article_id", t.id);
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 o = c?.map((i) => i.tag_id) || [];
23
+ const i = l?.map((o) => o.tag_id) || [];
24
24
  let e = [];
25
- if (o.length > 0) {
26
- const { data: i, error: n } = await this.db.from("tags").select("name").in("id", o);
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 = i.map((l) => l.name);
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: c, tags: s } = r, o = p[c] ?? p.latest;
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: d, error: f } = await this.db.from("tags").select("id").in("name", s);
59
- if (f || !d?.length)
60
- return console.error("Error fetching tag IDs:", f?.message), { items: [], total: 0 };
61
- const w = d.map((g) => g.id), { data: u, error: h } = await this.db.from("tag_articles").select("article_id").in("tag_id", w);
62
- if (h || !u?.length)
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
- h?.message
65
+ b?.message
66
66
  ), { items: [], total: 0 };
67
- const b = Array.from(
68
- new Set(u.map((g) => g.article_id))
67
+ const p = Array.from(
68
+ new Set(h.map((m) => m.article_id))
69
69
  );
70
- if (b.length === 0)
70
+ if (p.length === 0)
71
71
  return { items: [], total: 0 };
72
- e = e.in("id", b);
72
+ e = e.in("id", p);
73
73
  }
74
- e = e.order(o.column, { ascending: o.ascending });
75
- const i = t * _, n = i + _ - 1;
76
- e = e.range(i, n);
77
- const { data: l, error: m, count: E } = await e;
78
- return m ? (console.error("Error fetching articles:", m), { items: [], total: 0 }) : {
79
- items: l || [],
80
- total: E || 0
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) {
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.12",
5
+ "version": "0.0.13",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {