[Suggestion] use JSON-LD php generator
jimblue opened this issue · comments
Hi Paul,
As we talked about it on Slack, here the php library that can generate JSON-LD: https://github.com/Torann/json-ld
It would be a bit of work to migrate your plugin to use this library.
But in the end it will definitively help you out to speed up development when adding new microdata
support.
Cheers
Hi Jim,
Following our discussion, I post here rather than slack in case other people who knows this library can give insight.
I took another look, but I don't really see how this could help.
Here is how things are done with the json-ld library:
$context = \JsonLd\Context::create('news_article', [
'headline' => 'Article headline',
'description' => 'A most wonderful article',
'mainEntityOfPage' => [
'url' => 'https://google.com/article',
],
'image' => [
'url' => 'https://google.com/thumbnail1.jpg',
'height' => 800,
'width' => 800,
],
'datePublished' => '2015-02-05T08:00:00+08:00',
'dateModified' => '2015-02-05T09:20:00+08:00',
'author' => [
'name' => 'John Doe',
],
'publisher' => [
'name' => 'Google',
'logo' => [
'url' => 'https://google.com/logo.jpg',
'width' => 600,
'height' => 60,
]
],
]);
And here is how it's done in the plugin:
if ($page->header()->articleenabled and $this->config['plugins']['seo']['article']) {
$microdata['article'] = [
'@context' => 'http://schema.org',
'@type' => 'Article',
'headline' => @$headline ,
'mainEntityOfPage' => [
"@type" => "WebPage",
'url' => $this->grav['uri']->base(),
],
'articleBody' => @$this->cleanMarkdown($content),
'datePublished' => @date("c", $page->date()),
'dateModified' => @date("c", $page->modified()),
];
So both are very similar
The most difficult part with Grav is more on the blueprint-side imo. With a few microdata, it already adds tons of fields, and I would rather have some basic blueprint, and a chained-select like this: https://appelsiini.net/projects/chained/ + the multilevel field.
This would allow users to add other value manually and build more complex microdata.
I got your point ! You're right, this library it's not really helpful in the end. I close this.