Add Index Listener
This commit is contained in:
@@ -9,7 +9,6 @@ class MeilisearchEventMarkerListener
|
||||
{
|
||||
public function onParseTemplate(Template $template): void
|
||||
{
|
||||
// Exakter Template-Name – kein Raten
|
||||
if ($template->getName() !== 'mod_eventreader') {
|
||||
return;
|
||||
}
|
||||
@@ -21,7 +20,6 @@ class MeilisearchEventMarkerListener
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔥 Event vollständig laden (inkl. Custom-Felder)
|
||||
$event = CalendarEventsModel::findByPk($GLOBALS['objEvent']->id);
|
||||
|
||||
if ($event === null) {
|
||||
|
||||
@@ -2,79 +2,71 @@
|
||||
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||
|
||||
use Contao\Config;
|
||||
use Contao\PageModel;
|
||||
use Contao\StringUtil;
|
||||
use Contao\Config;
|
||||
|
||||
class MeilisearchPageMarkerListener
|
||||
{
|
||||
public function onOutputFrontendTemplate(string $buffer, string $template): string
|
||||
{
|
||||
// Nur Frontend-Seiten
|
||||
if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage'] instanceof PageModel) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$markers = $GLOBALS['MEILISEARCH_MARKERS'] ?? [];
|
||||
|
||||
$page = $GLOBALS['objPage'];
|
||||
$lines = ['MEILISEARCH'];
|
||||
|
||||
/*
|
||||
* PAGE-DATEN (immer vorhanden)
|
||||
*/
|
||||
$priority = (int) ($page->priority ?? 0);
|
||||
$keywords = trim((string) ($page->keywords ?? ''));
|
||||
// ======================
|
||||
// PAGE
|
||||
// ======================
|
||||
if ((int) $page->priority > 0) {
|
||||
$lines[] = 'page.priority=' . (int) $page->priority;
|
||||
}
|
||||
|
||||
// searchimage: Page → Fallback
|
||||
$searchImageUuid = null;
|
||||
if (!empty($page->keywords)) {
|
||||
$lines[] = 'page.keywords=' . trim($page->keywords);
|
||||
}
|
||||
|
||||
if (!empty($page->searchimage)) {
|
||||
$searchImageUuid = StringUtil::binToUuid($page->searchimage);
|
||||
$lines[] = 'page.searchimage=' . StringUtil::binToUuid($page->searchimage);
|
||||
}
|
||||
|
||||
if (!$searchImageUuid) {
|
||||
$fallback = Config::get('meilisearch_fallback_image');
|
||||
if ($fallback) {
|
||||
$searchImageUuid = StringUtil::binToUuid($fallback);
|
||||
// ======================
|
||||
// EVENT
|
||||
// ======================
|
||||
if (!empty($GLOBALS['MEILISEARCH_MARKERS']['event'])) {
|
||||
$event = $GLOBALS['MEILISEARCH_MARKERS']['event'];
|
||||
|
||||
if (!empty($event['priority'])) {
|
||||
$lines[] = 'event.priority=' . $event['priority'];
|
||||
}
|
||||
|
||||
if (!empty($event['keywords'])) {
|
||||
$lines[] = 'event.keywords=' . $event['keywords'];
|
||||
}
|
||||
}
|
||||
|
||||
// Page-Marker sammeln
|
||||
$markers['page'] = [
|
||||
'priority' => $priority > 0 ? $priority : null,
|
||||
'keywords' => $keywords !== '' ? $keywords : null,
|
||||
'searchimage' => $searchImageUuid,
|
||||
];
|
||||
// ======================
|
||||
// NEWS (später)
|
||||
// ======================
|
||||
if (!empty($GLOBALS['MEILISEARCH_MARKERS']['news'])) {
|
||||
$news = $GLOBALS['MEILISEARCH_MARKERS']['news'];
|
||||
|
||||
/*
|
||||
* MARKER AUFBAUEN
|
||||
*/
|
||||
$lines = [];
|
||||
$lines[] = 'MEILISEARCH';
|
||||
|
||||
foreach ($markers as $scope => $data) {
|
||||
if (!is_array($data)) {
|
||||
continue;
|
||||
if (!empty($news['priority'])) {
|
||||
$lines[] = 'news.priority=' . $news['priority'];
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value === null || $value === '' || $value === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lines[] = $scope . '.' . $key . '=' . $value;
|
||||
if (!empty($news['keywords'])) {
|
||||
$lines[] = 'news.keywords=' . $news['keywords'];
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn wirklich nichts da ist → nichts anhängen
|
||||
if (count($lines) === 1) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$marker =
|
||||
"\n<!--\n" .
|
||||
implode("\n", $lines) .
|
||||
"\n-->\n";
|
||||
$marker = "\n<!--\n" . implode("\n", $lines) . "\n-->\n";
|
||||
|
||||
return str_replace('</body>', $marker . '</body>', $buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user