add: article view
View for blog articles
This commit is contained in:
parent
579491f216
commit
4104477533
15 changed files with 121 additions and 33 deletions
20
app/assets/css/blog/article.css
Normal file
20
app/assets/css/blog/article.css
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
4
app/assets/css/blog/excerpt.css
Normal file
4
app/assets/css/blog/excerpt.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
.Excerpt {
|
||||
font-size: 1.5rem;
|
||||
font-style: italic;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
.BlogOverview {
|
||||
& .category-list {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 1rem;
|
||||
list-style: none;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
app/components/Blog/Excerpt.vue
Normal file
9
app/components/Blog/Excerpt.vue
Normal file
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
<p class="Excerpt">
|
||||
<slot/>
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
|
@ -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>
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -7,6 +7,14 @@ export default defineContentConfig({
|
|||
source: 'blog/*.md',
|
||||
schema: z.object({
|
||||
date: z.string(),
|
||||
image: z.string(),
|
||||
thumbnail: z.string(),
|
||||
category: z.string(),
|
||||
tags: z.array(z.string()),
|
||||
author: z.object({
|
||||
name: z.string(),
|
||||
image: z.string(),
|
||||
}),
|
||||
excerpt: z.object({
|
||||
type: z.string(),
|
||||
children: z.any(),
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
image: 'https://picsum.photos/600/250?random=4'
|
||||
image: 'https://picsum.photos/1920/450?random=4'
|
||||
thumbnail: 'https://picsum.photos/750/250?random=4'
|
||||
title: 'Blogfussel - für mehr Fussel im Blog'
|
||||
description: 'Und nochmal...'
|
||||
navigation: true
|
||||
date: 2025-07-01
|
||||
date: 2025-06-11
|
||||
category: 'story'
|
||||
tags: [ 'start', 'story' ]
|
||||
author:
|
||||
|
@ -11,8 +11,9 @@ author:
|
|||
image: '/img/og.webp'
|
||||
---
|
||||
|
||||
Warum ich mich dazu entschlossen habe jetzt doch wieder mit dem Bloggen anzufangen? Nun ja, das hat alles angefangen, als man mich einfach so auf
|
||||
Instagram gesperrt hat.
|
||||
::blog-excerpt
|
||||
Warum ich mich dazu entschlossen habe jetzt doch wieder mit dem Bloggen anzufangen? Da muss ich etwas ausholen.
|
||||
::
|
||||
|
||||
<!-- more -->
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ image: 'https://picsum.photos/600/250?random=3'
|
|||
title: 'Post 1'
|
||||
description: 'Blablabla'
|
||||
navigation: true
|
||||
date: 2025-06-20
|
||||
date: 2025-05-20
|
||||
category: 'tutorial'
|
||||
tags: [ 'test', 'wasd' ]
|
||||
author:
|
||||
|
|
|
@ -3,7 +3,7 @@ image: 'https://picsum.photos/600/250?random=2'
|
|||
title: 'Post 2'
|
||||
description: 'Blablabla'
|
||||
navigation: true
|
||||
date: 2025-06-16
|
||||
date: 2025-05-16
|
||||
category: 'snippet'
|
||||
tags: [ 'test', 'asdf' ]
|
||||
author:
|
||||
|
|
|
@ -3,7 +3,7 @@ image: 'https://picsum.photos/600/250?random=1'
|
|||
title: 'Post 3'
|
||||
description: 'Blablabla'
|
||||
navigation: true
|
||||
date: 2025-06-25
|
||||
date: 2025-05-25
|
||||
category: 'freelancing'
|
||||
tags: [ 'test', '123' ]
|
||||
author:
|
||||
|
|
|
@ -3,7 +3,7 @@ image: 'https://picsum.photos/600/250?random=5'
|
|||
title: 'Post 4'
|
||||
description: 'Blablabla'
|
||||
navigation: true
|
||||
date: 2025-06-25
|
||||
date: 2025-05-25
|
||||
category: 'news'
|
||||
tags: [ 'test', '123' ]
|
||||
author:
|
||||
|
|
|
@ -46,6 +46,8 @@ export default defineNuxtConfig({
|
|||
'~/assets/css/blog/card.css',
|
||||
'~/assets/css/blog/author.css',
|
||||
'~/assets/css/blog/overview.css',
|
||||
'~/assets/css/blog/article.css',
|
||||
'~/assets/css/blog/excerpt.css',
|
||||
],
|
||||
|
||||
postcss: {
|
||||
|
|
|
@ -17,11 +17,19 @@ const makeItem = (article: BlogCollectionItem, base: string) => `
|
|||
</item>
|
||||
`
|
||||
|
||||
const simpleDate = (date: Date) => {
|
||||
date.setDate(date.getDate() + 1)
|
||||
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
|
||||
}
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
const baseUrl = getRequestURL(event)
|
||||
const blogUrl = `${baseUrl.protocol}//${baseUrl.host}`
|
||||
|
||||
const articles = (await queryCollection(event, 'blog').order('date', 'DESC').all())
|
||||
const articles = await queryCollection(event, 'blog')
|
||||
.where('date', '<', simpleDate(new Date()))
|
||||
.order('date', 'DESC')
|
||||
.all()
|
||||
|
||||
const xmlItems = articles.map(article => makeItem(article, blogUrl)).join('')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue