@karaoke-cms/module-blog 0.9.7 → 0.9.8

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@karaoke-cms/module-blog",
3
3
  "type": "module",
4
- "version": "0.9.7",
4
+ "version": "0.9.8",
5
5
  "description": "Blog module for karaoke-cms — posts, tags, RSS",
6
6
  "main": "./src/index.ts",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
9
  "./schema": "./src/schema.ts",
10
+ "./pages/list": "./src/pages/list.astro",
10
11
  "./pages/post": "./src/pages/post.astro",
11
12
  "./pages/page": "./src/pages/page/[page].astro",
12
13
  "./components/FeaturedPost": "./src/components/FeaturedPost.astro",
@@ -27,7 +28,7 @@
27
28
  },
28
29
  "peerDependencies": {
29
30
  "astro": ">=6.0.0",
30
- "@karaoke-cms/astro": "^0.9.7"
31
+ "@karaoke-cms/astro": "^0.9.8"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@karaoke-cms/astro": "workspace:*",
package/src/index.ts CHANGED
@@ -28,8 +28,9 @@ export const blog = defineModule({
28
28
  defaultCssPath: join(_srcDir, 'styles', 'blog.css'),
29
29
 
30
30
  routes: (mount) => [
31
- { pattern: `${mount}/[slug]`, entrypoint: '@karaoke-cms/module-blog/pages/post' },
32
- { pattern: `${mount}/page/[page]`, entrypoint: '@karaoke-cms/module-blog/pages/page' },
31
+ { pattern: mount, entrypoint: '@karaoke-cms/module-blog/pages/list' },
32
+ { pattern: `${mount}/[slug]`, entrypoint: '@karaoke-cms/module-blog/pages/post' },
33
+ { pattern: `${mount}/page/[page]`, entrypoint: '@karaoke-cms/module-blog/pages/page' },
33
34
  ],
34
35
 
35
36
  menuEntries: (mount, id) => [
@@ -40,7 +41,8 @@ export const blog = defineModule({
40
41
  scaffoldPages: (mount) => {
41
42
  const mountDir = mount.replace(/^\//, '') || 'blog';
42
43
  return [
43
- { src: join(_srcDir, 'pages', 'post.astro'), dest: `${mountDir}/[slug].astro` },
44
+ { src: join(_srcDir, 'pages', 'list.astro'), dest: `${mountDir}/index.astro` },
45
+ { src: join(_srcDir, 'pages', 'post.astro'), dest: `${mountDir}/[slug].astro` },
44
46
  { src: join(_srcDir, 'pages', 'page', '[page].astro'), dest: `${mountDir}/page/[page].astro` },
45
47
  ];
46
48
  },
@@ -0,0 +1,26 @@
1
+ ---
2
+ import { getCollection } from 'astro:content';
3
+ import DefaultPage from '@karaoke-cms/astro/layouts/DefaultPage.astro';
4
+ import PaginatedPostList from '@karaoke-cms/module-blog/components/PaginatedPostList';
5
+ import RecentPosts from '@karaoke-cms/module-blog/components/RecentPosts';
6
+ import { siteTitle, blogMount } from 'virtual:karaoke-cms/config';
7
+
8
+ const PAGE_SIZE = 10;
9
+ const allPosts = (await getCollection('blog', ({ data }) => data.publish === true))
10
+ .sort((a, b) => (b.data.date?.valueOf() ?? 0) - (a.data.date?.valueOf() ?? 0));
11
+
12
+ const totalPages = Math.max(1, Math.ceil(allPosts.length / PAGE_SIZE));
13
+ const posts = allPosts.slice(0, PAGE_SIZE);
14
+ ---
15
+
16
+ <DefaultPage title={`Blog — ${siteTitle}`}>
17
+ {posts.length > 0 ? (
18
+ <PaginatedPostList posts={posts} mount={blogMount} currentPage={1} totalPages={totalPages} />
19
+ ) : (
20
+ <div class="empty-state">
21
+ <p>No posts published yet.</p>
22
+ <p>Create a Markdown file in your vault's <code>blog/</code> folder and set <code>publish: true</code> in the frontmatter to make it appear here.</p>
23
+ </div>
24
+ )}
25
+ <RecentPosts mount={blogMount} slot="right" />
26
+ </DefaultPage>