82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca;
|
|
|
|
final class ArticleSchema
|
|
{
|
|
private const CONTEXT = "https://schema.org";
|
|
|
|
public static function list(array $items, string $path, string $name, string $description): array
|
|
{
|
|
$url = Config::host() . $path;
|
|
$list = [];
|
|
foreach (array_values($items) as $index => $item) {
|
|
$list[] = ["@type" => "ListItem", "position" => $index + 1, "url" => $item["url"], "name" => $item["name"]];
|
|
}
|
|
|
|
return [
|
|
"@context" => self::CONTEXT,
|
|
"@graph" => [
|
|
[
|
|
"@type" => "CollectionPage",
|
|
"@id" => $url . "#webpage",
|
|
"url" => $url,
|
|
"name" => $name,
|
|
"description" => $description,
|
|
"inLanguage" => LANGUAGE_ID,
|
|
"about" => ["@id" => Config::host() . "/#store"],
|
|
"mainEntity" => ["@id" => $url . "#items"],
|
|
"workTranslation" => PageSchema::translations($path, "CollectionPage"),
|
|
],
|
|
[
|
|
"@type" => "ItemList",
|
|
"@id" => $url . "#items",
|
|
"url" => $url,
|
|
"numberOfItems" => count($list),
|
|
"itemListElement" => $list,
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
public static function detail(array $article): array
|
|
{
|
|
$url = Config::host() . $article["path"];
|
|
$store = ["@id" => Config::host() . "/#store"];
|
|
$node = [
|
|
"@type" => "Article",
|
|
"@id" => $url . "#article",
|
|
"url" => $url,
|
|
"headline" => $article["name"],
|
|
"description" => $article["description"],
|
|
"inLanguage" => LANGUAGE_ID,
|
|
"datePublished" => $article["published"],
|
|
"dateModified" => $article["modified"],
|
|
"author" => $store,
|
|
"publisher" => $store,
|
|
"wordCount" => $article["words"],
|
|
];
|
|
$page = [
|
|
"@type" => "WebPage",
|
|
"@id" => $url . "#webpage",
|
|
"url" => $url,
|
|
"name" => $article["name"],
|
|
"description" => $article["description"],
|
|
"inLanguage" => LANGUAGE_ID,
|
|
"mainEntity" => ["@id" => $url . "#article"],
|
|
"datePublished" => $article["published"],
|
|
"dateModified" => $article["modified"],
|
|
"workTranslation" => PageSchema::translations($article["path"], "WebPage"),
|
|
];
|
|
if ($article["image"]) {
|
|
$image = PageSchema::image($url . "#image", $article["image"]["url"], $article["image"]["width"], $article["image"]["height"]);
|
|
$node["image"] = $image;
|
|
$page["primaryImageOfPage"] = ["@id" => $url . "#image"];
|
|
}
|
|
|
|
return ["@context" => self::CONTEXT, "@graph" => [$page, $node]];
|
|
}
|
|
}
|