diff --git a/bun.lockb b/bun.lockb index 60574a5..bcde764 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cec3596..60e6a8e 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "@types/yaml-front-matter": "^4.1.3", "feed": "^4.2.2", "highlight.js": "^11.10.0", - "hono": "^4.4.13", - "marked": "^13.0.2", - "marked-highlight": "^2.1.3", + "hono": "^4.6.13", + "marked": "^13.0.3", + "marked-highlight": "^2.2.1", "remark": "^15.0.1", - "smol-toml": "^1.3.0", + "smol-toml": "^1.3.1", "yaml-front-matter": "^4.1.1" }, "devDependencies": { diff --git a/src/handlers/feed.ts b/src/handlers/feed.ts index e411cff..b40e266 100644 --- a/src/handlers/feed.ts +++ b/src/handlers/feed.ts @@ -1,25 +1,20 @@ import { Hono, Context } from 'hono'; import { PostService } from '@blog/services/post-file'; +import { getFeed } from '@blog/services/feed-generator'; import { Feed } from 'feed'; const feed = new Hono<{ Variables: { postService: PostService }}>(); let feedBuffer: string = ""; export async function getFeedFile(c: Context) { - c.header('Content-Type', 'text/xml'); - if (!feedBuffer) { const postService: PostService = c.get('postService'); - const posts = postService.getPublishedPosts(); - - // get the site meta - - // create the feed - // get the feed data - feedBuffer = ""; + const feed: Feed = await getFeed(postService); + feedBuffer = feed.rss2(); } - - c.body(feedBuffer); + + c.header('Content-Type', 'text/xml'); + return c.body(feedBuffer); } feed.get('/rss.xml', getFeedFile); diff --git a/src/index.tsx b/src/index.tsx index c3a0627..8a22c4e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,6 +4,7 @@ import { serveStatic } from 'hono/bun'; import { Page } from '@blog/templates/Page'; import home from '@blog/handlers/home'; import posts from '@blog/handlers/posts'; +import feed from '@blog/handlers/feed'; import type { SiteMeta } from '@blog/models/SiteMeta'; import { postFileMiddleware } from '@blog/middleware/post-service'; import { logger } from 'hono/logger'; @@ -36,6 +37,7 @@ app.use('/static/*', serveStatic({ })); app.route('/', home); +app.route('/feed', feed) app.route('/posts', posts); console.log("Starting the blog"); diff --git a/src/services/feed-generator.ts b/src/services/feed-generator.ts index 989caa6..72e113c 100644 --- a/src/services/feed-generator.ts +++ b/src/services/feed-generator.ts @@ -6,7 +6,7 @@ import type { Post } from '@blog/models/post'; const updatedDate = new Date(); export async function getFeed(postService: PostService): Feed { - const config = getSiteConfig(); + const config = await getSiteConfig(); const feed = new Feed({ title: config.title, description: config.site.description, @@ -22,20 +22,20 @@ export async function getFeed(postService: PostService): Feed { } }); - postService.getAllPosts().map((post: Post) => { + postService.getPublishedPosts().map((post: Post) => { feed.addItem({ title: post.meta.title, id: post.meta.slug, link: post.meta.slug, description: post.meta.description, content: post.html, - author: [ + author: { name: config.author, email: config.email - ] + } }); }); return feed; -} +};