Skip to content

Commit

Permalink
Support null tags
Browse files Browse the repository at this point in the history
  • Loading branch information
narze committed Dec 15, 2023
1 parent 1d3783b commit 9467e76
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"npm-run-all": "^4.1.5",
"octokit": "^3.1.0",
"pagefind": "^0.12.0",
"prettier-plugin-astro": "^0.12.2",
"remark": "^14.0.3",
"remark-frontmatter": "^4.0.1",
"rimraf": "^5.0.1",
Expand Down
40 changes: 39 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 24 additions & 13 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const blog = defineCollection({
heroImage: z.string().optional(),
draft: z.boolean().optional(),
filepath: z.string().optional(), // Added from add-filepath plugin
tags: z.array(z.string().or(z.null())).optional(),
tags: z
.array(z.any())
.default([])
.nullable()
.transform((arr) => (arr ? arr.map((item) => String(item)) : [])),
}),
})

Expand All @@ -42,18 +46,25 @@ const secondBrain = defineCollection({
draft: z.boolean().optional(),
filepath: z.string(), // Added from add-filepath plugin
tags: z
.array(
z
.string()
.refine(
(tag) => !/\s/.test(tag),
(tag) => ({
message: `Tag "${tag}" cannot include whitespaces`,
})
)
.or(z.null())
)
.optional(),
.array(z.any())
.nullable()
.default([])
.transform((arr) => (arr ? arr.map((item) => String(item).trim()) : []))
.refine(
(arr) =>
arr.every(
(item) =>
z
.string()
.refine((value) => !/\s/.test(value), {
message: "String must not contain whitespaces",
})
.safeParse(item).success
),
{
message: "Array elements must not contain whitespaces",
}
),
}),
})

Expand Down
4 changes: 3 additions & 1 deletion src/layouts/SecondBrainPost.astro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const { slug } = Astro.params

<!-- Tags -->
{
tags && tags.length && (
tags && tags.length ? (
<div class="flex gap-1">
{tags.map(
(tag) =>
Expand All @@ -50,6 +50,8 @@ const { slug } = Astro.params
)
)}
</div>
) : (
""
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/pages/second-brain/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const secondBrainPosts = await getCollection("second-brain", ({ data }) => {
{
secondBrainPosts.map((post) => (
<li>
<a href={`/${post.slug}/`} transition:name={`entry-${post.slug}`}>{post.data.title || post.id}</a>
<a href={`/${post.slug}/`} transition:name={`entry-${post.slug}`}>
{post.data.title || post.id}
</a>
</li>
))
}
Expand Down

0 comments on commit 9467e76

Please sign in to comment.