From dec50951d03915420879a8a4fd1413696d76f603 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Sat, 22 Nov 2025 16:59:54 +0100 Subject: [PATCH] Fix page title extraction to use clean filenames - Add fallback in scanForPageTitles to use clean filename when no title found in content - Extract clean filename using basename() and formatDisplayName() for page titles - Ensures page titles are always clean (without language prefixes and extensions) - Footer now shows correct page titles for all content types - Consistent title handling for files, directories, and auto-linking --- engine/core/class/CodePressCMS.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/engine/core/class/CodePressCMS.php b/engine/core/class/CodePressCMS.php index 5e80b15..c6f3c3b 100644 --- a/engine/core/class/CodePressCMS.php +++ b/engine/core/class/CodePressCMS.php @@ -392,15 +392,19 @@ class CodePressCMS { // Convert to HTML $body = $converter->convert($content)->getContent(); + // Extract clean filename for title (without language prefix and extension) + $filename = basename($actualFilePath); + $cleanName = $this->formatDisplayName($filename); + // Auto-link page titles to existing content pages (but not in H1 tags) - $body = $this->autoLinkPageTitles($body, $title); + $body = $this->autoLinkPageTitles($body, $cleanName); // Convert relative internal links to CMS format $body = preg_replace('/href="\/blog\/([^"]+)"/', 'href="?page=blog/$1"', $body); $body = preg_replace('/href="\/([^"]+)"/', 'href="?page=$1"', $body); return [ - 'title' => $title ?: 'Untitled', + 'title' => $cleanName ?: 'Untitled', 'content' => $body ]; } @@ -493,6 +497,12 @@ class CodePressCMS { if ($title && !empty(trim($title))) { $pagePath = preg_replace('/\.[^.]+$/', '', $relativePath); $pages[$pagePath] = $title; + } else { + // Fallback to clean filename if no title found in content + $filename = basename($path, pathinfo($path, PATHINFO_EXTENSION)); + $cleanName = $this->formatDisplayName($filename); + $pagePath = preg_replace('/\.[^.]+$/', '', $relativePath); + $pages[$pagePath] = $cleanName; } } } @@ -546,6 +556,9 @@ class CodePressCMS { $filename = 'php-' . $matches[2]; } + // Remove file extensions (.md, .php, .html) from display names + $filename = preg_replace('/\.(md|php|html)$/', '', $filename); + // Handle special cases first if (strtolower($filename) === 'phpinfo') { return 'phpinfo';