Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
Filter Posts in Next JS

I want to filter the posts by tag.The tag can use {post.frontmatter.tag} to get.When I try to add that into filter but it don't work. there are error msg:TypeError: Cannot read properties of undefined (reading 'includes')


I get the meta by the frontmatter such as {post.frontmatter.tag}.It is working.There are code:

      <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)
    }
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!