Handle optional 'tags' field in blog posts
A conditional chaining operator has been added while mapping over post data tags to handle cases where the 'tags' field might not be present. This prevents the application from crashing in case 'tags' is undefined for a particular blog post.
This commit is contained in:
parent
a5c2e6bbde
commit
b9ad4143a5
1 changed files with 1 additions and 1 deletions
|
@ -84,7 +84,7 @@ const { post } = Astro.props;
|
||||||
|
|
||||||
<div class="space-x-2">
|
<div class="space-x-2">
|
||||||
{
|
{
|
||||||
post.data.tags.map((tag: string) => (
|
post.data.tags?.map((tag: string) => (
|
||||||
<span class="inline-flex items-center gap-x-1.5 rounded-lg bg-neutral-400/30 px-3 py-1.5 text-xs font-medium text-neutral-700 outline-none focus:outline-none focus-visible:outline-none focus-visible:ring dark:bg-neutral-700/60 dark:text-neutral-300">
|
<span class="inline-flex items-center gap-x-1.5 rounded-lg bg-neutral-400/30 px-3 py-1.5 text-xs font-medium text-neutral-700 outline-none focus:outline-none focus-visible:outline-none focus-visible:ring dark:bg-neutral-700/60 dark:text-neutral-300">
|
||||||
{capitalize(tag)}
|
{capitalize(tag)}
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue