#Access mdx metadata
22 messages · Page 1 of 1 (latest)
I'm guessing this is part of remark-gfm using https://github.com/remarkjs/remark-frontmatter
I wrote a script that would walk through all my mdx files, grab the meta data, and saved them into a JSON file at build time then exposed it with a loader$.
I used that to create pagination and do some custom stuff in a layout file
Yeah I was thinking of a similar approach, but I'd like to use SSG just like the docs website does. Weird, because metadata is encoded in the docs but I don't see it used anywhere
for now stuff like
<span q:slot="title">Testing</span>
works but this is rather bad
you could always import the JSON without a loader then?
Yeah regular import could work, hmm
Probably better, since the content is static anyway.
I'll look into making a singular "data" file from which I can export individual content,
thanks for the pointers 😁
Should be part of the page bundle, rendered on the server and complete on browser
Sure not a problem! im happy to share my script. it isnt pretty but gets the job done haha
Yeah it's a lot of trying and guessing with newer frameworks haha
I'll consider this complete for now, probably a good idea as a feature to make that frontmatter metadata available, but its more a feature request.
Thanks a lot again btw 😄
I'll see if I can format this nicely for a feature request
@hoary cargo After some poking around in the code, seems like there was a PR previously to include it in the export.
You can access it via the useDocumentHead() hook as the frontmatter object.
Be aware that certain keys are filtered though, it seems like title and author for example are filtered.
Weird, but able to circumvent via title_ and author_, probably need to file an issue about that. 🤔
Have a nice evening!
---
title: test
title_: Test
author_:
name: frammie
avatar: me.png
words: 4032
---
You can access both title and author via useDocumentHead(). Author is available in the meta object. And title is available in the title key.
Assuming, const head = useDocumentHead();
You can access the title with head.title and the the author with head.meta.filter((v) => v.name=='author')[0].content. Not sure if there is a better way to get the author.