use useState composable
Signed-off-by: nurRiyad <asadnurriyad@gmail.com>
This commit is contained in:
8
app.vue
8
app.vue
@@ -1,4 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
htmlAttrs: {
|
htmlAttrs: {
|
||||||
lang: "en",
|
lang: "en",
|
||||||
@@ -12,6 +14,10 @@ useHead({
|
|||||||
{ name: "twitter:creator", content: "@nuxt_js" },
|
{ name: "twitter:creator", content: "@nuxt_js" },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { data } = await useAsyncData("index", () => queryContent("/").find());
|
||||||
|
|
||||||
|
useState("blogData", () => (data.value as Array<ParsedContent>) || []);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -37,7 +43,7 @@ useHead({
|
|||||||
/* Layout Transition */
|
/* Layout Transition */
|
||||||
.layout-enter-active,
|
.layout-enter-active,
|
||||||
.layout-leave-active {
|
.layout-leave-active {
|
||||||
transition: all 0.4s;
|
transition: all 0.3s;
|
||||||
}
|
}
|
||||||
.layout-enter-from,
|
.layout-enter-from,
|
||||||
.layout-leave-to {
|
.layout-leave-to {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ContentLoader } from "vue-content-loader";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div
|
|
||||||
class="font-ibmmono px-10 mb-4 text-slate-800 group shadow-sm bg-white rounded-lg py-4"
|
|
||||||
>
|
|
||||||
<content-loader
|
|
||||||
viewBox="0 0 476 45"
|
|
||||||
:speed="2"
|
|
||||||
primaryColor="#f3f3f3"
|
|
||||||
secondaryColor="#ecebeb"
|
|
||||||
>
|
|
||||||
<rect x="9" y="6" rx="0" ry="0" width="38" height="34" />
|
|
||||||
<rect x="58" y="6" rx="0" ry="0" width="369" height="9" />
|
|
||||||
<rect x="71" y="29" rx="0" ry="0" width="113" height="9" />
|
|
||||||
<rect x="191" y="28" rx="0" ry="0" width="113" height="9" />
|
|
||||||
</content-loader>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const routeType = computed(() => {
|
const routeType = computed(() => {
|
||||||
return route.params.topic || "";
|
return route.params.topic || "";
|
||||||
});
|
});
|
||||||
const { data } = await useLazyAsyncData("listhero", () =>
|
const data = useState("blogData");
|
||||||
queryContent(`/${routeType.value}`).find()
|
|
||||||
);
|
|
||||||
|
|
||||||
const typeName = computed(() => {
|
const typeName = computed(() => {
|
||||||
return data.value?.at(0)?.type || "";
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
|
const filteredType = allpost.filter((post) => post._dir === routeType.value);
|
||||||
|
return filteredType.at(0)?.type || "";
|
||||||
});
|
});
|
||||||
|
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
title: String,
|
title: String,
|
||||||
|
dir: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
router.push(`/tags/${props.title?.toLocaleLowerCase()}`);
|
router.push(`/tags/${props.dir}`);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ definePageMeta({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="container mx-auto bg-white max-w-6xl p-6 prose prose-slate">
|
<main
|
||||||
|
class="container mx-auto bg-white max-w-5xl p-6 min-h-screen prose prose-slate"
|
||||||
|
>
|
||||||
<ContentDoc />
|
<ContentDoc />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ definePageMeta({
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="container mx-auto max-w-6xl font-ibmmono antialiased min-h-[72vh]"
|
class="container mx-auto max-w-6xl font-ibmmono antialiased min-h-screen"
|
||||||
>
|
>
|
||||||
<div class="flex gap-14">
|
<div class="flex gap-14">
|
||||||
<div class="m-2 rounded-lg object-cover">
|
<div class="m-2 rounded-lg object-cover">
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import type { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: "list",
|
layout: "list",
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data } = useLazyAsyncData("blogs", () => queryContent("/").find());
|
const data = useState("blogData");
|
||||||
|
|
||||||
|
// get all blog post
|
||||||
const getAllPost = computed(() => {
|
const getAllPost = computed(() => {
|
||||||
const allpost = data.value || [];
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
const alltypes = allpost.map((post) => {
|
const alltypes = allpost.map((post) => {
|
||||||
return {
|
return {
|
||||||
title: post.title,
|
title: post.title,
|
||||||
@@ -26,7 +29,7 @@ const getAllPost = computed(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="container mx-auto max-w-6xl font-ibmmono antialiased min-h-[72vh]"
|
class="container mx-auto max-w-6xl font-ibmmono antialiased min-h-screen"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<template v-for="pp in getAllPost" :key="pp">
|
<template v-for="pp in getAllPost" :key="pp">
|
||||||
|
|||||||
@@ -1,17 +1,24 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { data } = useLazyAsyncData("index", () => queryContent("/").find());
|
import type { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
|
const data = useState("blogData");
|
||||||
|
|
||||||
// get all the unique types from content
|
// get all the unique types from content
|
||||||
const getTopCategory = computed(() => {
|
const getTopCategory = computed(() => {
|
||||||
const allpost = data.value || [];
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
const alltypes = allpost.map((post) => post.type);
|
const alltypes = allpost.map((post) => {
|
||||||
|
return {
|
||||||
|
type: post.type,
|
||||||
|
dir: post._dir,
|
||||||
|
};
|
||||||
|
});
|
||||||
const uniqType = new Set(alltypes);
|
const uniqType = new Set(alltypes);
|
||||||
return uniqType;
|
return uniqType;
|
||||||
});
|
});
|
||||||
|
|
||||||
// get all post in recent time order
|
// get all post in recent time order
|
||||||
const getRecentContent = computed(() => {
|
const getRecentContent = computed(() => {
|
||||||
const allpost = data.value || [];
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
const customizePost = allpost.map((post) => {
|
const customizePost = allpost.map((post) => {
|
||||||
return {
|
return {
|
||||||
title: post.title,
|
title: post.title,
|
||||||
@@ -27,13 +34,13 @@ const getRecentContent = computed(() => {
|
|||||||
const d = new Date(b.date);
|
const d = new Date(b.date);
|
||||||
return c < d ? 1 : -1;
|
return c < d ? 1 : -1;
|
||||||
});
|
});
|
||||||
return customizePost;
|
return customizePost.filter((post, idx) => idx < 6);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="container px-4 mx-auto max-w-6xl flex font-ibmmono gap-14 antialiased min-h-[72vh]"
|
class="container px-4 mx-auto max-w-6xl flex font-ibmmono gap-14 antialiased min-h-screen"
|
||||||
>
|
>
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<h1 class="text-xl pb-8 text-[#e60067]">RECENTLY PUBLISHED</h1>
|
<h1 class="text-xl pb-8 text-[#e60067]">RECENTLY PUBLISHED</h1>
|
||||||
@@ -54,7 +61,7 @@ const getRecentContent = computed(() => {
|
|||||||
<div>
|
<div>
|
||||||
<h2 class="text-xl pb-8 text-[#e60067]">TOP CATEGORIES</h2>
|
<h2 class="text-xl pb-8 text-[#e60067]">TOP CATEGORIES</h2>
|
||||||
<template v-for="cat in getTopCategory" :key="cat">
|
<template v-for="cat in getTopCategory" :key="cat">
|
||||||
<topic-card :title="cat" />
|
<topic-card :title="cat.type" :dir="cat.dir" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: "list",
|
layout: "list",
|
||||||
});
|
});
|
||||||
@@ -8,33 +10,34 @@ const route = useRoute();
|
|||||||
const routeType = computed(() => {
|
const routeType = computed(() => {
|
||||||
return route.params.topic || "";
|
return route.params.topic || "";
|
||||||
});
|
});
|
||||||
const { data } = useLazyAsyncData("topic", () =>
|
|
||||||
queryContent(`/${routeType.value}`).find()
|
|
||||||
);
|
|
||||||
|
|
||||||
const typeName = computed(() => {
|
const data = useState("blogData");
|
||||||
const t = data.value?.at(0)?.type || "";
|
|
||||||
return t.toUpperCase();
|
|
||||||
});
|
|
||||||
|
|
||||||
const getRecentContent = computed(() => {
|
const getRecentContent = computed(() => {
|
||||||
const allpost = data.value || [];
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
const alltypes = allpost.map((post) => {
|
const modifedPost = allpost.map((post) => {
|
||||||
return {
|
return {
|
||||||
title: post.title,
|
title: post.title,
|
||||||
description: post.description,
|
description: post.description,
|
||||||
path: post._path,
|
path: post._path,
|
||||||
date: post.date as string,
|
date: post.date as string,
|
||||||
author: post.author,
|
author: post.author,
|
||||||
|
dir: post._dir,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
alltypes.sort(function (a, b) {
|
console.log(modifedPost);
|
||||||
|
|
||||||
|
const filteredPost = modifedPost.filter(
|
||||||
|
(post) => post.dir === routeType.value
|
||||||
|
);
|
||||||
|
|
||||||
|
filteredPost.sort(function (a, b) {
|
||||||
const c = new Date(a.date);
|
const c = new Date(a.date);
|
||||||
const d = new Date(b.date);
|
const d = new Date(b.date);
|
||||||
return c < d ? 1 : -1;
|
return c < d ? 1 : -1;
|
||||||
});
|
});
|
||||||
return alltypes;
|
return filteredPost;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { ParsedContent } from "@nuxt/content/dist/runtime/types";
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: "list",
|
layout: "list",
|
||||||
});
|
});
|
||||||
const { data } = useLazyAsyncData("tags", () => queryContent("/").find());
|
const data = useState("blogData");
|
||||||
|
|
||||||
const getTopCategory = computed(() => {
|
const getTopCategory = computed(() => {
|
||||||
const allpost = data.value || [];
|
const allpost = (data.value as Array<ParsedContent>) || [];
|
||||||
const alltypes = allpost.map((post) => post.type);
|
const alltypes = allpost.map((post) => post.type);
|
||||||
const uniqType = new Set(alltypes);
|
const uniqType = new Set(alltypes);
|
||||||
const cobj = <Array<{ type: string; count: number; path: string }>>[];
|
const cobj = <Array<{ type: string; count: number; path: string }>>[];
|
||||||
|
|||||||
Reference in New Issue
Block a user