Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use <script type="application/ld+json"> in <svelte:head> #2438

Closed
cudr opened this issue Apr 19, 2019 · 6 comments
Closed

Use <script type="application/ld+json"> in <svelte:head> #2438

cudr opened this issue Apr 19, 2019 · 6 comments
Labels

Comments

@cudr
Copy link
Contributor

cudr commented Apr 19, 2019

Good day!

Have we any solution to use json-ld in svelte:head?

I try insert it as @html string, but it rewrite all other head elements.

reproduction: https://v3.svelte.technology/repl?version=3.0.0-beta.28&gist=0337994512de9223053c6f24e34e7d04

@Conduitry
Copy link
Member

You could instead do

<svelte:head>
	<script type='application/ld+json'>{some_json}</script>
</svelte:head>

which doesn't have this problem.

But I do think that {@html} in <svelte:head> clearing everything else in the head is probably a bug.

@cudr
Copy link
Contributor Author

cudr commented Apr 19, 2019

@Conduitry, thanks!

But looks like in <script> inner value ignored.

reproduction: https://v3.svelte.technology/repl?version=3.0.0-beta.28&gist=0337994512de9223053c6f24e34e7d04

@Conduitry
Copy link
Member

Ah right, sorry I forgot about that. Non-top-level <script> and <style> tags are always left as-is and aren't parsed for Svelte syntax, partly because they're a lot more likely to naturally contain strings that could be confused with expressions in braces.

So, yeah I think using {@html} to insert the entire tag does seem like a reasonable way to do this, but that isn't working correctly currently.

@Rich-Harris
Copy link
Member

Released 3.4.4 with the fix

@ourway
Copy link

ourway commented Oct 15, 2019

It does not work.

 <script type="application/ld+json">{jsonLd}</script>

Any updates?

@ourway
Copy link

ourway commented Oct 15, 2019

OK, here is the correct way to use it:

{@html '<script type="application/ld+json">'+ JSON.stringify(jsonLd) + '</script>'}

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

No branches or pull requests

4 participants