make latest page dynamic

Signed-off-by: nurRiyad <asadnurriyad@gmail.com>
This commit is contained in:
nurRiyad
2022-12-19 23:38:44 +06:00
parent 4ef9100efc
commit b48a3ce1cf
3 changed files with 52 additions and 10 deletions

View File

@@ -2,7 +2,28 @@
definePageMeta({
layout: "list",
});
const { data } = await useAsyncData("home", () => queryContent("/").find());
const getRecentContent = computed(() => {
const allpost = data.value || [];
const alltypes = allpost.map((post) => {
return {
title: post.title,
description: post.description,
path: post._path,
date: post.date as string,
author: post.author,
};
});
alltypes.sort(function (a, b) {
const c = new Date(a.date);
const d = new Date(b.date);
return c < d ? 1 : -1;
});
return alltypes;
});
</script>
<template>
@@ -11,7 +32,15 @@ const { data } = await useAsyncData("home", () => queryContent("/").find());
LATEST CONTENT
</h1>
<div class="flex justify-between flex-wrap">
<latest-blog-card v-for="n in 20" :key="n" />
<template v-for="pp in getRecentContent" :key="pp">
<latest-blog-card
:title="pp.title"
:description="pp.description"
:date="pp.date"
:author="pp.author"
:path="pp.path"
/>
</template>
</div>
</div>
</template>