-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: turn FAQ answers RichText (#253)
* feat: turn FAQ answers in RichText * fix: add target="_blank" to RichText links * bump version
- Loading branch information
1 parent
b855a97
commit 6d5cf81
Showing
6 changed files
with
34 additions
and
8 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
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
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 |
---|---|---|
@@ -1,8 +1,21 @@ | ||
import { documentToReactComponents } from '@contentful/rich-text-react-renderer' | ||
import type { Document as ContentfulDocument } from '@contentful/rich-text-types' | ||
import { documentToReactComponents, type RenderNode, type Options } from '@contentful/rich-text-react-renderer' | ||
import { INLINES, type Document as ContentfulDocument, type Hyperlink } from '@contentful/rich-text-types' | ||
|
||
const options: Options = { | ||
renderNode: { | ||
[INLINES.HYPERLINK]: (node: Hyperlink) => { | ||
const text = node.content.find((item) => item.nodeType === 'text')?.value | ||
return ( | ||
<a href={node.data.uri} target="_blank" rel="noreferrer"> | ||
{text} | ||
</a> | ||
) | ||
}, | ||
} as unknown as RenderNode, | ||
} | ||
|
||
const RichText = (props: ContentfulDocument) => { | ||
return <>{documentToReactComponents(props)}</> | ||
return <>{documentToReactComponents(props, options)}</> | ||
} | ||
|
||
export default RichText |
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