add: article view

View for blog articles
This commit is contained in:
webfussel 2025-06-12 14:11:52 +02:00
parent 579491f216
commit 4104477533
15 changed files with 121 additions and 33 deletions

View file

@ -0,0 +1,20 @@
.BlogArticle {
display: flex;
flex-direction: column;
gap: 2rem;
& .image {
width: 100%;
height: 450px;
border-radius: 1rem;
overflow: hidden;
background: #000;
& img {
width: 100%;
height: 100%;
opacity: .8;
object-fit: cover;
}
}
}

View file

@ -0,0 +1,4 @@
.Excerpt {
font-size: 1.5rem;
font-style: italic;
}

View file

@ -1,6 +1,7 @@
.BlogOverview {
& .category-list {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 1rem;
list-style: none;

View file

@ -1,22 +1,23 @@
<template>
<NuxtLink :to="link" class="BlogCard z-2">
<div class="image">
<img :src="image" alt=" " aria-hidden="true" />
<img :src="image" alt=" " aria-hidden="true"/>
</div>
<div class="card-content">
<header>
<span class="chip"><BlogCategory :name="category" /></span>
<span class="chip"><BlogCategory :name="category"/></span>
<h2>{{ title }}</h2>
<small>{{ description }}</small>
</header>
<main>
<ContentRenderer :value="excerpt" />
<p>
{{ generatePlainText(excerpt.value).at(0)?.text ?? '' }}
</p>
</main>
<footer>
<BlogAuthor :name="author.name" :image="author.image" :date="date" />
<BlogAuthor :name="author.name" :image="author.image" :date="date"/>
<div class="tags">
<span>tags</span>
<span class="tag" v-for="tag in tags">{{tag}}</span>
<span class="tag" v-for="tag in tags">{{ tag }}</span>
</div>
</footer>
</div>
@ -25,19 +26,20 @@
<script setup lang="ts">
import type { Category } from './types'
import type { MinimalNode } from '@nuxt/content'
type Props = {
title : string
description : string
image : string
date : string
excerpt : { type: string, children?: any }
link : string
tags : string[]
category : Category
author : {
name : string
image : string
title: string
description: string
image: string
date: string
excerpt: { type: string, value: MinimalNode[], children?: any }
link: string
tags: string[]
category: Category
author: {
name: string
image: string
}
}

View file

@ -0,0 +1,9 @@
<template>
<p class="Excerpt">
<slot/>
</p>
</template>
<script setup lang="ts">
</script>

View file

@ -1,9 +1,33 @@
<template>
<section class="BlogArticle content">
<NuxtLink class="text inline-flex-row" to="/blog">
<Icon name="ph:arrow-left-duotone"/>
Zurück zur Übersicht
</NuxtLink>
<p v-if="!article">
Sorry bro, aber der Artikel existiert einfach nicht.
</p>
<div v-else>
<header>
<div class="image z-2">
<img :src="article.image" alt="Artikelbild" aria-hidden="true"/>
</div>
<h1 class="margin-top">{{ article.title }}</h1>
<h2>{{ article.description }}</h2>
</header>
<div class="flex-col gap-default">
<ContentRenderer v-if="article" :value="article" :style="{ display: 'contents' }"/>
</div>
</div>
</section>
</template>
<script setup lang="ts">
const route = useRoute()
const { data: article } = await useAsyncData('article', () => queryCollection('blog').path(route.path).first())
</script>
<style scoped>

View file

@ -26,7 +26,16 @@ import type { Category } from '../../components/Blog/types'
const route = useRoute()
const { data: articles } = await useAsyncData('articles', () => queryCollection('blog').order('date', 'DESC').all())
const simpleDate = (date: Date) => {
date.setDate(date.getDate() + 1)
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
}
const { data: articles } = await useAsyncData('articles', () => queryCollection('blog')
.where('date', '<', simpleDate(new Date()))
.order('date', 'DESC')
.all(),
)
const firstTen = computed(() => {
if (route.query.category) {
@ -49,13 +58,13 @@ const allCategoriesAndCount = computed(() => {
const makeBlogCard = (article: BlogCollectionItem) => ({
title: article.title,
description: article.description,
image: article.meta.image as string,
image: article.thumbnail as string,
date: article.date as string,
excerpt: article.excerpt,
excerpt: article.excerpt as any,
link: article.path,
tags: article.meta.tags as string[],
category: article.meta.category as Category,
author: article.meta.author as { name: string, image: string },
tags: article.tags as string[],
category: article.category as Category,
author: article.author as { name: string, image: string },
})
useHead({