Compare commits

...

7 Commits

9 changed files with 118 additions and 0 deletions

BIN
bun.lockb

Binary file not shown.

12
config/site.toml Normal file
View 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"

View File

@ -5,11 +5,13 @@
}, },
"dependencies": { "dependencies": {
"@types/yaml-front-matter": "^4.1.3", "@types/yaml-front-matter": "^4.1.3",
"feed": "^4.2.2",
"highlight.js": "^11.10.0", "highlight.js": "^11.10.0",
"hono": "^4.4.13", "hono": "^4.4.13",
"marked": "^13.0.2", "marked": "^13.0.2",
"marked-highlight": "^2.1.3", "marked-highlight": "^2.1.3",
"remark": "^15.0.1", "remark": "^15.0.1",
"smol-toml": "^1.3.0",
"yaml-front-matter": "^4.1.1" "yaml-front-matter": "^4.1.1"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,3 +1,4 @@
export const POST_PATH: string = __dirname + '/../posts'; export const POST_PATH: string = __dirname + '/../posts';
export const CONFIG_PATH: string = __dirname + '/../config';
export const STATIC_PATH: string = __dirname + '/assets'; export const STATIC_PATH: string = __dirname + '/assets';
export const POST_ROUTE_PREFIX: string = '/posts' export const POST_ROUTE_PREFIX: string = '/posts'

26
src/handlers/feed.ts Normal file
View 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;

View File

@ -1,3 +1,6 @@
/**
* SiteMeta is often used for the `<meta />` tags in the document header
*/
export type SiteMeta = { export type SiteMeta = {
description?: string, description?: string,
tags?: string[], tags?: string[],

View 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
View 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;
}

View 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;
}