solidjs / solid-meta

Write meta tags to the document head
131 stars 18 forks source link

Support for JSON-LD #23

Open vilarfg opened 2 years ago

vilarfg commented 2 years ago

Perhaps I missed something, but it seems solid-meta doesn't currently expose a way to set json-ld on the head.

JSON-LD is Google's preferred schema markup and it's kind of a big deal for SEO.

I am currently trying out Solid Start and couldn't find a way to set it up, I was expecting we could do something like:

<Script type="application/ld+json">{"json linked data goes here as a string"}</Script>

Anyway, I am about to open a PR that would allow us to do:

<JSONLD>{{ key: "value", ... }}</JSONLD>

which, IMO, would be even more ergonomic.

I don't like the fact that JSONLD is all caps. Maybe we can find a better name. Please let us not choose: JavaScriptObjectNotationLinkedData :joy:

ryansolid commented 2 years ago

Hmm... special casing it vs just making it a Script tag probably goes beyond the scope of this project, keeping things minimal wrapper over native elements. You could always wrap it if we supported inserting script tags which we don't as of yet. I think we've collected a few reasons to do that now.

So it's probably worth adding Script tags. Meta tags/Title have certain overriding characteristics and I guess Script would just insert until unmounted. Mostly haven't added it yet because the library this library is based on never did.

Only thing I'm pondering is if limiting it in the proposed way provides some advantage over script. Ergonomics aside I wonder if there are security considerations of generic script insertion.

vilarfg commented 2 years ago

Only thing I'm pondering is if limiting it in the proposed way provides some advantage over script. Ergonomics aside I wonder if there are security considerations of generic script insertion.

@ryansolid exactly

That's why I came up with <JSONLD>: as it enforces type="application/ld+json" and takes care of the stringification it would do away with the security concerns.

Another idea would be just to export MetaTag.