TIL: Array Map Async Callback

This questioned my knowledge of asynchronous javascript in general, and forced me to slow down for a second to take a refresher.

Ultimately, wrapping the array.map with a Promise.all() fixed the problems I was having

export const getStaticProps = async () => {
  const tweets = await Promise.all(
    tweetFilePaths.map(async (filePath) => {
      const source = fs.readFileSync(path.join(TWEETS_PATH, filePath))
      const { content, data } = matter(source)

      const serialized = await serialize(content)
      return serialized
    })
  )

  return { props: { tweets } }
}