Add PDF file detection to item metadata
Add a new function to find PDF files in a directory and include the PDF file path in the item metadata output
This commit is contained in:
parent
d198b3f5fe
commit
dc4292f298
1 changed files with 14 additions and 1 deletions
|
|
@ -200,6 +200,17 @@ function findCoverImage(string $dirPath): ?string {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
function findPdfFile(string $dirPath): ?string {
|
||||
$files = scandir($dirPath) ?: [];
|
||||
foreach ($files as $file) {
|
||||
if (pathinfo($file, PATHINFO_EXTENSION) === 'pdf') {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function loadTranslations(string $lang): array {
|
||||
$translationFile = dirname(__DIR__) . "/custom/languages/$lang.ini";
|
||||
if (file_exists($translationFile)) {
|
||||
|
|
@ -440,6 +451,7 @@ switch ($parsedPath['type']) {
|
|||
|
||||
$metadata = loadMetadata($itemPath, $currentLang, $defaultLang);
|
||||
$coverImage = findCoverImage($itemPath);
|
||||
$pdfFile = findPdfFile($itemPath);
|
||||
|
||||
$title = $metadata['title'] ?? extractTitle($itemPath, $patterns) ?? $item;
|
||||
$date = null;
|
||||
|
|
@ -461,7 +473,8 @@ switch ($parsedPath['type']) {
|
|||
'date' => $date,
|
||||
'url' => $langPrefix . '/' . trim($requestPath, '/') . '/' . urlencode($urlSlug),
|
||||
'cover' => $coverImage ? $langPrefix . '/' . trim($requestPath, '/') . '/' . urlencode($urlSlug) . '/' . $coverImage : null,
|
||||
'summary' => $metadata['summary'] ?? null
|
||||
'summary' => $metadata['summary'] ?? null,
|
||||
'pdf' => $pdfFile ? $langPrefix . '/' . trim($requestPath, '/') . '/' . urlencode($urlSlug) . '/' . $pdfFile : null
|
||||
];
|
||||
}, $subdirs));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue