69 lines
1.8 KiB
Vue
69 lines
1.8 KiB
Vue
<script setup lang="ts">
|
|
import type { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
|
|
|
const data = useState("blogData");
|
|
|
|
// get all the unique types from content
|
|
const getTopCategory = computed(() => {
|
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
|
const alltypes = allpost.map((post) => {
|
|
return {
|
|
type: post.type,
|
|
dir: post._dir,
|
|
};
|
|
});
|
|
return [...new Map(alltypes.map((item) => [item["dir"], item])).values()];
|
|
});
|
|
|
|
// get all post in recent time order
|
|
const getRecentContent = computed(() => {
|
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
|
const customizePost = allpost.map((post) => {
|
|
return {
|
|
title: post.title,
|
|
description: post.description,
|
|
path: post._path,
|
|
date: post.date as string,
|
|
type: post.type,
|
|
};
|
|
});
|
|
|
|
customizePost.sort(function (a, b) {
|
|
const c = new Date(a.date);
|
|
const d = new Date(b.date);
|
|
return c < d ? 1 : -1;
|
|
});
|
|
return customizePost.filter((post, idx) => idx < 6);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="container px-4 mx-auto max-w-6xl flex font-ibmmono gap-14 antialiased min-h-screen"
|
|
>
|
|
<div class="flex-1">
|
|
<h1 class="text-xl pb-8 text-[#e60067]">RECENTLY PUBLISHED</h1>
|
|
<div class="space-y-8">
|
|
<template v-for="rp in getRecentContent" :key="rp">
|
|
<blog-card
|
|
:title="rp.title"
|
|
:description="rp.description"
|
|
:path="rp.path"
|
|
:date="rp.date"
|
|
:type="rp.type"
|
|
/>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="basis-1/4">
|
|
<div>
|
|
<h2 class="text-xl pb-8 text-[#e60067]">TOP CATEGORIES</h2>
|
|
<template v-for="cat in getTopCategory" :key="cat">
|
|
<topic-card :title="cat.type" :dir="cat.dir" />
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|