Color mode

Recent Posts

Recent posts list rendering: shows the latest published notes sorted by frontmatter date.

日本語

Overview

recentPosts() provides a RecentPosts component that renders an ordered list of recently posted articles. getRecentPosts() reads manifest.discoverableEntries, so unlisted, draft, and scheduled notes are excluded. It derives a date from the frontmatter (date falling back to created), sorts newest first, and truncates to limit items. Notes without a parseable date are dropped. Whether and where to place the list is the site's decision.

With no posts, the component renders nothing.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { recentPostsPlugin } from "@riebeckite/plugin-recent-posts";
 
export default defineConfig({
  // ...
  plugins: [recentPostsPlugin()],
});

recentPostsPlugin() registers the plugin in the plugin list and bundles style.css into the app stylesheet.

Render the component

tsx
import RecentPosts, { getRecentPosts } from "@riebeckite/plugin-recent-posts";
import { content } from "../content";
 
const recentPosts = getRecentPosts({ manifest: await content.getManifest() });
 
// ...in your route
return <Article afterContent={<RecentPosts posts={recentPosts} />} />;

getRecentPosts() filters out the index note before collecting posts.

Component

RecentPosts({ posts }) renders a <section class="recent-posts rr-recent-posts"> with a heading and an ordered list. Each item links to the post and shows its date formatted for the en-US locale. The rr-recent-posts root hook is the stable class themes may target.

Options

Option Type Default Description
manifest Pick<ContentManifest, "discoverableEntries"> — Source of candidate posts
limit number 5 Maximum number of posts to return

Exports

  • recentPostsPlugin() — plugin factory
  • RecentPosts — list component (default export of components/recent-posts.tsx)
  • getRecentPosts({ manifest, limit? }) — collects the latest discoverable posts
  • Type: RecentPost ({ slug, permalink, title, postedAt })

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/recent-posts/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Recent Posts
4 +
5 + Recent posts list rendering: shows the latest published notes sorted by
6 + frontmatter date.
7 +
8 + [日本語](./recent-posts.md)
9 +
10 + ## Overview
11 +
12 + `recentPosts()` provides a `RecentPosts` component that renders an ordered list
13 + of recently posted articles. `getRecentPosts()` reads
14 + `manifest.discoverableEntries`, so `unlisted`, `draft`, and scheduled notes are
15 + excluded. It derives a date from the frontmatter (`date` falling back to
16 + `created`), sorts newest first, and truncates to `limit` items. Notes without a
17 + parseable date are dropped. Whether and where to place the list is the site's
18 + decision.
19 +
20 + With no posts, the component renders nothing.
21 +
22 + ## Usage
23 +
24 + ```ts
25 + import { defineConfig } from "@riebeckite/core";
26 + import { recentPostsPlugin } from "@riebeckite/plugin-recent-posts";
27 +
28 + export default defineConfig({
29 + // ...
30 + plugins: [recentPostsPlugin()],
31 + });
32 + ```
33 +
34 + `recentPostsPlugin()` registers the plugin in the plugin list and bundles
35 + `style.css` into the app stylesheet.
36 +
37 + ### Render the component
38 +
39 + ```tsx
40 + import RecentPosts, { getRecentPosts } from "@riebeckite/plugin-recent-posts";
41 + import { content } from "../content";
42 +
43 + const recentPosts = getRecentPosts({ manifest: await content.getManifest() });
44 +
45 + // ...in your route
46 + return <Article afterContent={<RecentPosts posts={recentPosts} />} />;
47 + ```
48 +
49 + `getRecentPosts()` filters out the `index` note before collecting posts.
50 +
51 + ## Component
52 +
53 + `RecentPosts({ posts })` renders a
54 + `<section class="recent-posts rr-recent-posts">` with a heading and an ordered
55 + list. Each item links to the post and shows its date formatted for the
56 + `en-US` locale. The `rr-recent-posts` root hook is the stable class themes may
57 + target.
58 +
59 + ## Options
60 +
61 + | Option | Type | Default | Description |
62 + | ------ | ---- | ------- | ----------- |
63 + | `manifest` | `Pick<ContentManifest, "discoverableEntries">` | — | Source of candidate posts |
64 + | `limit` | `number` | `5` | Maximum number of posts to return |
65 +
66 + ## Exports
67 +
68 + - `recentPostsPlugin()` — plugin factory
69 + - `RecentPosts` — list component (default export of `components/recent-posts.tsx`)
70 + - `getRecentPosts({ manifest, limit? })` — collects the latest discoverable
71 + posts
72 + - Type: `RecentPost` (`{ slug, permalink, title, postedAt }`)
73 +
74 + ## See also
75 +
76 + - [Plugin guide](../reference/plugin-api.en.md)
77 +