From b98029f2140d8a5b8d4482d4d0dde9c73204075a Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 11 May 2026 09:40:19 +0200 Subject: [PATCH 1/2] fix: parse knowledge base article headings new line and tweak breadcrumbs The KB article was not being split correctly by line so the entire article was being reproduced in the title tag, and this also resulted in repeated headings. At the same time, tweak the layout of the page to put the navigation at the end of the article, add the KMKBxxxx id to the title, and improve the breadcrumb navigation for KB articles. Fixes: #2503 Test-bot: skip --- _includes/includes/template.php | 9 +++++++++ knowledge-base/index.php | 27 +++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/_includes/includes/template.php b/_includes/includes/template.php index 1bbadc261..9babb11de 100644 --- a/_includes/includes/template.php +++ b/_includes/includes/template.php @@ -100,10 +100,19 @@ function head($args=[]){ } function write_breadcrumbs(){ + global $kb_title; $request_uri = explode("?",$_SERVER["REQUEST_URI"]); $crumbs = explode("/",$request_uri[0]); $crumbcount = count($crumbs); $crumbtrail = ''; + if(sizeof($crumbs) > 1 && $crumbs[1] == 'knowledge-base') { + if(isset($_REQUEST['id'])) { + // KB articles are served by a single file, so we need to look for the + // global variable $kb_title to get the appropriate title, which is set + // in /knowledge-base/index.php. + $crumbs[2] = isset($kb_title) ? $kb_title : ''; + } + } for($i=1; $i<$crumbcount; $i++){ $crumb = ucfirst(str_replace(array(".php","_","-"),array(""," "," "),$crumbs[$i]) . ' '); diff --git a/knowledge-base/index.php b/knowledge-base/index.php index cf690216b..b36eca9e2 100644 --- a/knowledge-base/index.php +++ b/knowledge-base/index.php @@ -7,7 +7,7 @@ use function com\keyman\help\kb\link_from_id; $id = null; - $title = 'Knowledge Base index'; + $kb_title = 'Knowledge Base index'; if(isset($_REQUEST['id'])) { $id = $_REQUEST['id']; @@ -24,12 +24,12 @@ } else { // We test the first line of the file for a title. - $text = explode('\n', $kb); + $text = explode("\n", $kb); if(count($text) > 0) { if(substr($text[0], 0, 2) == '# ') { - $title = trim(substr($text[0], 2)); + $kb_title = trim(substr($text[0], 2)) . sprintf(" (KMKB%04.4d)", intval($id)); } else { - $title = $filename; + $kb_title = $filename; } } } @@ -37,25 +37,28 @@ // Required head([ - 'title' =>'Keyman Support | ' . $title, + 'title' =>'Keyman Support | ' . $kb_title, 'css' => ['template.css','prism.css', 'kb-search.css'], 'showMenu' => true, 'index' => false ]); - echo "

Knowledge Base index

"; if($id) { - echo "

"; + $ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts(); + echo $ParsedownAndAlerts->text($kb); + + echo "


"; + echo "Knowledge Base index   |   "; $pid = intval($id,10) - 1; - if($pid > 0) echo "< Previous article   "; + if($pid > 0) echo "< Previous article   |   "; $nid = intval($id,10) + 1; if(file_exists(filename_from_id($nid))) { echo "Next article > "; } - echo "


"; - $ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts(); - echo $ParsedownAndAlerts->text($kb); - } else { + echo "

"; + + } else { $query = trim($_GET['q'] ?? ''); + echo "

Knowledge Base index

"; echo "