From daf43aa2a7e2224173e60c379646ce525e2ceada Mon Sep 17 00:00:00 2001 From: nurRiyad Date: Tue, 20 Dec 2022 00:32:53 +0600 Subject: [PATCH] make topic detail page dynamic Signed-off-by: nurRiyad --- pages/tags/[topic].vue | 51 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/pages/tags/[topic].vue b/pages/tags/[topic].vue index 21f4d96..6d0d204 100644 --- a/pages/tags/[topic].vue +++ b/pages/tags/[topic].vue @@ -2,16 +2,59 @@ definePageMeta({ layout: "list", }); -const { data } = await useAsyncData("home", () => queryContent("/").find()); + +const route = useRoute(); + +const routeType = computed(() => { + return route.params.topic || ""; +}); +const { data } = await useAsyncData("home", () => + queryContent(`/${routeType.value}`).find() +); + +const typeName = computed(() => { + const t = data.value?.at(0)?.type || ""; + return t.toUpperCase(); +}); + +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; +});