@guzhongren/sha 0.1.2 → 0.1.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@guzhongren/sha",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "个人 Astro 博客主题 — 开箱即用的内容驱动博客",
6
6
  "license": "MIT",
@@ -28,13 +28,14 @@
28
28
  "./styles.css": "./src/styles/global.css"
29
29
  },
30
30
  "peerDependencies": {
31
- "astro": "^7.1.3",
32
- "@astrojs/mdx": "^7.0.0",
33
31
  "@astrojs/markdown-remark": "^7.0.0",
32
+ "@astrojs/mdx": "^7.0.0",
34
33
  "@tailwindcss/vite": "^4.0.0",
34
+ "astro": "^7.1.3",
35
35
  "tailwindcss": "^4.0.0"
36
36
  },
37
37
  "dependencies": {
38
+ "@astrojs/rss": "^4.0.19",
38
39
  "echarts": "^6.1.0",
39
40
  "gemoji": "^8.1.0",
40
41
  "mermaid": "^11.16.0",
package/src/config.ts CHANGED
@@ -49,6 +49,7 @@ export function normalizeOptions(options: BlogThemeOptions): NormalizedBlogTheme
49
49
  categories: false,
50
50
  about: false,
51
51
  search: false,
52
+ rss: false,
52
53
  }
53
54
  : {
54
55
  home: options.routes?.home ?? true,
@@ -57,6 +58,7 @@ export function normalizeOptions(options: BlogThemeOptions): NormalizedBlogTheme
57
58
  categories: options.routes?.categories ?? true,
58
59
  about: options.routes?.about ?? true,
59
60
  search: options.routes?.search ?? true,
61
+ rss: options.routes?.rss ?? true,
60
62
  },
61
63
  };
62
64
  }
package/src/index.ts CHANGED
@@ -100,6 +100,7 @@ export default function blogTheme(options: BlogThemeOptions): AstroIntegration {
100
100
  }
101
101
  if (config.routes.about) injectRoute({ pattern: "/about", entrypoint: route("./pages/about.astro") });
102
102
  if (config.routes.search) injectRoute({ pattern: "/search", entrypoint: route("./pages/search.astro") });
103
+ if (config.routes.rss) injectRoute({ pattern: "/rss.xml", entrypoint: route("./pages/rss.xml.ts") });
103
104
  },
104
105
  "astro:build:done": async ({ dir }) => {
105
106
  if (!config.routes.search) return;
@@ -0,0 +1,22 @@
1
+ import rss from "@astrojs/rss";
2
+ import { getCollection } from "astro:content";
3
+ import config from "virtual:blog-theme/config";
4
+ import { isPublished, sortPosts, postHref } from "../utils";
5
+
6
+ export async function GET(context: { site: URL }) {
7
+ const posts = sortPosts((await getCollection("posts")).filter(isPublished));
8
+
9
+ return rss({
10
+ xmlns: { atom: "http://www.w3.org/2005/Atom" },
11
+ title: config.site.title,
12
+ description: config.site.description,
13
+ site: context.site,
14
+ items: posts.map((post) => ({
15
+ title: post.data.title,
16
+ description: post.data.description,
17
+ pubDate: post.data.publishDate ?? new Date(),
18
+ link: postHref(post),
19
+ })),
20
+ customData: `<language>${config.site.lang}</language>`,
21
+ });
22
+ }
package/src/types.ts CHANGED
@@ -46,6 +46,7 @@ export type BlogThemeOptions = {
46
46
  categories?: boolean;
47
47
  about?: boolean;
48
48
  search?: boolean;
49
+ rss?: boolean;
49
50
  };
50
51
  };
51
52
 
@@ -90,5 +91,6 @@ export type NormalizedBlogThemeOptions = {
90
91
  categories: boolean;
91
92
  about: boolean;
92
93
  search: boolean;
94
+ rss: boolean;
93
95
  };
94
96
  };