diff --git a/src/assets/static/main.css b/src/assets/static/main.css new file mode 100644 index 0000000..f8c50f4 --- /dev/null +++ b/src/assets/static/main.css @@ -0,0 +1,14 @@ +header, footer, main { + max-width: 800px; + margin: 0 auto; + padding: 1em; + box-sizing: border-box; +} + +header { + border-bottom: 1px solid #ccc; +} + +footer { + border-top: 1px solid #ccc; +} diff --git a/src/handlers/home.tsx b/src/handlers/home.tsx index 5200c52..5f5ccb8 100644 --- a/src/handlers/home.tsx +++ b/src/handlers/home.tsx @@ -12,11 +12,8 @@ const app = new Hono<{ Variables: Posts }>(); app.get("/", async (c) => { const postService: PostFileService = c.get('postService'); - const posts = postService.getPosts(); - const postList: PostMeta[] = Array.from(posts.values()) - .map((p: Post) => p.meta) - .sort((p1: Post, p2: Post) => p1.meta.date - p2.meta.date); - + const postList: PostMeta[] = Array.from(postService.getPublishedPosts()) + .map((p: Post) => p.meta); return c.render(, { meta: { diff --git a/src/index.tsx b/src/index.tsx index 89832f1..4381313 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,7 +7,6 @@ import posts from '@blog/handlers/posts'; import type { SiteMeta } from '@blog/models/SiteMeta'; import { postFileMiddleware } from '@blog/middleware/post-service'; import { logger } from 'hono/logger'; -import { STATIC_PATH } from '@blog/config'; declare module 'hono' { interface ContextRenderer { @@ -36,7 +35,6 @@ app.use('/static/*', serveStatic({ } })); -console.log(JSON.stringify({ message: "Bootstrapping the routes..." })); app.route('/', home); app.route('/posts', posts); diff --git a/src/services/post-file.ts b/src/services/post-file.ts index e88412f..85098b0 100644 --- a/src/services/post-file.ts +++ b/src/services/post-file.ts @@ -57,13 +57,19 @@ export class PostFileService { } public getPostsSortedByDate(desc: boolean = true): Post[] { - return Array.from(this.posts.entries()).sort((p1: Post, p2: Post) => { - if (desc) { - return p1.meta.date - p2.meta.date; - } + return Array.from(this.posts.values()) + .sort((p1: Post, p2: Post) => { + if (desc) { + return p1.meta.date.getTime() - p2.meta.date.getTime(); + } - return p2.meta.date - p1.meta.date; - }) + return p2.meta.date.getTime() - p1.meta.date.getTime(); + }); + } + + public getPublishedPosts(): Post[] { + return this.getPostsSortedByDate() + .filter((p: Post) => p.meta.draft == false); } public getPost(slug: string): Post { diff --git a/src/templates/Page.tsx b/src/templates/Page.tsx index 7ed6b75..4b961e3 100644 --- a/src/templates/Page.tsx +++ b/src/templates/Page.tsx @@ -17,7 +17,9 @@ export function Page({ children, meta }: { children: any, meta: SiteMeta }) {
-
davesmithhayes.com
+
{children} diff --git a/src/templates/Pages/Home.tsx b/src/templates/Pages/Home.tsx index e7b9e70..07acf82 100644 --- a/src/templates/Pages/Home.tsx +++ b/src/templates/Pages/Home.tsx @@ -4,7 +4,7 @@ import { PostMeta } from '@blog/models/PostMeta'; export function Home({ posts }: { posts: PostMeta[] }) { return (
-

davesmithhayes.com

+

Posts

{posts.length ? :
No posts.
}
);