Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

An Astro native portable text solution #27

Open
runeb opened this issue Jul 15, 2023 · 0 comments
Open

An Astro native portable text solution #27

runeb opened this issue Jul 15, 2023 · 0 comments

Comments

@runeb
Copy link

runeb commented Jul 15, 2023

Thank you for this project! I have one request regarding the portable text handling in this project. The way it is currently handled is by rendering to html via @portabletext/[email protected] and setting the html string directly on a fragment.

There is an Astro native way to do this which lets you emit Astro components instead: https://github.com/theisel/astro-portabletext. Would you consider updating your project to leverage this module instead?

It then becomes

---
import { PortableText } from "astro-portabletext";
import Code from "./Code.astro";
const {portableText} = Astro.props;

const components = {
  type: {
    code: Code
  },
}
---

<PortableText
  value={portableText}
  components={components}
/>

And you can write proper Astro components for your custom types

---
import { Prism } from '@astrojs/prism';
const {node} = Astro.props;
const {code, language} = node;
---

<Prism lang={language} code={code}></Prism>

Thanks again for the work on this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant