oekazuma / svelte-meta-tags

Svelte Meta Tags provides components designed to help you manage SEO for Svelte projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Schema Can be an Array

jdgamble555 opened this issue · comments

A JSON-LD schema can be an array of items. This should be accepted:

https://stackoverflow.com/a/32954313/271450
https://stackoverflow.com/questions/48294593/how-do-you-combine-several-json-ld-markups/48295719#48295719

If it is an array, the @context could be added to each item.


Here is one option:

	// create schema with context
	function createSchema(schema: any) {
		// add context
		const addContext = (c: any) => ({ '@context': 'http://schema.org', ...c });

		// handle object
		if (!Array.isArray(schema)) {
			return addContext(schema);
		}

		// handle array
		schema = schema.map((v) => addContext(v));
		return schema.length === 1 ? schema[0] : schema;
	}

	$: json = `${'<scri' + 'pt type="application/ld+json">'}${JSON.stringify(createSchema(schema))}${
		'</scri' + 'pt>'
	}`;

J

I think this is a good suggestion.
I will work on it when I have time.

For now, this can be handled by writing multiple <JsonLd />.

🎉 This issue has been resolved in version 2.7.0 🎉

The release is available on:

npm package (@latest dist-tag)
GitHub release

docs: JSON-LD Multiple Examples