aboutsummaryrefslogtreecommitdiff
path: root/components/updates
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2023-07-17 15:08:57 -0400
committerAndrew Lee <alee14498@protonmail.com>2023-07-17 15:08:57 -0400
commitddbe4fa61425f6a871a23238ce15a0929e201e6e (patch)
treec1d5c2a0674bcbf2cf79180445d8d26518b7009d /components/updates
parent8fbaca0d8ec9dc1323facb7f4c0029e32cfe5223 (diff)
downloadalure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.tar.gz
alure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.tar.bz2
alure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.zip
Modularizing certain elements; Working information section
Diffstat (limited to 'components/updates')
-rw-r--r--components/updates/DateFormatter.js9
-rw-r--r--components/updates/PostPreview.js15
-rw-r--r--components/updates/getPostMetadata.js20
3 files changed, 44 insertions, 0 deletions
diff --git a/components/updates/DateFormatter.js b/components/updates/DateFormatter.js
new file mode 100644
index 0000000..11f3bf3
--- /dev/null
+++ b/components/updates/DateFormatter.js
@@ -0,0 +1,9 @@
+
+import { parseISO, format } from 'date-fns'
+
+const DateFormatter = (dateString) => {
+ const date = parseISO(dateString)
+ return <time dateTime={dateString}>{format(date, 'LLLL d, yyyy')}</time>
+}
+
+export default DateFormatter \ No newline at end of file
diff --git a/components/updates/PostPreview.js b/components/updates/PostPreview.js
new file mode 100644
index 0000000..ca261c0
--- /dev/null
+++ b/components/updates/PostPreview.js
@@ -0,0 +1,15 @@
+import Link from "next/link";
+import DateFormatter from '@/components/updates/DateFormatter'
+
+export default function PostPreview(props) {
+ return (
+ <div key="post" className="bg-zinc-800 py-3 px-5 border border-gray-600 rounded-lg space-y-3">
+ <Link href={`/updates/${props.slug}`}>
+ <h2 className="font-medium text-2xl hover:underline">{props.title}</h2>
+ </Link>
+ <span>By {props.author}</span>
+ <p>{props.description}</p>
+ <p className="font-medium text-sm">Posted on {DateFormatter(props.date)}</p>
+ </div>
+ )
+}
diff --git a/components/updates/getPostMetadata.js b/components/updates/getPostMetadata.js
new file mode 100644
index 0000000..88e4566
--- /dev/null
+++ b/components/updates/getPostMetadata.js
@@ -0,0 +1,20 @@
+import {readdirSync, readFileSync} from "fs";
+import matter from "gray-matter";
+
+export default function getPostMetadata() {
+ const folder = "posts/";
+ const files = readdirSync(folder);
+ const markdownPosts = files.filter((file) => file.endsWith(".md"));
+
+ return markdownPosts.map((fileName) => {
+ const fileContent = readFileSync(`posts/${fileName}`, "utf-8");
+ const matterResult = matter(fileContent);
+ return {
+ title: matterResult.data.title,
+ author: matterResult.data.author,
+ date: matterResult.data.date,
+ description: matterResult.data.description,
+ slug: fileName.replace(".md", "")
+ }
+ })
+}