Support <script id="data" type="application/json">
blocks for more easily embedding data in html
#1074
Closed
marceloverdijk
started this conversation in
Proposal
Replies: 1 comment 1 reply
-
It's already possible using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Body
Summary
Please add support for
<script id="data" type="application/json">
blocks based on data from frontmatter.Background & Motivation
Currently there are 2 ways to pass frontmatter data to client script:
The first suggests to use
data-*
attributes on components or html elements, and the second suggests:causing the data var to be put in a IIFE:
which is not useful in all cases, as it cannot be accessed outside.
For SSG websites it would be useful to be able to more easily embed data in html,
and the good thing is html has something for that:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#embedding_data_in_html
Goals
A concise, bulleted-list outlining the intended goals of this RFC.
Example
const people = [..];
<script id="people-data" type="application/json"> {JSON.stringify(people)} </script>Beta Was this translation helpful? Give feedback.
All reactions