From db0836a4996a1f0f8d7665ce4a064679a24e9d5c Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Mon, 18 Nov 2024 22:44:52 -0500 Subject: [PATCH] Work on the feed generator to use the PostService. --- bun.lockb | Bin 30384 -> 30384 bytes src/services/feed-generator.ts | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/bun.lockb b/bun.lockb index 9f740604e14fee9bfe52edb3b6174d5350b8dc2a..60574a51535752a65dbb977ab7b03e011547b0ad 100755 GIT binary patch delta 21 bcmdn+mT?0R{q$vLj5E|T)-%}Tw?P8{X!i(V delta 21 Xcmdn+mT?0R{q$vLVgQ3pej79ZUc?6! diff --git a/src/services/feed-generator.ts b/src/services/feed-generator.ts index 532e217..989caa6 100644 --- a/src/services/feed-generator.ts +++ b/src/services/feed-generator.ts @@ -1,4 +1,41 @@ import { Feed, FeedOptions } from 'feed'; import { getSiteConfig } from '@blog/services/config'; +import { PostService } from '@blog/services/post-file'; +import type { Post } from '@blog/models/post'; +const updatedDate = new Date(); + +export async function getFeed(postService: PostService): Feed { + const config = getSiteConfig(); + const feed = new Feed({ + title: config.title, + description: config.site.description, + link: config.site.link, + language: config.site.language, + copyright: config.site.copyright, + generator: "dsh feed gen", + updated: updatedDate, + author: { + name: "Dave Smith-Hayes", + email: "me@davesmithhayes.com", + link: "davesmithhayes.com" + } + }); + + postService.getAllPosts().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: [ + name: config.author, + email: config.email + ] + }); + }); + + return feed; +}