fix: no 'uncategorized' category in categories page
This commit is contained in:
parent
6e89919cd4
commit
b103c045e2
3 changed files with 12 additions and 7 deletions
|
@ -5,8 +5,8 @@ export const posts = ({ image }) => z.object({
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
pubDate: z.coerce.date(),
|
pubDate: z.coerce.date(),
|
||||||
updatedDate: z.coerce.date().optional(),
|
updatedDate: z.coerce.date().optional(),
|
||||||
categories: z.array(z.string()).optional().default(['uncategorized']),
|
categories: z.array(z.string()).default(['uncategorized']),
|
||||||
tags: z.array(z.string()).optional().default([]),
|
tags: z.array(z.string()).optional(),
|
||||||
cover: image().optional(),
|
cover: image().optional(),
|
||||||
author: z.string().optional(),
|
author: z.string().optional(),
|
||||||
});
|
});
|
|
@ -7,6 +7,8 @@ tags:
|
||||||
- 'design'
|
- 'design'
|
||||||
- 'code'
|
- 'code'
|
||||||
- 'minimalism'
|
- 'minimalism'
|
||||||
|
categories:
|
||||||
|
- 'thinking'
|
||||||
---
|
---
|
||||||
|
|
||||||
Minimalism isn't just about having less, it's about making room for what matters.
|
Minimalism isn't just about having less, it's about making room for what matters.
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
---
|
---
|
||||||
import Layout from '../../layouts/Layout.astro';
|
import Layout from '../../layouts/Layout.astro';
|
||||||
import {getCollection} from "astro:content";
|
import {getCollection} from "astro:content";
|
||||||
import {categoryLabel} from "astro/client/dev-toolbar/apps/audit/rules";
|
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const allPosts = await getCollection('posts');
|
const allPosts = await getCollection('posts');
|
||||||
console.log(allPosts)
|
// Get all categories, ensuring the default 'uncategorized' is used when categories is undefined
|
||||||
const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories ? post.data.categories : []).flat())];
|
const uniqueCategories = [...new Set(allPosts.map((post: any) =>
|
||||||
|
post.data.categories || ['uncategorized']).flat())];
|
||||||
|
|
||||||
return uniqueCategories.map((category) => {
|
return uniqueCategories.map((category) => {
|
||||||
const filteredPosts = allPosts.filter((post: any) => post.data.categories?.includes(category));
|
const filteredPosts = allPosts.filter((post: any) =>
|
||||||
|
(post.data.categories || ['uncategorized']).includes(category));
|
||||||
return {
|
return {
|
||||||
params: { category },
|
params: { category },
|
||||||
props: { posts: filteredPosts },
|
props: { posts: filteredPosts },
|
||||||
|
@ -30,4 +32,5 @@ const { posts } = Astro.props;
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue