From 6d30303a297451d6365f935242a17ecccfd70d16 Mon Sep 17 00:00:00 2001 From: colmugx Date: Tue, 30 Jul 2024 13:50:52 +0800 Subject: [PATCH] feat: refactor post components and move to astro --- src/component/FormattedDate.astro | 19 +++++++ src/component/Post.astro | 2 +- src/component/PostItem.astro | 49 +++++++++++++++++ src/component/PostList.astro | 4 +- src/component/PostMeta.astro | 66 +++++++++++++++++++++++ src/component/svelte/FormattedDate.svelte | 13 ----- src/component/svelte/Post/PostItem.svelte | 41 -------------- src/component/svelte/Post/PostMeta.svelte | 53 ------------------ src/layout/BlogPost.astro | 3 +- 9 files changed, 138 insertions(+), 112 deletions(-) create mode 100644 src/component/FormattedDate.astro create mode 100644 src/component/PostItem.astro create mode 100644 src/component/PostMeta.astro delete mode 100644 src/component/svelte/FormattedDate.svelte delete mode 100644 src/component/svelte/Post/PostItem.svelte delete mode 100644 src/component/svelte/Post/PostMeta.svelte diff --git a/src/component/FormattedDate.astro b/src/component/FormattedDate.astro new file mode 100644 index 0000000..96aded5 --- /dev/null +++ b/src/component/FormattedDate.astro @@ -0,0 +1,19 @@ +--- +import { SITE_LANG } from '@constant/app' + +type Props = { + date: Date +} + +const { date } = Astro.props +--- + + diff --git a/src/component/Post.astro b/src/component/Post.astro index 959e825..0c51ab6 100644 --- a/src/component/Post.astro +++ b/src/component/Post.astro @@ -1,6 +1,6 @@ --- import type { BlogEntry } from '@content/config' -import FormattedDate from '@component/svelte/FormattedDate.svelte' +import FormattedDate from './FormattedDate.astro' type Props = { post: BlogEntry diff --git a/src/component/PostItem.astro b/src/component/PostItem.astro new file mode 100644 index 0000000..ea9a628 --- /dev/null +++ b/src/component/PostItem.astro @@ -0,0 +1,49 @@ +--- +import type { BlogEntry } from '@content/config' +import FormattedDate from './FormattedDate.astro' + +type Props = { + post: BlogEntry + showPin?: boolean +} + +const { post, showPin } = Astro.props + +const isPin = post.data.pin +const date = post.data.date || (post.data.pubDate as Date) +--- + +
+
+ + { + post.data.category && ( + + {post.data.category} + + ) + } +
+ +

+ {post.data.title} +

+ { + post.data.description && ( +

+ {post.data.description} +

+ ) + } +
+
diff --git a/src/component/PostList.astro b/src/component/PostList.astro index 0924509..a0d7551 100644 --- a/src/component/PostList.astro +++ b/src/component/PostList.astro @@ -1,7 +1,7 @@ --- import type { BlogEntry } from '@content/config' -import PostItem from './svelte/Post/PostItem.svelte' import ToArchive from './ToArchive.astro' +import PostItem from './PostItem.astro' type Props = { list: BlogEntry[] @@ -17,7 +17,7 @@ const _list = home && isMax ? list.slice(0, 10) : list ---
- {_list.map(post => )} + {_list.map(post => )} {isMax && }
diff --git a/src/component/PostMeta.astro b/src/component/PostMeta.astro new file mode 100644 index 0000000..8cc5eda --- /dev/null +++ b/src/component/PostMeta.astro @@ -0,0 +1,66 @@ +--- +import type { PostMeta } from '@model/post-meta' +import { convertDash } from 'src/util/convertDash' +import FormattedDate from './FormattedDate.astro' + +type Props = { + meta: PostMeta +} + +const { meta } = Astro.props +--- + +
+
+ + { + meta.category && ( + + {meta.category} + + ) + } + { + meta.readingTime && ( +
{Math.ceil(meta.readingTime.minutes)} mins read
+ ) + } +
+
+
+
+

+ {meta.title} +

+ { + meta.subTitle && ( +
+

+ —— {meta.subTitle} +

+
+ ) + } +
+
+
+ { + meta.tags?.map(tag => ( + + {tag} + + )) + } +
+
+
+ + diff --git a/src/component/svelte/FormattedDate.svelte b/src/component/svelte/FormattedDate.svelte deleted file mode 100644 index 7c1880f..0000000 --- a/src/component/svelte/FormattedDate.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/src/component/svelte/Post/PostItem.svelte b/src/component/svelte/Post/PostItem.svelte deleted file mode 100644 index 477368a..0000000 --- a/src/component/svelte/Post/PostItem.svelte +++ /dev/null @@ -1,41 +0,0 @@ - - -
-
- - {#if post.data.category} - - {post.data.category} - - {/if} -
- -

- {post.data.title} -

- {#if post.data.description} -

- {post.data.description} -

- {/if} -
-
diff --git a/src/component/svelte/Post/PostMeta.svelte b/src/component/svelte/Post/PostMeta.svelte deleted file mode 100644 index 3266213..0000000 --- a/src/component/svelte/Post/PostMeta.svelte +++ /dev/null @@ -1,53 +0,0 @@ - - -
-
- - {#if meta.category} - - {meta.category} - - {/if} - {#if meta.readingTime} -
- {Math.ceil(meta.readingTime.minutes)} mins read -
- {/if} -
-
-
-
-

- {meta.title} -

- {#if meta.subTitle} -
-

- —— {meta.subTitle} -

-
- {/if} -
-
-
- {#each meta.tags as tag} - {tag} - {/each} -
-
-
- - diff --git a/src/layout/BlogPost.astro b/src/layout/BlogPost.astro index 114957c..fa8db44 100644 --- a/src/layout/BlogPost.astro +++ b/src/layout/BlogPost.astro @@ -3,7 +3,6 @@ import '../style/content.css' import type { ReadTimeResults } from 'reading-time' import type { BlogEntry } from '@content/config' import type { PostMeta as TPostMeta } from '@model/post-meta' -import PostMeta from '@component/svelte/Post/PostMeta.svelte' import { SITE_DESCRIPTION, SITE_TITLE } from '@constant/app' import Header from '@component/Header.astro' import Page from './Page.astro' @@ -31,7 +30,7 @@ const title = `${data.title} · ${SITE_TITLE} `
- +