feat: 添加文档标题规范化功能和优化文档显示逻辑

This commit is contained in:
2026-04-10 18:16:03 +08:00
parent d1cd73ccdb
commit 470b6ad776
3 changed files with 780 additions and 2 deletions

View File

@@ -3,6 +3,15 @@ require_once('./include/db_info.inc.php');
require_once('./include/setlang.php');
require_once('./include/const.inc.php');
function normalize_doc_title($text) {
$text = trim((string)$text);
$text = preg_replace('/[\s\p{P}\p{S}]+/u', '', $text);
if (function_exists('mb_strtolower')) {
return mb_strtolower($text, 'UTF-8');
}
return strtolower($text);
}
$docs_dir = __DIR__ . '/doc';
$doc_entries = array();
@@ -30,6 +39,7 @@ if (empty($selected_file) && !empty($doc_entries)) {
$selected_title = '文档';
$selected_markdown = '';
$show_selected_title = true;
if (!empty($selected_file)) {
$selected_path = realpath($docs_dir . DIRECTORY_SEPARATOR . $selected_file);
@@ -49,6 +59,9 @@ if (!empty($selected_file)) {
$selected_markdown = preg_replace('/^\xEF\xBB\xBF/', '', $selected_markdown);
}
$selected_title = preg_replace('/\.md$/i', '', basename($selected_path));
if (preg_match('/^\s*#\s+(.+)$/mu', $selected_markdown, $heading_match)) {
$show_selected_title = normalize_doc_title($heading_match[1]) !== normalize_doc_title($selected_title);
}
}
}