Refactor code structure for improved readability and maintainability

This commit is contained in:
interlope committed 2026-06-03 00:10:14 +02:00
1 parent 3b31711b49
commit fa211d243f
14 files changed
+428 -11

No files matched your search

+25
View File
@@ -18,3 +18,28 @@
</div>
</div>
</footer>
<?php
// Client-side search index (all published posts) for the search overlay.
// Guarded so any Pages-API difference degrades to an empty index, not an error.
try {
global $pages;
$bdSearchIndex = array();
if (isset($pages) && method_exists($pages, 'getList')) {
foreach ($pages->getList(1, 1000, true) as $bdSk) {
$bdSp = new Page($bdSk);
if ($bdSp->isStatic()) { continue; } // posts only
$bdSearchIndex[] = array(
't' => blowdit_plain($bdSp->title()),
'u' => $bdSp->permalink(),
'd' => blowdit_plain($bdSp->description()),
'c' => blowdit_plain($bdSp->category()),
'g' => array_values(array_map('blowdit_plain', $bdSp->tags(true))),
);
}
}
echo '<script type="application/json" id="blowdit-search-index">'
. json_encode($bdSearchIndex, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
. '</script>';
} catch (\Throwable $e) {}
?>
+3 -6
View File
@@ -244,12 +244,9 @@
<link rel="manifest" href="<?php echo DOMAIN_THEME . 'manifest.webmanifest'; ?>">
<link rel="apple-touch-icon" href="<?php echo DOMAIN_THEME . 'img/favicon.png'; ?>">
<!-- Inter typeface (Blowfish-like typography) — loaded non-render-blocking:
fetched as print media, then flipped to all once it arrives. -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" media="print" onload="this.media='all'">
<noscript><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"></noscript>
<!-- Inter typeface — self-hosted (see @font-face in style.css). No third-party
request; preload the body weight for a faster first text paint. -->
<link rel="preload" as="font" type="font/woff2" href="<?php echo DOMAIN_THEME . 'fonts/inter-400.woff2'; ?>" crossorigin>
<!-- Include Bootstrap CSS file bootstrap.css -->
<?php echo Theme::cssBootstrap(); ?>
+1
View File
@@ -21,6 +21,7 @@ if (!function_exists('blowdit_icon')) {
'chevron-right' => '<path d="M9 18l6-6-6-6"/>',
'house' => '<path d="M3 10.5 12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/>',
'link' => '<path d="M9 17H7A5 5 0 0 1 7 7h2"/><path d="M15 7h2a5 5 0 0 1 0 10h-2"/><path d="M8 12h8"/>',
'search' => '<circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/>',
'share' => '<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><path d="M8.6 13.5l6.8 4M15.4 6.5l-6.8 4"/>',
// --- Theme picker (mirror in blowdit.js) ---
'sun' => '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/>',
+7
View File
@@ -59,6 +59,13 @@
<?php endif; ?>
<?php endif; ?>
<!-- Search (opens the overlay; also bound to the "/" key) -->
<li class="nav-item ml-md-2 mt-2 mt-md-0">
<button type="button" class="theme-toggle js-search-open" aria-label="<?php echo $L->get('Search'); ?>" title="<?php echo $L->get('Search'); ?> (/)">
<?php echo blowdit_icon('search'); ?>
</button>
</li>
<!-- Theme picker -->
<li class="nav-item ml-md-2 mt-2 mt-md-0 theme-picker-wrap">
<button type="button" id="theme-toggle" class="theme-toggle" aria-label="<?php echo $L->get('Toggle theme') ?>" title="<?php echo $L->get('Toggle theme') ?>" aria-haspopup="true" aria-expanded="false">
+37
View File
@@ -54,6 +54,43 @@
</div>
<?php endif ?>
<!-- Series box: posts sharing a tag whose key starts with "series-"
(e.g. tag "Series: Homelab" -> key "series-homelab"), ordered oldest-first. -->
<?php if (!$page->isStatic() && !$url->notFound()) :
$bdSeriesTag = ''; $bdSeriesName = '';
foreach ($page->tags(true) as $bdTk => $bdTn) {
if (preg_match('/^series[-_]/i', $bdTk)) { $bdSeriesTag = $bdTk; $bdSeriesName = $bdTn; break; }
}
$bdSeriesPosts = array();
if ($bdSeriesTag) {
try {
global $pages;
if (isset($pages) && method_exists($pages, 'getList')) {
foreach ($pages->getList(1, 1000, true) as $bdSk) {
$bdSp = new Page($bdSk);
if (in_array($bdSeriesTag, array_keys($bdSp->tags(true)), true)) { $bdSeriesPosts[] = $bdSp; }
}
usort($bdSeriesPosts, function ($a, $b) { return strcmp($a->getValue('date'), $b->getValue('date')); });
}
} catch (\Throwable $e) { $bdSeriesPosts = array(); }
}
$bdSeriesLabel = trim(preg_replace('/^series\s*[:\-_]?\s*/i', '', blowdit_plain($bdSeriesName)));
?>
<?php if (count($bdSeriesPosts) > 1) : ?>
<aside class="series-box">
<div class="series-box-title"><?php echo blowdit_icon('folder'); ?><span><?php echo $L->get('Part of a series'); ?><?php echo $bdSeriesLabel !== '' ? ': ' . htmlspecialchars($bdSeriesLabel, ENT_QUOTES, 'UTF-8') : ''; ?></span></div>
<ol class="series-list">
<?php foreach ($bdSeriesPosts as $bdSp) : $bdIsCur = ($bdSp->key() === $page->key()); ?>
<li class="series-item<?php echo $bdIsCur ? ' is-current' : ''; ?>">
<?php if ($bdIsCur) : ?><span><?php echo blowdit_text($bdSp->title()); ?></span>
<?php else : ?><a href="<?php echo $bdSp->permalink(); ?>"><?php echo blowdit_text($bdSp->title()); ?></a><?php endif ?>
</li>
<?php endforeach ?>
</ol>
</aside>
<?php endif ?>
<?php endif ?>
<!-- Full content -->
<div class="content">
<?php