fix: filter
filter also reacting to external posts
This commit is contained in:
parent
5681454b61
commit
7038e47c75
1 changed files with 12 additions and 11 deletions
|
@ -48,17 +48,6 @@ const firstTen = computed<BlogCard[]>(() => {
|
||||||
return (articles.value?.slice(0, 10) ?? []).map(makeBlogCard)
|
return (articles.value?.slice(0, 10) ?? []).map(makeBlogCard)
|
||||||
})
|
})
|
||||||
|
|
||||||
const allCategoriesAndCount = computed<Record<Category, number>>(() => {
|
|
||||||
const categories = {} as Record<Category, number>
|
|
||||||
articles.value?.forEach(article => {
|
|
||||||
const category = article.category as Category
|
|
||||||
if (category) {
|
|
||||||
categories[category] = (categories[category] ?? 0) + 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return categories
|
|
||||||
})
|
|
||||||
|
|
||||||
const { data: externalPostsRaw } = useFetch('/api/external-posts', { method: 'POST' })
|
const { data: externalPostsRaw } = useFetch('/api/external-posts', { method: 'POST' })
|
||||||
|
|
||||||
const externalPosts = computed<BlogCard[]>(() => externalPostsRaw.value?.flatMap(externalBlog => {
|
const externalPosts = computed<BlogCard[]>(() => externalPostsRaw.value?.flatMap(externalBlog => {
|
||||||
|
@ -75,6 +64,18 @@ const externalPosts = computed<BlogCard[]>(() => externalPostsRaw.value?.flatMap
|
||||||
|
|
||||||
const allPosts = computed<BlogCard[]>(() => [...(firstTen.value ?? []), ...(externalPosts.value ?? [])].sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()))
|
const allPosts = computed<BlogCard[]>(() => [...(firstTen.value ?? []), ...(externalPosts.value ?? [])].sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()))
|
||||||
|
|
||||||
|
const allCategoriesAndCount = computed<Record<Category, number>>(() => {
|
||||||
|
const categories = {} as Record<Category, number>
|
||||||
|
articles.value?.forEach(article => {
|
||||||
|
const category = article.category as Category
|
||||||
|
if (category) {
|
||||||
|
categories[category] = (categories[category] ?? 0) + 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
categories['extern'] = externalPosts.value?.length ?? 0
|
||||||
|
return categories
|
||||||
|
})
|
||||||
|
|
||||||
const makeBlogCard = (article: BlogCollectionItem): BlogCard => ({
|
const makeBlogCard = (article: BlogCollectionItem): BlogCard => ({
|
||||||
title: article.title,
|
title: article.title,
|
||||||
description: article.description,
|
description: article.description,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue