Accessing Nuxt Content inside a Nuxt Module #3458
Unanswered
JoshuwayMorris
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Hey I struggled with this as well. I do not think it is possible from that specific event. The collections as a whole are never stored or emitted except through the dumps or sql file. I was able to solve a similar issue here: which will listen to the nuxt file:afterParse event and load it up in memeory. You can steal the BuildData class from that thread, and then build a collection of all the files nuxt-content has seen, or track it in another way export default defineNuxtModule({
meta: { name: 'your-nuxt-module' },
setup(_, nuxt) {
const build = new BuildData()
nuxt.hook('content:file:afterParse', (hook) => {
build.seen(hook)
})
nuxt.hook('build:done', () => {
// Do whatever with the data
})
}
}) You can do something similar in a module, eg: |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello 👋
I have a Nuxt Module within the
/modules
directory.Within this module, I listen for the
build:done
hook (i.e.nuxt.hook('build:done', ...
).Is it possible for me to access the Nuxt Content files within this hook? I am essentially trying to generate a JSON file that contains all of my Nuxt Content files.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions