Quiero filtrar las publicaciones por etiqueta. La etiqueta puede usar {post.frontmatter.tag} para obtener. Cuando intento agregar eso al filtro, pero no funciona. hay mensaje de error: TypeError: Cannot read properties of undefined (reading 'includes')
Obtengo el meta por el frontmatter como {post.frontmatter.tag} . Está funcionando. Hay código:
<Container> <Heading as="h3" fontSize={20} mb={4}> Blog </Heading> <Section delay={0.1}> <div className="posts"> {posts.filter(post => post.frontmatter.tag.includes('a')).map(filteredposts => ( <li>{filteredposts}</li> ))} </div> </Section> </Container> </layout> ) } export async function getStaticProps() { // Get files from the posts dir const files = fs.readdirSync(path.join('posts')) // Get slug and frontmatter from posts const posts = files.map(filename => { // Create slug const slug = filename.replace('.md', '') // Get frontmatter const markdownWithMeta = fs.readFileSync( path.join('posts', filename), 'utf-8' ) const { data: frontmatter } = matter(markdownWithMeta) return { slug, frontmatter } }) return { props: { posts: posts.sort(sortByDate) } } }