Add a Site TOML, the TOML parser, Feed generator, and a small test for parsing the site TOML.

This commit is contained in:
Dave Smith-Hayes 2024-10-22 20:44:00 -04:00
parent 9df6a10ed3
commit c8b5f72657
7 changed files with 48 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'

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");
})
})

10
src/services/config.ts Normal file
View File

@ -0,0 +1,10 @@
import TOML from 'smol-toml';
import { CONFIG_PATH } from '@blog/config';
export async function getSiteConfig() {
const siteConfig = CONFIG_PATH + '/site.toml';
const file = Bun.file(siteConfig);
const data = await file.text();
return TOML.parse(data);
}

View File

@ -0,0 +1,14 @@
// generate the feed
//
import { Feed, FeedOptions } from 'feed';
export async function feedFactory(): Feed {
}
export async function generateFeed(posts: PostService, feed: Feed): Feed {
const feed = new Feed({});
return feed;
}