From d149a0bf8f5e472e0b0c4952ee0a91602afcdf50 Mon Sep 17 00:00:00 2001 From: Ty Clifford Date: Fri, 3 Jul 2026 09:34:49 -0400 Subject: [PATCH] - 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. --- bl-plugins/search/plugin.php | 19 +++++++++++++++---- bl-themes/dark-neon/php/home.php | 9 +++++---- bl-themes/dark-neon/php/navbar.php | 3 ++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bl-plugins/search/plugin.php b/bl-plugins/search/plugin.php index 25abe95..7ea1d7f 100644 --- a/bl-plugins/search/plugin.php +++ b/bl-plugins/search/plugin.php @@ -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', '

' . $this->highlightTerms($excerpt, $this->searchTerm) . '

'); } @@ -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( diff --git a/bl-themes/dark-neon/php/home.php b/bl-themes/dark-neon/php/home.php index 19ee31c..378576e 100644 --- a/bl-themes/dark-neon/php/home.php +++ b/bl-themes/dark-neon/php/home.php @@ -1,5 +1,6 @@ getSearchTerm() !== ''; $sidebarHtml = ''; ob_start(); Theme::plugins('siteSidebar'); @@ -19,7 +20,7 @@ $socialIconMap = array( ); ?> - +
@@ -82,7 +83,7 @@ $socialIconMap = array( title(), ENT_QUOTES, 'UTF-8'); ?> - description() && $WHERE_AM_I !== 'search') : ?> + description() && !$isSearchPage) : ?>

description(), ENT_QUOTES, 'UTF-8'); ?>

@@ -99,9 +100,9 @@ $socialIconMap = array(
- readMore() || $WHERE_AM_I === 'search') : ?> + readMore() || $isSearchPage) : ?> - get('Open result') : $L->get('Read more'); ?> + get('Open result') : $L->get('Read more'); ?> diff --git a/bl-themes/dark-neon/php/navbar.php b/bl-themes/dark-neon/php/navbar.php index 0613e69..9f47aa7 100644 --- a/bl-themes/dark-neon/php/navbar.php +++ b/bl-themes/dark-neon/php/navbar.php @@ -1,6 +1,7 @@ getSearchTerm() : ''; +$isSearchPage = $searchPlugin && $searchPlugin->getSearchTerm() !== ''; +$searchValue = $isSearchPage ? $searchPlugin->getSearchTerm() : ''; $searchMinChars = $searchPlugin ? max(1, (int) $searchPlugin->getValue('minChars')) : 1; $searchAction = json_encode(Theme::siteUrl() . 'search/'); $socialIconMap = array(