Plugin adding support for automatic handling of taxonomies with Nuxt Content.
# With Yarn
yarn add @thombruce/nuxt-taxonomies
# With npm
npm install @thombruce/nuxt-taxonomies --save
Add @thombruce/nuxt-taxonomies
to buildModules
in nuxt.config.js
:
buildModules: [
// ...
"@thombruce/nuxt-taxonomies",
// ...
],
<script>
export default {
async asyncData ({ $taxonomies }) {
// To list all tags found in /content/blog files
const tags = $taxonomies('tags', 'blog').all() // [{ slug: 'my-tag', title: 'My Tag' }, { slug: 'my-other-tag', title: 'My Other Tag' }]
return { tags }
}
}
<script>
export default {
async asyncData ({ $taxonomies }) {
// To retrieve a specific term
const term = $taxonomies('tags', 'blog').find('my-tag') // { slug: 'my-tag', title: 'My Tag' }
return { term }
}
}
</script>