add: category, date sorting
Add category layouts and date sorting
This commit is contained in:
parent
9b66a79a8c
commit
579491f216
7 changed files with 85 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
|||
.BlogCard {
|
||||
overflow: hidden;
|
||||
border-radius: 1rem;
|
||||
background: var(--color-orange-black);
|
||||
background: var(--color-black);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
|
@ -60,7 +60,6 @@
|
|||
}
|
||||
|
||||
|
||||
|
||||
@media (width <= 780px) {
|
||||
.BlogCard header {
|
||||
align-items: center;
|
15
app/assets/css/blog/overview.css
Normal file
15
app/assets/css/blog/overview.css
Normal file
|
@ -0,0 +1,15 @@
|
|||
.BlogOverview {
|
||||
& .category-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
& .article-overview {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 2rem;
|
||||
}
|
||||
}
|
|
@ -97,6 +97,15 @@ a {
|
|||
color: var(--color-white);
|
||||
}
|
||||
|
||||
a.side {
|
||||
color: var(--color-orange);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--color-orange-light);
|
||||
}
|
||||
}
|
||||
|
||||
a.text {
|
||||
color: var(--color-orange);
|
||||
text-decoration: underline;
|
||||
|
@ -148,6 +157,7 @@ span.chip {
|
|||
align-items: center;
|
||||
gap: .5em;
|
||||
width: max-content;
|
||||
transition: var(--transition-time);
|
||||
|
||||
&:not(.dark) {
|
||||
--background: var(--color-orange);
|
||||
|
@ -197,6 +207,10 @@ span.chip {
|
|||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.margin-top-middle {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
.margin-top-big {
|
||||
margin-top: 6rem;
|
||||
}
|
||||
|
@ -206,7 +220,7 @@ span.chip {
|
|||
}
|
||||
|
||||
.bg-radial {
|
||||
background-image: radial-gradient(circle at 100vw 100vh, rgba(255,145,0,0.2) 0%, rgba(0,0,0,0) 63%, rgba(0,0,0,0) 100%);
|
||||
background-image: radial-gradient(circle at 100vw 100vh, rgba(255, 145, 0, 0.2) 0%, rgba(0, 0, 0, 0) 63%, rgba(0, 0, 0, 0) 100%);
|
||||
background-color: var(--color-orange-black);
|
||||
background-repeat: no-repeat;
|
||||
|
||||
|
@ -241,6 +255,10 @@ span.chip {
|
|||
flex-direction: column;
|
||||
}
|
||||
|
||||
.flex-wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.gap-default {
|
||||
gap: 3rem;
|
||||
}
|
||||
|
@ -288,12 +306,6 @@ span.chip {
|
|||
align-items: center;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.tip-container .tip {
|
||||
scale: 0;
|
||||
position: absolute;
|
||||
|
|
|
@ -20,5 +20,5 @@ const icons: Record<Category, string> = {
|
|||
'freelancing': 'ph:laptop-duotone',
|
||||
}
|
||||
|
||||
const icon = computed(() => name ? icons[name] : 'ph:question-mark-duotone')
|
||||
const icon = computed(() => icons[name] ?? 'ph:question-mark-duotone')
|
||||
</script>
|
|
@ -1,19 +1,52 @@
|
|||
<template>
|
||||
<section id="blog" class="Blog content">
|
||||
<div class="grid">
|
||||
<BlogCard v-for="article in articles" v-bind="makeBlogCard(article)"/>
|
||||
</div>
|
||||
<section id="blog" class="BlogOverview content">
|
||||
<main>
|
||||
<ul class="category-list">
|
||||
<li>
|
||||
<NuxtLink class="inline-flex-row gap-sm side" to="/blog">
|
||||
<span class="chip" :class="{ 'dark' : route.query.category}">Alle {{ articles?.length }}</span>
|
||||
</NuxtLink>
|
||||
</li>
|
||||
<li v-for="(count, category) in allCategoriesAndCount">
|
||||
<NuxtLink class="inline-flex-row gap-sm side" :to="`?category=${category}`">
|
||||
<span class="chip" :class="{ 'dark' : category !== route.query.category}"><BlogCategory :name="category"/> {{ count }}</span>
|
||||
</NuxtLink>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="grid margin-top-middle article-overview">
|
||||
<BlogCard v-for="article in firstTen" v-bind="makeBlogCard(article)"/>
|
||||
</div>
|
||||
</main>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { BlogCollectionItem } from '@nuxt/content'
|
||||
import type { Category } from '../../components/Blog/types'
|
||||
|
||||
const { data } = await useAsyncData('articles', () => queryCollection('blog').order('date', 'DESC').limit(10).all())
|
||||
const route = useRoute()
|
||||
|
||||
const articles = data.value!
|
||||
const { data: articles } = await useAsyncData('articles', () => queryCollection('blog').order('date', 'DESC').all())
|
||||
|
||||
const makeBlogCard = (article: typeof articles[0]) => ({
|
||||
const firstTen = computed(() => {
|
||||
if (route.query.category) {
|
||||
return articles.value?.filter(article => article.meta.category === route.query.category).slice(0, 10) ?? []
|
||||
}
|
||||
return articles.value?.slice(0, 10) ?? []
|
||||
})
|
||||
|
||||
const allCategoriesAndCount = computed(() => {
|
||||
const categories = {} as Record<Category, number>
|
||||
articles.value?.forEach(article => {
|
||||
const category = article.meta.category as Category
|
||||
if (category) {
|
||||
categories[category] = (categories[category] ?? 0) + 1
|
||||
}
|
||||
})
|
||||
return categories
|
||||
})
|
||||
|
||||
const makeBlogCard = (article: BlogCollectionItem) => ({
|
||||
title: article.title,
|
||||
description: article.description,
|
||||
image: article.meta.image as string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue