Next.js Discord

Discord Forum

How to read mdx files from local files? What is leerob.io's 'contentlayer/generated' code?

Answered
ascee posted this in #help-forum
Open in Discord

17 Replies

Asian black bear
in tsconfig.json we can see that it is a paths alias to something generated at build (?) time
    "paths": {
      "contentlayer/generated": ["./.contentlayer/generated"]
    },
Asian black bear
It is made somehow by this package https://github.com/contentlayerdev/contentlayer
Answer
Asian black bear
It seems to maybe be indexing the MDX files to aid in navigation?
This is definitely a pretty complicated way if you want do just load some static MDX files, but a pretty good example of how to do a blog with metadata from the MDX posts like
---
title: 'Programming Portfolios'
publishedAt: '2017-02-24'
summary: 'Tips for creating a portfolio that stands out.'
---
but it might require some more understanding to initially work it out (for markdown, id say better, but just pages with jsx, harder)
in either case, try the built in Next MDX support first, it is pretty good
@ascee are you there/ do you understand what minabot and I shared...
Absolutely sorry for not replying! Was Trying these as you shared thank you so much
ahh yeah thats understandable
(i just wanted to make sure you didn't leave the server or give up like some do)
contentlayer is very good when you need typed metadata for mdx files
@riský ahh yeah thats understandable
we holding strong here