Skip to content

feat: include json-ld #653

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

Merged
merged 3 commits into from
Jul 30, 2024
Merged

feat: include json-ld #653

merged 3 commits into from
Jul 30, 2024

Conversation

tripodsan
Copy link
Contributor

fixes #648

Copy link

This PR will trigger a minor release when merged.

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3eeaeb0) to head (273953b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #653   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           45        45           
  Lines         3558      3585   +27     
=========================================
+ Hits          3558      3585   +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -34,6 +35,13 @@ function createElement(name, ...attrs) {
return h(name, properties);
}

function sanitizeJsonLd(jsonLd) {
if (jsonLd.toLowerCase().indexOf('</script>') >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.parse() would throw anyway if string contained tags

Copy link
Contributor Author

@tripodsan tripodsan Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it could also be quoted:

<html>
<head>
	<script type="application/ld+json">
	{ "$foo": "</script><script type='application/javascript'>alert('hello')</script>" }
	</script>	
</head>
<body>
	test
</body>
</html>

@rofe
Copy link
Contributor

rofe commented Jul 29, 2024

It looks like the current implementation only supports a single json-ld property in the metadata block (last one wins?). I think we should add support for multiple, as there are several examples of pages that have more than one. Or can you combine multiple schema objects into a single script tag?

@tripodsan
Copy link
Contributor Author

tripodsan commented Jul 29, 2024

It looks like the current implementation only supports a single json-ld property in the metadata block (last one wins?). I think we should add support for multiple, as there are several examples of pages that have more than one. Or can you combine multiple schema objects into a single script tag?

the current implementation uses the last one defined.

this could be extended in the future by allowing all json-ld- prefixed properties to generate a script tag.
eg: json-ld-<name> -> <script data-name="<name>" type="application/ld+json">...

@davidnuescheler
Copy link

let's keep it simple for now, we can add support for multiple named ones later. i really don't think that's necessary, especially as all the current mechanisms (head.html and client-side) are still there and are working.

@tripodsan tripodsan merged commit f1c9f3f into main Jul 30, 2024
7 checks passed
@tripodsan tripodsan deleted the json-ld branch July 30, 2024 15:12
Copy link

🎉 This PR is included in version 6.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@hparra
Copy link
Contributor

hparra commented Aug 8, 2024

@rofe Using an array of JSON-LDs is valid

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

Successfully merging this pull request may close these issues.

[metadata] server-sided json-ld schema support
4 participants