Add site meta to templates.

This commit is contained in:
Dave Smith-Hayes 2024-07-03 21:48:29 -04:00
parent 76066ddae1
commit f25d9aed56
5 changed files with 19 additions and 10 deletions

View File

@ -1,5 +1,5 @@
export type SiteMeta = {
description: string,
tags: string[],
description?: string,
tags?: string[],
author?: string,
};

View File

@ -1,9 +1,9 @@
import { Hono } from 'hono';
import { PostPage } from '@blog/templates/Pages/PostPage';
import { FourOhFour } from '@blog/templates/Pages/FourOhFour';
import { readdir } from 'node:fs/promises';
import { readPostMarkdown } from '@blog/util/readPostMarkdown';
import { SiteMeta } from '@blog/model/SiteMeta';
import { readPostMarkdown } from '@blog/util/post-reader';
const app = new Hono();
@ -18,8 +18,14 @@ app.get('/posts/:slug', async (c) => {
return c.render(<FourOhFour />);
}
const post = await readPostMarkdown(__dirname + "/../posts/" + postFile);
return c.render(<PostPage post={post} />);
const post = await readPostMarkdown(postFile);
const meta = {
description: post.meta.description,
tags: post.meta.tags,
author: "Dave Smith-Hayes"
};
return c.render(<PostPage post={post} />, { meta });
});
export default app;

View File

@ -1,5 +1,6 @@
import { css, Style } from 'hono/css';
import { SiteMeta } from '@blog/model/SiteMeta';
import { MetaTags } from '@blog/templates/components/MetaTags';
const logoClass = css`
font-size: 16pt;
@ -10,6 +11,7 @@ export function Page({ children, meta }: { children: any, meta: SiteMeta }) {
<html lang="en">
<head>
<title>davesmithhayes.com</title>
<MetaTags meta={meta} />
<Style />
</head>
<body>

View File

@ -1,10 +1,10 @@
import { Post } from "@blog/templates/Pages";
import { Post } from "@blog/model/Post";
export function PostPage({ post }: { post: Post }) {
const html = { __html: post.content };
const html = { __html: post.html ?? '' };
return (
<>
<h1>{post.title}</h1>
<h1>{post.meta.title}</h1>
<div dangerouslySetInnerHTML={html} />
</>
);

View File

@ -24,11 +24,12 @@ export function Author({ meta }: { meta: SiteMeta }) {
return (<meta name="author" content={meta.author} />);
}
export function MetaTags(meta: SiteMeta) {
export function MetaTags({ meta }: { meta: SiteMeta }) {
return (
<>
<Description meta={meta} />
<Tags meta={meta} />
<Author meta={meta} />
</>
)
}