-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): enable custom text rendering in PortableText (#165)
Provides users with fine-grained control over text node output via the new `text` option
- Loading branch information
Showing
13 changed files
with
355 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
import type { TextNode, Props as $ } from "../lib/types"; | ||
export type Props = $<TextNode>; | ||
const { node } = Astro.props; | ||
--- | ||
|
||
{node.text} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
import type { TextNode, Props as $ } from "astro-portabletext/types"; | ||
export type Props = $<TextNode>; | ||
const { node } = Astro.props; | ||
const replacedText = node.text.replace('programmer', 'JavaScript developer').replace('arrays', 'callbacks'); | ||
--- | ||
|
||
{replacedText} |
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,17 @@ | ||
--- | ||
import type { TextNode, Props as $ } from "astro-portabletext/types"; | ||
export type Props = $<TextNode>; | ||
const { node } = Astro.props; | ||
--- | ||
|
||
{node.text.split(' ').map((it, idx) => idx === 0 ? ( | ||
<> <span>{it}</span></> | ||
) : it)} | ||
|
||
<style> | ||
span { | ||
color: yellow; | ||
} | ||
</style> |
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,19 @@ | ||
--- | ||
import type { TextNode, Props as $ } from "astro-portabletext/types"; | ||
export type Props = $<TextNode>; | ||
const { node, index } = Astro.props; | ||
--- | ||
{index === 1 ? ( | ||
<> | ||
| ||
<span>{node.text.trim()}</span> | ||
</> | ||
) : node.text} | ||
|
||
<style> | ||
span { | ||
color: green; | ||
} | ||
</style> |
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,20 @@ | ||
--- | ||
import { PortableText } from "astro-portabletext"; | ||
import Layout from "../../layouts/Default.astro"; | ||
const blocks = [ | ||
{ | ||
_type: "block", | ||
children: [ | ||
{ | ||
_type: "span", | ||
text: "hello world", | ||
}, | ||
], | ||
}, | ||
]; | ||
--- | ||
|
||
<Layout> | ||
<PortableText value={blocks} /> | ||
</Layout> |
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,21 @@ | ||
--- | ||
import { PortableText } from "astro-portabletext"; | ||
import Layout from "../../layouts/Default.astro"; | ||
import TextReplace from '../../components/TextReplace.astro'; | ||
const blocks = [ | ||
{ | ||
_type: "block", | ||
children: [ | ||
{ | ||
_type: "span", | ||
text: "Why did the programmer quit his job? Because he didn't get arrays.", | ||
}, | ||
], | ||
}, | ||
]; | ||
--- | ||
|
||
<Layout> | ||
<PortableText value={blocks} components={{text: TextReplace}}/> | ||
</Layout> |
Oops, something went wrong.