- Fixed the cross-theme blank search issue in [plugin.php](/Users/tyemeclifford/Documents/GH/blog/bl-plugins/search/plugin.php).

The important change: search still intercepts the route early, but 
before themes render it now feeds results through the normal 
home/listing state. That avoids themes going blank when they do not know 
how to render a custom search state.
I also made search safer:
Indexes raw page text instead of fully rendered content.
Uses raw content for excerpts.
Guards the search call so exceptions do not white-screen the page.
Updated Dark Neon so it still detects search pages correctly after this 
compatibility change.
This commit is contained in:
Ty Clifford
2026-07-03 09:34:49 -04:00
parent 9d9790976a
commit d149a0bf8f
3 changed files with 22 additions and 9 deletions
+15 -4
View File
@@ -491,7 +491,14 @@ EOF;
$this->searchTerm = $stringToSearch;
// Search the string in the cache and get all pages with matches
$list = $this->search($stringToSearch);
try {
$list = $this->search($stringToSearch);
} catch (Exception $e) {
if (class_exists('Log')) {
Log::set(__METHOD__ . LOG_SEP . 'Search failed: ' . $e->getMessage());
}
$list = array();
}
$this->numberOfItems = count($list);
// Split the content in pages
@@ -528,7 +535,9 @@ EOF;
if ($this->webhook($webhook, false, false)) {
global $url;
global $WHERE_AM_I;
$WHERE_AM_I = 'search';
// Feed search results through regular listing templates for theme compatibility.
$url->setWhereAmI('home');
$WHERE_AM_I = 'home';
// Get the pre-defined variable from the rule 69.pages.php
// We change the content to show in the website
@@ -537,7 +546,8 @@ EOF;
foreach ($this->pagesFound as $pageKey) {
try {
$page = new Page($pageKey);
$excerpt = $this->getSearchExcerpt($page->content(), $this->searchTerm);
$contentSource = method_exists($page, 'contentRaw') ? $page->contentRaw() : $page->content();
$excerpt = $this->getSearchExcerpt($contentSource, $this->searchTerm);
if (!empty($excerpt)) {
$page->setField('content', '<p class="search-result-excerpt">' . $this->highlightTerms($excerpt, $this->searchTerm) . '</p>');
}
@@ -690,7 +700,8 @@ EOF;
// Process content
$characterLimit = max(250, (int) $this->getValue('wordsToCachePerPage') * 6);
$content = Text::truncate($this->plainText($page->content()), $characterLimit, '');
$contentSource = method_exists($page, 'contentRaw') ? $page->contentRaw() : $page->content();
$content = Text::truncate($this->plainText($contentSource), $characterLimit, '');
// Include the page to the cache
$cache[$pageKey] = array(