From 26d75b9edf8ebf798006ef273e28d2165b984de6 Mon Sep 17 00:00:00 2001 From: smack0007 Date: Fri, 17 May 2024 15:32:22 +0200 Subject: [PATCH] Refactor how templates are defined. --- .gitignore | 7 +- .vscode/settings.json | 6 +- src/templates/index.tsx | 30 ++- src/templates/page.tsx | 368 +++++++++++++++++------------------ src/templates/post.tsx | 14 +- src/templates/postHeader.tsx | 46 ++--- src/templates/tags.tsx | 24 ++- 7 files changed, 234 insertions(+), 261 deletions(-) diff --git a/.gitignore b/.gitignore index 873b06d6..b970715d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,4 @@ -[B|b]in/ -[O|o]bj/ -.cache/ -.vs/ +bin/ node_modules/ -dist/ -*.suo commit.msg \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b2221b39..de847234 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,9 @@ { "deno.enable": true, - "editor.tabSize": 2 + "editor.tabSize": 2, + + "[typescriptreact]": { + "editor.defaultFormatter": "denoland.vscode-deno" + } } diff --git a/src/templates/index.tsx b/src/templates/index.tsx index 4b393248..8a306330 100644 --- a/src/templates/index.tsx +++ b/src/templates/index.tsx @@ -1,21 +1,19 @@ import { html, Post } from "~/compiler/index.ts"; import { PostHeaderTemplate } from "./postHeader.tsx"; -export function IndexTemplate(posts: Post[]): string { - return posts - .map((post) => ( -
- {PostHeaderTemplate(post)} -
- {post.excerpt} +export const IndexTemplate = (posts: Post[]) => posts + .map((post) => ( +
+ {PostHeaderTemplate(post)} +
+ {post.excerpt} - {post.hasExcerpt && ( - - Read More - - )} -
+ {post.hasExcerpt && ( + + Read More + + )}
- )) - .join(""); -} +
+ )) + .join(""); diff --git a/src/templates/page.tsx b/src/templates/page.tsx index 39f09b28..fd257b6e 100644 --- a/src/templates/page.tsx +++ b/src/templates/page.tsx @@ -1,230 +1,214 @@ import { BASE_URL, html, Page } from "~/compiler/index.ts"; -export function PageTemplate(page: Page): string { - return ( - "" + - ( - - - - - - +export const PageTemplate = (page: Page) => + "" + + ( + + + + + + + - {page.frontMatter.title} - + {page.frontMatter.title} + - + - + + - - - - - - - +
+ +
+
{page.contents}
+
-
+ + + + + ); -} diff --git a/src/templates/post.tsx b/src/templates/post.tsx index d173dacc..50b87c71 100644 --- a/src/templates/post.tsx +++ b/src/templates/post.tsx @@ -1,12 +1,10 @@ import { html, Post } from "~/compiler/index.ts"; import { PostHeaderTemplate } from "./postHeader.tsx"; -export function PostTemplate(post: Post): string { - return ( -
- {PostHeaderTemplate(post)} +export const PostTemplate = (post: Post) => ( +
+ {PostHeaderTemplate(post)} -
{post.contents}
-
- ); -} +
{post.contents}
+
+); diff --git a/src/templates/postHeader.tsx b/src/templates/postHeader.tsx index 61e1e6ba..563760aa 100644 --- a/src/templates/postHeader.tsx +++ b/src/templates/postHeader.tsx @@ -1,28 +1,24 @@ import { encode, formatDate, getTagUrl, html, Post } from "~/compiler/index.ts"; -export function PostHeaderTemplate(post: Post): string { - return ( -
-

- {encode(post.frontMatter.title)} -

- {post.frontMatter.subtitle.length > 0 && ( -

{encode(post.frontMatter.subtitle)}

- )} -
- - - {formatDate(post.frontMatter.date)} - - - {post.frontMatter.tags.map((tag) => ( - - - {encode(tag)} - - ))} - -
+export const PostHeaderTemplate = (post: Post) => ( +
+

+ {encode(post.frontMatter.title)} +

+ {post.frontMatter.subtitle.length > 0 &&

{encode(post.frontMatter.subtitle)}

} +
+ + + {formatDate(post.frontMatter.date)} + + + {post.frontMatter.tags.map((tag) => ( + + + {encode(tag)} + + ))} +
- ); -} +
+); diff --git a/src/templates/tags.tsx b/src/templates/tags.tsx index 5ab47098..326140e8 100644 --- a/src/templates/tags.tsx +++ b/src/templates/tags.tsx @@ -1,15 +1,13 @@ import { html, Tag } from "~/compiler/index.ts"; -export function TagsTemplate(tags: Tag[]): string { - return ( - - ); -} +export const TagsTemplate = (tags: Tag[]) => ( + +);