Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions _includes/includes/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From devin.ai:

KB article title in breadcrumbs is mangled by URL-segment str_replace that converts dashes/underscores to spaces

The new code at _includes/includes/template.php:113 inserts the human-readable $kb_title (e.g. "FIX: Problems uninstalling Keyman 3.2 - 6.2 (KMKB0008)") into the $crumbs array, which is designed for URL path segments. This title then gets processed by the str_replace at line 117 that replaces - with spaces, _ with spaces, and removes .php — a transformation designed for URL slugs, not readable titles. This corrupts any KB title containing dashes (at least 15 articles are affected), e.g. "Keyman 3.2 - 6.2" becomes "Keyman 3.2 6.2". The same mangling also occurs at line 130 when computing $crumb2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a longstanding limitation with the breadcrumbs. A proper fix would be to read the title from each page, but that's more work. I think we leave it as is for now; it's only the breadcrumbs.

}
}
for($i=1; $i<$crumbcount; $i++){
$crumb = ucfirst(str_replace(array(".php","_","-"),array(""," "," "),$crumbs[$i]) . ' ');

Expand Down
26 changes: 14 additions & 12 deletions knowledge-base/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -24,38 +24,40 @@
} else {
// We test the first line of the file for a title.

$text = explode('\n', $kb);
$text = explode("\n", $kb);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a while (and devin.ai to point it out) to realize that this is what fixes the bug 😄.

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;
}
}
}
}

// Required
head([
'title' =>'Keyman Support | ' . $title,
'title' =>'Keyman Support | ' . $kb_title,
'css' => ['template.css','prism.css', 'kb-search.css'],
'showMenu' => true,
'index' => false
]);
echo "<h1>Knowledge Base index</h1>";
if($id) {
echo "<p>";
$ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts();
echo $ParsedownAndAlerts->text($kb);

echo "<hr><p>";
echo "<a href='/kb'>Knowledge Base index</a> &nbsp; | &nbsp; ";
$pid = intval($id,10) - 1;
if($pid > 0) echo "<a href='".link_from_id($pid)."'>&lt; Previous article</a> &nbsp; ";
if($pid > 0) echo "<a href='".link_from_id($pid)."'>&lt; Previous article</a> &nbsp; | &nbsp; ";
$nid = intval($id,10) + 1;
if(file_exists(filename_from_id($nid))) {
echo "<a href='".link_from_id($nid)."'>Next article &gt;</a> ";
}
echo "</p><hr>";
$ParsedownAndAlerts = new \Keyman\Site\Common\GFMAlerts();
echo $ParsedownAndAlerts->text($kb);
echo "</p>";
} else {
$query = trim($_GET['q'] ?? '');
echo "<h1>Knowledge Base index</h1>";
echo "<div class='search-bar'>";
echo "<form>";
echo "<span class='search-icon'>🔍</span>";
Expand All @@ -81,6 +83,6 @@
echo "<li><a href='".link_from_id($id)."'>KMKB{$matches[1]}: " . htmlspecialchars($title) . "</a></li>";
}
}
}
echo "</ul>";
}
?>
Loading