From dc4292f298dc660a372e80381351869ed84295a4 Mon Sep 17 00:00:00 2001 From: Ruben Date: Tue, 14 Oct 2025 21:08:57 +0200 Subject: [PATCH] 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 --- app/router.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/router.php b/app/router.php index 028f1da..f1ae42d 100644 --- a/app/router.php +++ b/app/router.php @@ -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));