diff --git a/web/src/pages/posts/[slug].astro b/web/src/pages/posts/[slug].astro index 1502194..52b83eb 100644 --- a/web/src/pages/posts/[slug].astro +++ b/web/src/pages/posts/[slug].astro @@ -1,5 +1,106 @@ --- import Base from "@layout/Base"; - +import { getFormattedDate } from "@utils/date"; +import { calcReadTime } from '@utils/post' +import { authPB } from "@utils/pocketbase"; +const { slug } = Astro.params export const prerender = false ---- \ No newline at end of file + +const pb = await authPB() + +const post = await pb.collection('posts').getFirstListItem(`slug="${slug}"`) + +const { title, content, publishDate, description } = post + +const headerImage = pb.files.getURL(post, post.headerImage) + +const wordCount = content.split(' ').length; +const readTime = calcReadTime(wordCount); +const formattedPublishDate = getFormattedDate(publishDate); + +--- + + +
+

{title}

+ + + +

{description}

+ + | + {readTime} min. read | + { + post.tags.map((tag, i) => ( + <> + + #{tag} + + {i < post.tags.length - 1 && ", "} + + )) + } + + + + +
+ +
+ +
+ + + + + + + \ No newline at end of file diff --git a/web/src/styles/global.css b/web/src/styles/global.css index d9e7a29..fd23d9d 100644 --- a/web/src/styles/global.css +++ b/web/src/styles/global.css @@ -37,6 +37,10 @@ @apply text-black underline decoration-black; @apply hover:decoration-(--accent); } + + h2 { + @apply text-xl; + } } .content-panel { diff --git a/web/src/utils/post.ts b/web/src/utils/post.ts new file mode 100644 index 0000000..a499750 --- /dev/null +++ b/web/src/utils/post.ts @@ -0,0 +1,10 @@ +export function calcReadTime(wordCount: number) { + let d = new Date() + // avg reading rate of 184 wpm + d.setMinutes(wordCount/184); + if (d.getMinutes() == 0) { + return "< 1"; + } else { + return d.getMinutes().toLocaleString(); + } +} \ No newline at end of file