nuxt / content

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

use of flatUnwrap and ContentSlot[unwrap] per the docs doesn't iterate properly through content #2372

Open samcarrington opened 1 year ago

samcarrington commented 1 year ago

Environment

Reproduction

https://stackblitz.com/edit/nuxt-starter-zfuxp6?file=content%2Findex.md,components%2Fcontent%2FcontentList.vue

Describe the bug

Using the useUnwrap composable to unpack and re-render a list from a markdown file no longer effectively iterates through list items in the pass-through of the used slot from the iteration through flatUnwrap into the ContentSlot component.

The v-for iteration runs through the correct number of items, but the ContentSlot :use and unwrap parameters have no effect on the output, and the whole content of the list is rendered into each item rather than a single item.

Additional context

No response

Logs

No response

Lexpeartha commented 11 months ago

The only work around I found for this is to pin version to ~2.7.X and do workaround mentioned in nuxt/content#2254 Latter is only needed if you want to use nuxt 3.7+

mklueh commented 8 months ago

Any news on this?

I'd also wish the docs would cover how to use it. I had no idea how the list should look like in my markdown and thought you'd do something like this

. a
. b
. c

the markdown side on how to use named slots other than "default" is also not covered

gsabater commented 7 months ago

I'm having the same issue, right now im worndering if I should use two components or props to print the list items, but as of now, the iteration of list items using <ContentSlot :use="() => item" unwrap="li" /> is not working

samcarrington commented 1 month ago

This implementation has been broken over a year now - behaves contrary to the docs and doesn't iterate list items properly.

masterkram commented 1 month ago

Hello, I have also been having this issue. I came up with a workaround of making my List component from scratch: Did not manage to understand however, why the approach with ContentSlot duplicates the list. Hope this helps.

<script setup lang="ts">
const { flatUnwrap, unwrap } = useUnwrap()
import { resolveComponent } from 'vue';

const slots = useSlots();

function renderListElements() {
  return flatUnwrap(slots.default!(), ['ul']
  ).map((element: any) => h(resolveComponent('MDCSlot'), { use: () => element, unwrap: 'li' }));
}

</script>

<template>
  <ul class="not-prose">
    <li v-for="el in renderListElements()">
      <Icon name="tabler:check" />
      <span>
        <component :is="() => unwrap(el, ['li'])" />
      </span>
    </li>
  </ul>
</template>