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));