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
This commit is contained in:
parent
79569437e2
commit
dec50951d0
@ -392,15 +392,19 @@ class CodePressCMS {
|
|||||||
// Convert to HTML
|
// Convert to HTML
|
||||||
$body = $converter->convert($content)->getContent();
|
$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)
|
// 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
|
// Convert relative internal links to CMS format
|
||||||
$body = preg_replace('/href="\/blog\/([^"]+)"/', 'href="?page=blog/$1"', $body);
|
$body = preg_replace('/href="\/blog\/([^"]+)"/', 'href="?page=blog/$1"', $body);
|
||||||
$body = preg_replace('/href="\/([^"]+)"/', 'href="?page=$1"', $body);
|
$body = preg_replace('/href="\/([^"]+)"/', 'href="?page=$1"', $body);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => $title ?: 'Untitled',
|
'title' => $cleanName ?: 'Untitled',
|
||||||
'content' => $body
|
'content' => $body
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -493,6 +497,12 @@ class CodePressCMS {
|
|||||||
if ($title && !empty(trim($title))) {
|
if ($title && !empty(trim($title))) {
|
||||||
$pagePath = preg_replace('/\.[^.]+$/', '', $relativePath);
|
$pagePath = preg_replace('/\.[^.]+$/', '', $relativePath);
|
||||||
$pages[$pagePath] = $title;
|
$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];
|
$filename = 'php-' . $matches[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove file extensions (.md, .php, .html) from display names
|
||||||
|
$filename = preg_replace('/\.(md|php|html)$/', '', $filename);
|
||||||
|
|
||||||
// Handle special cases first
|
// Handle special cases first
|
||||||
if (strtolower($filename) === 'phpinfo') {
|
if (strtolower($filename) === 'phpinfo') {
|
||||||
return 'phpinfo';
|
return 'phpinfo';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user