-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render Blok Components within RichText #476
Comments
Hi, @joezimjs, you are completely right in your statement; thanks for sharing your concerns with us. Actually, the Astro implementation is our first try at introducing this in our SDKs (I see you fast there 😏). As Astro is kind of new as an SDK in our list, it is easy to test new initiatives (it is less used by our clients) to then introduce this in the rest of the SDKs, so sooner than later, this will be implemented to the Nuxt SDK too (@alexjoverm do you want to add anything here?). For now, about the links you mention, the 3rd one you should ignore it since we are using Nuxt 3 here, and that article is for the old Nuxt 2. For the FAQ and the runtime template compiler, for now, this is a working approach. I know it is not the ideal case, but for now, it is the simplest way. As we always say, this is a community effort, we are trying to provide the most features we can, but we don't have a dedicated team for the SDKs. We help when we have less workload, so please, if any day you want to do a pair programming session with me or one of my colleagues or open a PR with the features you need we will be so happy to see it happening! |
I got something working in my own repository by creating a custom |
Hmm... now that I'm thinking about it, there may be a better way that relies on the marks/nodes functionality that is defined for Also, I looked more closely at @storyblok/astro's implementation and it's not adequate to take care of bloks that are embedded inside other nodes (e.g. inside a bullet point item) because it only looks for bloks in the first level of content items, then renders the rest with the provided |
There! I changed it so it's all packed in one component and it takes advantage of the provided It's missing just a few things:
|
@joezimjs Thank you for your efforts on this. Here is how I added Just like we check the import { NuxtImg, NuxtLink } from '#components'
// use NuxtImg for images
if (node.type === 'image') {
return h(NuxtImg, {
provider: 'storyblok',
format: 'webp',
quality: 75,
src: node.attrs.src,
alt: node.attrs.alt,
title: node.attrs.title,
loading: 'lazy',
width: 700,
sizes: '90vw md:570px lg:700px',
})
} and since link is a if (tagItem.tag === 'a')
return h(NuxtLink, { ...tagItem.attrs }, () => [innerNode])
return h(tagItem.tag, tagItem.attrs, innerNode ? [innerNode] : undefined) |
I've done a very simple fix for this: <script setup lang="ts">
type Props = { text: any };
defineProps<Props>();
const renderText = (text: any) => {
const markup = { type: 'doc', content: [text] };
return renderRichText(markup);
};
</script>
<template>
<template v-if="text?.content" v-for="element in text?.content">
<template v-if="element.type === 'blok'" v-for="blok in element?.attrs?.body" :key="blok.id">
<component :is="blok.component" :blok />
</template>
<div v-else v-html="renderText(element)"></div>
</template>
</template> I haven't thoroughly texted it yet but seems to be working. |
@PP-Tom Looks pretty good but I don't think this will catch bloks that are embedded in a lower level of structure. For example, if you put a blok into a bullet point, the bulleted list will hit the To be fair, I was complaining that Astro had this implemented already while Nuxt still hadn't, but Astro implemented it in a very similar way to this, so it's like I'm the only person who cares about low-level embedded bloks... and I'm not even sure how much I care because I don't know if I have any use cases for it, but I see it as a blind spot for everyone who tries to implement this. |
Good point. I'm really surprised that StoryBlok's UI is built in Vue but it's been almost a year for a 1st party solution for this. I know it's a DX thing, but just surprised. |
Right?!? |
Hi @joezimjs @PP-Tom @Youhan jumping here to give some good news on I'm currently working on a framework agnostic solution for the Richtext Renderer that is potentially extendable to each major framework (vue, react etc). Between all the features the use-case for rendering Blok components is covered and was successfully tested on the PoC. And yes, it includes as well overwriting resolves like adding the The community has been very patient about this topic so I want to be transparent that there IS a work-in-progress solution for this, we just need to wait a little bit more so it's rolled out since we are discussing internally the DX. Hope this brings a little bit of light to this topic, will keep you posted. |
Love to hear it! |
So glad to hear that 😇 |
Sorry to bother this community but I wasted a lot of time trying to know why It was so confusing to have Rich Text component example available on the documentation to see there is not implementation yet. <StoryblokRichText :doc="blok.description" /> Please don't do that before implementing something because developers trust documentation. I was getting:
|
Hi @moracabanas, the module should be exporting the Could you please check if you are using the latest version of the module? If that's the case could you provide me a minimal reproduction link so I can help you? Thanks |
@joezimjs Did you have a chance to test the new component? https://stackblitz.com/~/edit/nuxt-starter-cwrbwd?file=app.vue |
That was my fault.. I will try to upgrade to 6. Thanks to point me to the right direction I will try that and see. |
@moracabanas no worries, we are here to help 😊, let me know if you find any issue in the future. |
Hi, @alvarosabu! I tested StoryblokRichText in my project and it handles blok components just fine, but I get the Also the real-time changes in Storyblok's visual editor don't seem to work properly when using this component, so I think it's worth to note that. |
Hi @danissima thanks for the feedback, yes I'm working on a quickfix for the warning. I will also check the visual editor topic to see if i can reproduce it since it was working before. Thanks |
Description
Right now, there's no built-in way to render Blok components within rich text. This is odd... why would you give us the ability to embed bloks inside our rich text and then completely ignore that inside your SDKs? Sure, there are several "solutions" thrown around, but they all have issues:
The Astro Storyblok SDK has implemented this directly. I'm honestly quite surprised this hasn't been done for a while now.
Suggested solution or improvement
Implement a
RichText
component that will render blok component where bloks are used. Also, it would be nice to allow the rich text resolver to return VNodes so we can render custom components there, but if the first thing is implemented, I'm not sure what use I'd have for this.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: