-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added
@storyblok/richtext
and types
- Loading branch information
1 parent
c1627b3
commit c478211
Showing
9 changed files
with
185 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script setup lang="ts"> | ||
import { useSbRichtext } from "../composables/useRichText"; | ||
const props = defineProps<{ doc: any; resolvers?: any }>(); | ||
const { render } = useSbRichtext({ | ||
resolvers: props.resolvers, | ||
}); | ||
const root = () => render(props.doc); | ||
</script> | ||
|
||
<template> | ||
<root /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { VNode } from "vue"; | ||
import { createTextVNode, h } from "vue"; | ||
/* import { RouterLink } from 'vue-router' | ||
*/ | ||
import type { | ||
Node, | ||
NodeResolver, | ||
SbRichtextOptions, | ||
} from "@storyblok/richtext"; | ||
import { | ||
BlockTypes, | ||
/* MarkTypes, */ richTextResolver, | ||
} from "@storyblok/richtext"; | ||
import { StoryblokComponent } from "@storyblok/vue"; | ||
|
||
const componentResolver: NodeResolver<VNode> = (node: Node<VNode>): VNode => { | ||
return h( | ||
StoryblokComponent, | ||
{ | ||
blok: node?.attrs?.body[0], | ||
id: node.attrs?.id, | ||
}, | ||
node.children | ||
); | ||
}; | ||
|
||
export function useSbRichtext(options: SbRichtextOptions<VNode>) { | ||
const mergedOptions: SbRichtextOptions<VNode> = { | ||
renderFn: h, | ||
textFn: createTextVNode, | ||
resolvers: { | ||
/* [MarkTypes.LINK]: (node: Node<VNode>) => { | ||
return node.attrs?.linktype === 'STORY' | ||
? h(RouterLink, { | ||
to: node.attrs?.href, | ||
target: node.attrs?.target, | ||
}, node.text) | ||
: h('a', { | ||
href: node.attrs?.href, | ||
target: node.attrs?.target, | ||
}, node.text) | ||
}, */ | ||
[BlockTypes.COMPONENT]: componentResolver, | ||
...options.resolvers, | ||
}, | ||
}; | ||
return richTextResolver<VNode>(mergedOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters