I'm getting the error Cannot read properties of undefined (reading 'includes') on the following code, I can't seem to see what the problem is - I have this working on another project:
---
// @ts-nocheck
import { getCollection } from "astro:content";
import slugify from "slugify";
import CategoryLayout from "../../layouts/CategoryLayout.astro";
export async function getStaticPaths() {
const locations = await getCollection("locations");
const tags = [...new Set(locations.map((location) => location.data.tags).flat())];
return tags.map((tag) => {
const tagged = locations.filter((location) => location.data.tags.includes(tag));
return {
params: { tag: slugify(tag, { lower: true }) },
props: { tag: tag, locations: tagged }
};
});
}
const { tag, locations } = Astro.props;
---
<CategoryLayout title={tag} description="">
</CategoryLayout>
The entry in my content collection looks like:
---
title: Page
description: Desc
tags: [Historic Sites]
---