This commit is contained in:
Jürgen Mummert
2025-12-22 22:18:45 +01:00
parent d9e0c2ef51
commit 4555315496
@@ -20,7 +20,7 @@ class MeilisearchPageMarkerListener
/* /*
* ===================== * =====================
* PAGE (Basis + Fallback) * PAGE (Basis)
* ===================== * =====================
*/ */
$pageImageUuid = null; $pageImageUuid = null;
@@ -38,28 +38,30 @@ class MeilisearchPageMarkerListener
if (!empty($page->searchimage)) { if (!empty($page->searchimage)) {
$pageImageUuid = StringUtil::binToUuid($page->searchimage); $pageImageUuid = StringUtil::binToUuid($page->searchimage);
$lines[] = 'page.searchimage=' . $pageImageUuid;
}
}
// Globales Fallback (nur wenn Page kein Bild hat)
if (!$pageImageUuid) {
$fallback = Config::get('meilisearch_fallback_image');
if ($fallback) {
$pageImageUuid = StringUtil::binToUuid($fallback);
$lines[] = 'page.searchimage=' . $pageImageUuid;
} }
} }
/* /*
* ===================== * =====================
* EVENT (schema.org) * SCHEMA.ORG BLÖCKE
* ===================== * =====================
*/ */
if ( preg_match_all(
preg_match('#"@type"\s*:\s*"Event"#', $buffer) && '#<script type="application/ld\+json">\s*(\{.*?\})\s*</script>#s',
preg_match('#\\\/schema\\\/events\\\/(\d+)#', $buffer, $m) $buffer,
) { $jsonBlocks
);
foreach ($jsonBlocks[1] as $json) {
/*
* =====================
* EVENT
* =====================
*/
if (preg_match('#"@type"\s*:\s*"Event"#', $json)) {
if (preg_match('#\\\/schema\\\/events\\\/(\d+)#', $json, $m)) {
$event = CalendarEventsModel::findByPk((int) $m[1]); $event = CalendarEventsModel::findByPk((int) $m[1]);
if ($event !== null) { if ($event !== null) {
@@ -71,22 +73,25 @@ class MeilisearchPageMarkerListener
$lines[] = 'event.keywords=' . trim((string) $event->keywords); $lines[] = 'event.keywords=' . trim((string) $event->keywords);
} }
// 🔥 Event-Bild überschreibt Page-Bild
if ($event->addImage && !empty($event->singleSRC)) { if ($event->addImage && !empty($event->singleSRC)) {
$lines[] = 'event.searchimage=' . StringUtil::binToUuid($event->singleSRC); $lines[] = 'event.searchimage=' . StringUtil::binToUuid($event->singleSRC);
} }
} }
} }
if (preg_match('#"startDate"\s*:\s*"([^"]+)"#', $json, $dm)) {
$lines[] = 'event.date=' . $dm[1];
}
}
/* /*
* ===================== * =====================
* NEWS (schema.org) * NEWS
* ===================== * =====================
*/ */
if ( if (preg_match('#"@type"\s*:\s*"NewsArticle"#', $json)) {
preg_match('#"@type"\s*:\s*"NewsArticle"#', $buffer) &&
preg_match('#\\\/schema\\\/news\\\/(\d+)#', $buffer, $m) if (preg_match('#\\\/schema\\\/news\\\/(\d+)#', $json, $m)) {
) {
$news = NewsModel::findByPk((int) $m[1]); $news = NewsModel::findByPk((int) $m[1]);
if ($news !== null) { if ($news !== null) {
@@ -98,20 +103,39 @@ class MeilisearchPageMarkerListener
$lines[] = 'news.keywords=' . trim((string) $news->keywords); $lines[] = 'news.keywords=' . trim((string) $news->keywords);
} }
// 🔥 News-Bild überschreibt Page-Bild
if ($news->addImage && !empty($news->singleSRC)) { if ($news->addImage && !empty($news->singleSRC)) {
$lines[] = 'news.searchimage=' . StringUtil::binToUuid($news->singleSRC); $lines[] = 'news.searchimage=' . StringUtil::binToUuid($news->singleSRC);
} }
} }
} }
if (preg_match('#"datePublished"\s*:\s*"([^"]+)"#', $json, $dm)) {
$lines[] = 'news.date=' . $dm[1];
}
}
}
/*
* =====================
* PAGE IMAGE FALLBACK
* =====================
*/
if ($pageImageUuid) {
$lines[] = 'page.searchimage=' . $pageImageUuid;
} else {
$fallback = Config::get('meilisearch_fallback_image');
if ($fallback) {
$lines[] = 'page.searchimage=' . StringUtil::binToUuid($fallback);
}
}
if (count($lines) === 1) { if (count($lines) === 1) {
return $buffer; return $buffer;
} }
$marker = $marker =
"\n<!--\n" . "\n<!--\n" .
implode("\n", $lines) . implode("\n", array_unique($lines)) .
"\n-->\n"; "\n-->\n";
return str_contains($buffer, '</body>') return str_contains($buffer, '</body>')