Skip to content

Commit

Permalink
feat: Rework blog list
Browse files Browse the repository at this point in the history
  • Loading branch information
GabsEdits committed Apr 12, 2024
1 parent 5c9adbe commit 0dd4f80
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
5 changes: 1 addition & 4 deletions components/BlogList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@

<script setup lang="ts">
import { ref, computed } from "vue";
import { useData } from "vitepress";
const { theme } = useData();
const posts = theme.value.blog.posts;
import { data as posts } from "./posts.data";
const selectedTag = ref(null);
Expand Down
35 changes: 35 additions & 0 deletions components/posts.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import path from "path";
import { createContentLoader } from "vitepress";

interface Post {
title: string;
description: string;
tags: string[];
}

declare const data: Post[];
export { data };

export default createContentLoader(path.join(__dirname, "../../blog/posts/*.md"), {
excerpt: true,
transform(raw): Post[] {
return raw
.map(({ frontmatter }) => ({
title: frontmatter.title,
description: frontmatter.description,
tags: frontmatter.tags,
date: formatDate(frontmatter.date),
}))
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
},
});

function formatDate(raw: string): string {
const date = new Date(raw);
date.setUTCHours(12);
return date.toLocaleDateString("en-GB", {
year: "numeric",
month: "long",
day: "2-digit",
});
}

0 comments on commit 0dd4f80

Please sign in to comment.