nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.08k stars 624 forks source link

No queryContent from yml files when compatibility version 4 #2684

Closed DrDBanner closed 2 months ago

DrDBanner commented 2 months ago

Environment

Reproduction

nuxt.config.ts

// nuxt.config.ts
export default defineNuxtConfig({
  srcDir: 'app/',
  publicRuntimeConfig: {},
  privateRuntimeConfig: {},
  env: {
    BASE_URL: process.env.BASE_URL || 'http://localhost:3000',
  },
  devtools: {
    enabled: true
  },
  devServer: {
    port: 8080,
  },
  modules: [
    '@nuxt/icon',
    '@nuxt/content',
    '@bootstrap-vue-next/nuxt',
  ],
  css: ['bootstrap/dist/css/bootstrap.min.css',
       /* 'assets/styles/scss/global.scss',
        'assets/styles/css/global.css' */],
  bootstrapVueNext: {
    composables: true, // Will include all composables
    directives: {all: true}, // Will include all directives
  },
  content: {
  },
  future: {
   compatibilityVersion: 4
  },
})
//app/pages/index.vue
<script setup>
const { data } = await useAsyncData('', () => queryContent('/hello').findOne())
</script>

<template>
  <pre>
   data: {{ data }}
  </pre>
</template>
//  app/content/hello.yml

title: Foo
description: BAR beautiful & responsive Nuxt applications in minutes.
hero:
  title: Build your landing in seconds
  description: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.
  headline:
    label: Lorem ipsum dolor sit amet
    to: https://nuxt.com/fooo
    icon: i-heroicons-arrow-top-right-on-square-20-solid
  links:
    - label: Get started
      icon: i-heroicons-arrow-right-20-solid
      trailing: true
      to: '#features'
      size: xl
    - label: Use this template
      icon: i-simple-icons-github
      size: xl
      color: gray
      to: '#foo'
      target: _blank

Describe the bug

When compatibility version is set to 4 no data get displayed. If I switch to 3 the data gets displayed. When compatibility version is set to 3 the srcDir: 'app/‚ is mandatory.

Additional context

I'd assume to have it working with version 4 without additional configuration or change in syntax.

Logs

No response

liamsnowdon commented 2 months ago

Not 100% sure from your reproduction but looks like you've got the content directory inside the new app directory for compatibility version 4. I think the content directory needs to be in the rootDir/ instead of srcDir/. I had a similar issue with markdown files and doing this fixed it for me. This behaviour was changed in #2649, released in v2.13.0.

DrDBanner commented 2 months ago

Wow. Thanks!