@riebeckite/plugin-recent-posts 0.0.24 → 0.0.26

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.
@@ -2,5 +2,5 @@ import type { RecentPost } from "../src/recent-posts.js";
2
2
  type Props = {
3
3
  posts?: RecentPost[];
4
4
  };
5
- export default function RecentPosts(props: Props): import("hono/jsx/jsx-dev-runtime").JSX.Element;
5
+ export default function RecentPosts(props: Props): Promise<import("hono/utils/html").HtmlEscapedString>;
6
6
  export {};
@@ -1,8 +1,40 @@
1
+ // components/recent-posts.tsx
2
+ import { useSiteContext } from "@riebeckite/ui";
3
+ import { html } from "hono/html";
4
+
5
+ // src/recent-posts.server.ts
6
+ var DEFAULT_RECENT_POSTS_LIMIT = 5;
7
+ function getRecentPosts(args) {
8
+ const limit = Math.max(0, args.limit ?? DEFAULT_RECENT_POSTS_LIMIT);
9
+ return args.manifest.discoverableEntries.filter((entry) => entry.slug !== "index").flatMap((entry) => {
10
+ const postedAt = parseFrontmatterDate(
11
+ entry.frontmatter.date ?? entry.frontmatter.created
12
+ );
13
+ if (!postedAt) return [];
14
+ return [
15
+ {
16
+ slug: entry.slug,
17
+ permalink: entry.permalink,
18
+ title: entry.title,
19
+ postedAt
20
+ }
21
+ ];
22
+ }).toSorted((a, b) => b.postedAt.getTime() - a.postedAt.getTime()).slice(0, limit);
23
+ }
24
+ function parseFrontmatterDate(value) {
25
+ if (value instanceof Date) return value;
26
+ if (typeof value !== "string") return null;
27
+ const date = new Date(value);
28
+ if (Number.isNaN(date.getTime())) return null;
29
+ return date;
30
+ }
31
+
1
32
  // components/recent-posts.tsx
2
33
  import { jsx, jsxs } from "hono/jsx/jsx-runtime";
3
- function RecentPosts(props) {
4
- const posts = props.posts ?? [];
5
- if (posts.length === 0) return null;
34
+ async function RecentPosts(props) {
35
+ const site = useSiteContext();
36
+ const posts = props.posts ?? (site ? await getRecentPosts({ manifest: site.manifest }) : []);
37
+ if (posts.length === 0) return html``;
6
38
  return /* @__PURE__ */ jsxs("section", { class: "rr-recent-posts", "aria-labelledby": "recent-posts-title", children: [
7
39
  /* @__PURE__ */ jsx("div", { class: "rr-recent-posts__header", children: /* @__PURE__ */ jsx("h2", { class: "rr-recent-posts__title", id: "recent-posts-title", children: "Recent Posts" }) }),
8
40
  /* @__PURE__ */ jsx("ol", { class: "rr-recent-posts__list", children: posts.map((post) => {
package/dist/index.js CHANGED
@@ -1,11 +1,43 @@
1
1
  // index.ts
2
2
  import { definePlugin } from "@riebeckite/core";
3
3
 
4
+ // components/recent-posts.tsx
5
+ import { useSiteContext } from "@riebeckite/ui";
6
+ import { html } from "hono/html";
7
+
8
+ // src/recent-posts.server.ts
9
+ var DEFAULT_RECENT_POSTS_LIMIT = 5;
10
+ function getRecentPosts(args) {
11
+ const limit = Math.max(0, args.limit ?? DEFAULT_RECENT_POSTS_LIMIT);
12
+ return args.manifest.discoverableEntries.filter((entry) => entry.slug !== "index").flatMap((entry) => {
13
+ const postedAt = parseFrontmatterDate(
14
+ entry.frontmatter.date ?? entry.frontmatter.created
15
+ );
16
+ if (!postedAt) return [];
17
+ return [
18
+ {
19
+ slug: entry.slug,
20
+ permalink: entry.permalink,
21
+ title: entry.title,
22
+ postedAt
23
+ }
24
+ ];
25
+ }).toSorted((a, b) => b.postedAt.getTime() - a.postedAt.getTime()).slice(0, limit);
26
+ }
27
+ function parseFrontmatterDate(value) {
28
+ if (value instanceof Date) return value;
29
+ if (typeof value !== "string") return null;
30
+ const date = new Date(value);
31
+ if (Number.isNaN(date.getTime())) return null;
32
+ return date;
33
+ }
34
+
4
35
  // components/recent-posts.tsx
5
36
  import { jsx, jsxs } from "hono/jsx/jsx-runtime";
6
- function RecentPosts(props) {
7
- const posts = props.posts ?? [];
8
- if (posts.length === 0) return null;
37
+ async function RecentPosts(props) {
38
+ const site = useSiteContext();
39
+ const posts = props.posts ?? (site ? await getRecentPosts({ manifest: site.manifest }) : []);
40
+ if (posts.length === 0) return html``;
9
41
  return /* @__PURE__ */ jsxs("section", { class: "rr-recent-posts", "aria-labelledby": "recent-posts-title", children: [
10
42
  /* @__PURE__ */ jsx("div", { class: "rr-recent-posts__header", children: /* @__PURE__ */ jsx("h2", { class: "rr-recent-posts__title", id: "recent-posts-title", children: "Recent Posts" }) }),
11
43
  /* @__PURE__ */ jsx("ol", { class: "rr-recent-posts__list", children: posts.map((post) => {
@@ -39,33 +71,6 @@ function formatPostedDate(date) {
39
71
  };
40
72
  }
41
73
 
42
- // src/recent-posts.server.ts
43
- var DEFAULT_RECENT_POSTS_LIMIT = 5;
44
- function getRecentPosts(args) {
45
- const limit = Math.max(0, args.limit ?? DEFAULT_RECENT_POSTS_LIMIT);
46
- return args.manifest.discoverableEntries.filter((entry) => entry.slug !== "index").flatMap((entry) => {
47
- const postedAt = parseFrontmatterDate(
48
- entry.frontmatter.date ?? entry.frontmatter.created
49
- );
50
- if (!postedAt) return [];
51
- return [
52
- {
53
- slug: entry.slug,
54
- permalink: entry.permalink,
55
- title: entry.title,
56
- postedAt
57
- }
58
- ];
59
- }).toSorted((a, b) => b.postedAt.getTime() - a.postedAt.getTime()).slice(0, limit);
60
- }
61
- function parseFrontmatterDate(value) {
62
- if (value instanceof Date) return value;
63
- if (typeof value !== "string") return null;
64
- const date = new Date(value);
65
- if (Number.isNaN(date.getTime())) return null;
66
- return date;
67
- }
68
-
69
74
  // index.ts
70
75
  function recentPostsPlugin() {
71
76
  return definePlugin({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-recent-posts",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "hono": "^4.12.25",
25
- "@riebeckite/core": "0.0.24"
25
+ "@riebeckite/core": "0.0.26",
26
+ "@riebeckite/ui": "0.0.26"
26
27
  },
27
28
  "devDependencies": {
28
29
  "tsx": "^4.22.4"