mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-22 18:21:33 +08:00
feat: 允许tags不存在
This commit is contained in:
@ -76,7 +76,7 @@ const dateTimeOptions: Intl.DateTimeFormatOptions = {
|
|||||||
<path d='M6 9h-.01' />
|
<path d='M6 9h-.01' />
|
||||||
</svg>
|
</svg>
|
||||||
<div class='space-x-1'>
|
<div class='space-x-1'>
|
||||||
{data.tags.map((tag) => (
|
{data.tags?.map((tag) => (
|
||||||
<a
|
<a
|
||||||
aria-label={`View more blogs with the tag ${tag}`}
|
aria-label={`View more blogs with the tag ${tag}`}
|
||||||
class="inline-block before:content-['#'] hover:underline hover:underline-offset-4"
|
class="inline-block before:content-['#'] hover:underline hover:underline-offset-4"
|
||||||
|
@ -19,7 +19,7 @@ const post = defineCollection({
|
|||||||
.transform((val) => new Date(val)),
|
.transform((val) => new Date(val)),
|
||||||
coverImage: z.string().optional(),
|
coverImage: z.string().optional(),
|
||||||
draft: z.boolean().default(false),
|
draft: z.boolean().default(false),
|
||||||
tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
|
tags: z.array(z.string()).optional().default([]).transform(removeDupsAndLowerCase),
|
||||||
ogImage: z.string().optional(),
|
ogImage: z.string().optional(),
|
||||||
category: z.string().optional().nullable(),
|
category: z.string().optional().nullable(),
|
||||||
finished: z.boolean().default(false)
|
finished: z.boolean().default(false)
|
||||||
|
@ -16,7 +16,7 @@ export const getStaticPaths: GetStaticPaths = async ({ paginate }) => {
|
|||||||
const uniqueTags = getUniqueTags(allPostsByDate)
|
const uniqueTags = getUniqueTags(allPostsByDate)
|
||||||
|
|
||||||
return uniqueTags.flatMap((tag) => {
|
return uniqueTags.flatMap((tag) => {
|
||||||
const filterPosts = allPostsByDate.filter((post) => post.data.tags.includes(tag))
|
const filterPosts = allPostsByDate.filter((post) => post.data.tags?.includes(tag))
|
||||||
return paginate(filterPosts, {
|
return paginate(filterPosts, {
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
params: { tag }
|
params: { tag }
|
||||||
|
@ -18,7 +18,7 @@ export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
|
|||||||
|
|
||||||
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
||||||
export function getAllTags(posts: Array<CollectionEntry<'post'>>) {
|
export function getAllTags(posts: Array<CollectionEntry<'post'>>) {
|
||||||
return posts.flatMap((post) => [...post.data.tags])
|
return posts.flatMap((post) => [...(post.data?.tags ?? [])])
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
||||||
|
Reference in New Issue
Block a user