I'm writing my blog with Nuxt Content which can filter posts based on their properties. One of my properties is tags
. Now I would like to create a page for each tag.
My current solution works, but the query is case-sensitive, where I would really like it to be case-insensitive.
<script>
export default {
async asyncData({ $content, params }) {
const tag = params.tag
const articles = await $content('blog', params.slug)
.where({ tags: { $contains: tag } })
.only(['title', 'slug', 'description', 'createdAt', 'body'])
.sortBy('createdAt', 'asc')
.fetch()
return { articles, tag }
},
}
</script>
Based on the LokiJS documentation I tried to use a function in the where
function, but that returns all posts, instead of just the posts for the given tag.
<script>
export default {
async asyncData({ $content, params }) {
const tag = params.tag
const articles = await $content('blog', params.slug)
.where(function (article) {
return article.tags
.map((tag) => tag.toLowerCase())
.contains(params.tag.toLowerCase())
})
.only(['title', 'slug', 'description', 'createdAt', 'body'])
.sortBy('createdAt', 'asc')
.fetch()
return { articles, tag }
},
}
</script>
So how should I write the query in order to get articles that contain the tags without having to worry about case-sensitivity.