Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
db0836a499 | |||
4c78f3f83e | |||
e21de55d3f | |||
34a215eb7b | |||
21fb068901 | |||
ab5a83202e | |||
c8b5f72657 |
12
config/site.toml
Normal file
12
config/site.toml
Normal file
@ -0,0 +1,12 @@
|
||||
title = "davesmithhayes.com"
|
||||
|
||||
[owner]
|
||||
name = "Dave Smith-Hayes"
|
||||
email = "me@davesmithhayes.com"
|
||||
|
||||
[site]
|
||||
description = "Personal website of Dave Smith-Hayes - a father, developer, and musician."
|
||||
url = "https://davesmithhayes.com"
|
||||
repo = "https://git.davesmithhayes.com/dsh/blog"
|
||||
language = "en"
|
||||
copyright = "All rights reserved, Dave Smith-Hayes"
|
@ -5,11 +5,13 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@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",
|
||||
"remark": "^15.0.1",
|
||||
"smol-toml": "^1.3.0",
|
||||
"yaml-front-matter": "^4.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,3 +1,4 @@
|
||||
export const POST_PATH: string = __dirname + '/../posts';
|
||||
export const CONFIG_PATH: string = __dirname + '/../config';
|
||||
export const STATIC_PATH: string = __dirname + '/assets';
|
||||
export const POST_ROUTE_PREFIX: string = '/posts'
|
||||
|
26
src/handlers/feed.ts
Normal file
26
src/handlers/feed.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Hono, Context } from 'hono';
|
||||
import { PostService } from '@blog/services/post-file';
|
||||
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 = "";
|
||||
}
|
||||
|
||||
c.body(feedBuffer);
|
||||
}
|
||||
|
||||
feed.get('/rss.xml', getFeedFile);
|
||||
export default feed;
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* SiteMeta is often used for the `<meta />` tags in the document header
|
||||
*/
|
||||
export type SiteMeta = {
|
||||
description?: string,
|
||||
tags?: string[],
|
||||
|
9
src/services/config.test.ts
Normal file
9
src/services/config.test.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import { getSiteConfig } from '@blog/services/config';
|
||||
|
||||
describe("Test the global config for the site", () => {
|
||||
test("Parses the Owner", async () => {
|
||||
const siteConfig = await getSiteConfig();
|
||||
expect(siteConfig.owner.email).toBe("me@davesmithhayes.com");
|
||||
})
|
||||
})
|
24
src/services/config.ts
Normal file
24
src/services/config.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import TOML from 'smol-toml';
|
||||
import { CONFIG_PATH } from '@blog/config';
|
||||
|
||||
export type SiteConfig = {
|
||||
title: string;
|
||||
owner: {
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
site: {
|
||||
description: string;
|
||||
url: string;
|
||||
repo: string;
|
||||
language: string;
|
||||
copyright: string;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSiteConfig(): Promise<SiteConfig> {
|
||||
const siteConfig = CONFIG_PATH + '/site.toml';
|
||||
const file = Bun.file(siteConfig);
|
||||
const data = await file.text();
|
||||
return TOML.parse(data) as SiteConfig;
|
||||
}
|
41
src/services/feed-generator.ts
Normal file
41
src/services/feed-generator.ts
Normal file
@ -0,0 +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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user