Skip to content

Commit 00fe916

Browse files
authored
Merge pull request #2505 from keymanapp/fix/2503-kb-headings
fix: parse knowledge base article headings new line and tweak breadcrumbs
2 parents cdc0053 + f1eebaa commit 00fe916

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

_includes/includes/template.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,19 @@ function head($args=[]){
100100
}
101101

102102
function write_breadcrumbs(){
103+
global $kb_title;
103104
$request_uri = explode("?",$_SERVER["REQUEST_URI"]);
104105
$crumbs = explode("/",$request_uri[0]);
105106
$crumbcount = count($crumbs);
106107
$crumbtrail = '';
108+
if(sizeof($crumbs) > 1 && $crumbs[1] == 'knowledge-base') {
109+
if(isset($_REQUEST['id'])) {
110+
// KB articles are served by a single file, so we need to look for the
111+
// global variable $kb_title to get the appropriate title, which is set
112+
// in /knowledge-base/index.php.
113+
$crumbs[2] = isset($kb_title) ? $kb_title : '';
114+
}
115+
}
107116
for($i=1; $i<$crumbcount; $i++){
108117
$crumb = ucfirst(str_replace(array(".php","_","-"),array(""," "," "),$crumbs[$i]) . ' ');
109118

knowledge-base/index.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use function com\keyman\help\kb\link_from_id;
88

99
$id = null;
10-
$title = 'Knowledge Base index';
10+
$kb_title = 'Knowledge Base index';
1111

1212
if(isset($_REQUEST['id'])) {
1313
$id = $_REQUEST['id'];
@@ -24,38 +24,40 @@
2424
} else {
2525
// We test the first line of the file for a title.
2626

27-
$text = explode('\n', $kb);
27+
$text = explode("\n", $kb);
2828
if(count($text) > 0) {
2929
if(substr($text[0], 0, 2) == '# ') {
30-
$title = trim(substr($text[0], 2));
30+
$kb_title = trim(substr($text[0], 2)) . sprintf(" (KMKB%04.4d)", intval($id));
3131
} else {
32-
$title = $filename;
32+
$kb_title = $filename;
3333
}
3434
}
3535
}
3636
}
3737

3838
// Required
3939
head([
40-
'title' =>'Keyman Support | ' . $title,
40+
'title' =>'Keyman Support | ' . $kb_title,
4141
'css' => ['template.css','prism.css', 'kb-search.css'],
4242
'showMenu' => true,
4343
'index' => false
4444
]);
45-
echo "<h1>Knowledge Base index</h1>";
4645
if($id) {
47-
echo "<p>";
46+
$ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts();
47+
echo $ParsedownAndAlerts->text($kb);
48+
49+
echo "<hr><p>";
50+
echo "<a href='/kb'>Knowledge Base index</a> &nbsp; | &nbsp; ";
4851
$pid = intval($id,10) - 1;
49-
if($pid > 0) echo "<a href='".link_from_id($pid)."'>&lt; Previous article</a> &nbsp; ";
52+
if($pid > 0) echo "<a href='".link_from_id($pid)."'>&lt; Previous article</a> &nbsp; | &nbsp; ";
5053
$nid = intval($id,10) + 1;
5154
if(file_exists(filename_from_id($nid))) {
5255
echo "<a href='".link_from_id($nid)."'>Next article &gt;</a> ";
5356
}
54-
echo "</p><hr>";
55-
$ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts();
56-
echo $ParsedownAndAlerts->text($kb);
57+
echo "</p>";
5758
} else {
5859
$query = trim($_GET['q'] ?? '');
60+
echo "<h1>Knowledge Base index</h1>";
5961
echo "<div class='search-bar'>";
6062
echo "<form>";
6163
echo "<span class='search-icon'>🔍</span>";
@@ -81,6 +83,6 @@
8183
echo "<li><a href='".link_from_id($id)."'>KMKB{$matches[1]}: " . htmlspecialchars($title) . "</a></li>";
8284
}
8385
}
84-
}
8586
echo "</ul>";
87+
}
8688
?>

0 commit comments

Comments
 (0)