add function

Signed-off-by: nurRiyad <asadnurriyad@gmail.com>
This commit is contained in:
nurRiyad
2023-01-09 23:39:02 +06:00
parent e8ff379673
commit 5b9032cf68
5 changed files with 45 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
<template> <template>
<div> <div>
<NuxtLayout> <NuxtLayout>
<NuxtLoadingIndicator />
<NuxtPage /> <NuxtPage />
</NuxtLayout> </NuxtLayout>
</div> </div>

View File

@@ -1,9 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
defineProps({ interface Props {
title: String, title: string
}
withDefaults(defineProps<Props>(), {
title: 'No title available',
}) })
let color = [ // some random color for tags
const color = [
'#dc2626', '#dc2626',
'#d97706', '#d97706',
'#65a30d', '#65a30d',
@@ -16,20 +21,21 @@ let color = [
'#db2777', '#db2777',
] ]
// get a random number
const getRandomInt = (min: number, max: number) => { const getRandomInt = (min: number, max: number) => {
min = Math.ceil(min) min = Math.ceil(min)
max = Math.floor(max) max = Math.floor(max)
return Math.floor(Math.random() * (max - min + 1)) + min return Math.floor(Math.random() * (max - min + 1)) + min
} }
const randbgcolor = ref(`${color.at(getRandomInt(0, 8))}`) const picAColor = ref(`${color.at(getRandomInt(0, 8))}`)
</script> </script>
<template> <template>
<div <div
class="text-white px-5 py-3 rounded hover:underline randbgcolor hover:scale-[1.05] transition-all duration-500" class="text-white px-5 py-3 rounded hover:underline randbgcolor hover:scale-[1.05] transition-all duration-500"
> >
<NuxtLink :to="`/categories/${title}`" class="text-xl font-extrabold"> <NuxtLink :to="`/categories/${title.toLocaleLowerCase()}`" class="text-xl font-extrabold">
<h1>#{{ title }}</h1> <h1>#{{ title }}</h1>
</NuxtLink> </NuxtLink>
</div> </div>
@@ -37,6 +43,6 @@ const randbgcolor = ref(`${color.at(getRandomInt(0, 8))}`)
<style scoped> <style scoped>
.randbgcolor { .randbgcolor {
background-color: v-bind(randbgcolor); background-color: v-bind(picAColor);
} }
</style> </style>

View File

@@ -1,8 +1,21 @@
<script setup lang="ts">
const route = useRoute()
// The the category name and make the first char upper
const category = computed(() => {
const name = route.params.category || ''
const firstChar = name.at(0)?.toLocaleUpperCase() || ''
const otherChar = name.slice(1)
return firstChar + otherChar
})
</script>
<template> <template>
<div class="container mx-auto"> <div class="container mx-auto">
<div class="p-6 my-4 mx-3 rounded-md bg-gray-200"> <div class="p-6 my-4 mx-3 rounded-md bg-gray-200">
<h1 class="text-black font-semibold leading-tight text-4xl md:text-5xl my-5"> <h1 class="text-black font-semibold leading-tight text-4xl md:text-5xl my-5">
#{{ $route.params.category }} #{{ category }}
</h1> </h1>
</div> </div>
</div> </div>

View File

@@ -9,7 +9,8 @@ useHead({
], ],
titleTemplate: "Elon's Blog - %s", titleTemplate: "Elon's Blog - %s",
}) })
const { data } = await useAsyncData('home', () => queryContent('/blogs').find())
const { data } = await useAsyncData('home', () => queryContent('/blogs').where({}).find())
</script> </script>
<template> <template>
<main class="container max-w-5xl mx-auto text-zinc-600"> <main class="container max-w-5xl mx-auto text-zinc-600">

View File

@@ -7,28 +7,29 @@ useHead({
content: 'Home', content: 'Home',
}, },
], ],
titleTemplate: "Elon's Blog - %s", titleTemplate: "Riyad's Blog - %s",
}) })
const { data } = await useAsyncData('home', () => queryContent('/blogs').find()) const topics = [
'Javascript',
let ar = [ 'Typescript',
'javascript', 'Git',
'typescript', 'Docker',
'git', 'Kubernetes',
'docker', 'Vue',
'kubernetes', 'Nuxt',
'vue', 'Pinia',
'nuxt', 'Vuex',
'pinia', 'Firebase',
'cypress', 'Supabse',
'Cypress',
] ]
</script> </script>
<template> <template>
<main class="container max-w-5xl mx-auto text-zinc-600"> <main class="container max-w-5xl mx-auto text-zinc-600">
<CategoryHero /> <CategoryHero />
<div class="flex flex-wrap px-6 mt-12 gap-3"> <div class="flex flex-wrap px-6 mt-12 gap-3">
<template v-for="n in ar" :key="n"> <template v-for="topic in topics" :key="n">
<CategoryCard :title="n" /> <CategoryCard :title="topic" />
</template> </template>
</div> </div>
</main> </main>