Merge pull request #865 from splifingate/master

Added the Capability to Search the *Contents* of Blog Posts by @splifingate
This commit is contained in:
Dan 2025-01-27 07:08:38 +07:00 committed by GitHub
commit 416ce7e270
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 17 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
// * text=auto eol=lf

View file

@ -1323,13 +1323,18 @@ function get_keyword($keyword, $page, $perpage)
$tmp = array();
$words = explode(' ', $keyword);
foreach ($posts as $index => $v) {
$arr = explode('_', $v['basename']);
$filter = $arr[1] . ' ' . $arr[2];
foreach ($words as $word) {
if (stripos($filter, $word) !== false) {
$filepath = $v['dirname'] . '/' . $v['basename'];
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only)
$findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode
$lines = file($filepath);
foreach ($lines as $line) {
if (preg_match ($findRx, $line)) {
if (!in_array($v, $tmp)) {
$tmp[] = $v;
}
@ -1512,16 +1517,23 @@ function keyword_count($keyword)
$tmp = array();
$words = explode(' ', $keyword);
foreach ($posts as $index => $v) {
$arr = explode('_', $v['basename']);
$filter = $arr[1] . ' ' . $arr[2];
foreach ($words as $word) {
if (stripos($filter, $word) !== false) {
$tmp[] = $v;
}
}
$filepath = $v['dirname'] . '/' . $v['basename'];
$findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only)
$findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode
$lines = file($filepath);
foreach ($lines as $line) {
if (preg_match ($findRx, $line)) {
if (!in_array($v, $tmp)) {
$tmp[] = $v;
}
}
}
}
$tmp = array_unique($tmp, SORT_REGULAR);

View file

@ -28,9 +28,11 @@
<?php endif;?>
<?php if (isset($is_search)):?>
<div class="row justify-content-center" style="padding-top: 4rem;">
<!-- main.html.php -->
<div class="row justify-content-center" style="padding-top: 3rem;">
<div class="col-md-12 text-center">
<h1 class="mt-0"><?php echo $search->title;?></h1>
<h2 class="mt-0">Search: <span style='color: #628B48;'><?php echo $search->title;?></span> (<?php echo $search->count;?>)</h2>
<form><input type="search" name="search" class="form-control is-search" placeholder="<?php echo i18n('Type_to_search');?>"></form>
</div>
</div>
<?php endif;?>