diff --git a/app/cache.php b/app/cache.php index 69eee48..e0f2624 100644 --- a/app/cache.php +++ b/app/cache.php @@ -1,9 +1,9 @@ get('langPrefix', '') : ''; + $cached = getCachedMarkdown($filePath, $langPrefix); if ($cached !== null) { echo $cached; } else { + // Update to newer versions before PHP 9.0 release + // Current versions have been patched for PHP 8.4+ compatibility if (!class_exists('Parsedown')) { require_once __DIR__ . '/vendor/Parsedown.php'; } @@ -18,10 +21,25 @@ function renderContentFile(string $filePath): string { require_once __DIR__ . '/vendor/ParsedownExtra.php'; } $html = '
' . (new ParsedownExtra())->text(file_get_contents($filePath)) . '
'; - setCachedMarkdown($filePath, $html); + + // Add language prefix to internal links + if ($langPrefix) { + $html = preg_replace( + '/href="(\/[^"]*)"/', + 'href="' . $langPrefix . '$1"', + $html + ); + } + + setCachedMarkdown($filePath, $html, $langPrefix); echo $html; } } elseif (in_array($ext, ['html', 'php'])) { + // Make template variables available to PHP content files + if ($ctx !== null && $ext === 'php') { + $templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [], $ctx); + extract($templateVars); + } include $filePath; } return ob_get_clean(); @@ -29,12 +47,12 @@ function renderContentFile(string $filePath): string { function renderTemplate(Context $ctx, string $content, int $statusCode = 200): void { global $GLOBALS; - + // Get basic template vars $navigation = $ctx->navigation; $homeLabel = $ctx->homeLabel; $pageTitle = null; - + // Let plugins add template variables $templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [ 'content' => $content, @@ -42,7 +60,7 @@ function renderTemplate(Context $ctx, string $content, int $statusCode = 200): v 'homeLabel' => $homeLabel, 'pageTitle' => $pageTitle ], $ctx); - + extract($templateVars); http_response_code($statusCode); @@ -59,7 +77,7 @@ function renderFile(Context $ctx, string $filePath): void { $ext = pathinfo($realPath, PATHINFO_EXTENSION); if (in_array($ext, CONTENT_EXTENSIONS)) { - $content = renderContentFile($realPath); + $content = renderContentFile($realPath, $ctx); $pageDir = dirname($realPath); $pageMetadata = loadMetadata($pageDir); @@ -97,7 +115,7 @@ function renderFile(Context $ctx, string $filePath): void { 'pageCssHash' => $pageCssHash, 'socialImageUrl' => $socialImageUrl ], $ctx); - + extract($templateVars); // Wrap content with page template @@ -116,11 +134,11 @@ function renderFile(Context $ctx, string $filePath): void { function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void { $content = ''; foreach ($files as $file) { - $content .= renderContentFile($file); + $content .= renderContentFile($file, $ctx); } $pageMetadata = loadMetadata($pageDir); - + // Load page-level plugins getPluginManager()->loadPagePlugins($pageMetadata); @@ -154,7 +172,7 @@ function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void 'pageCssHash' => $pageCssHash, 'socialImageUrl' => $socialImageUrl ], $ctx); - + extract($templateVars); // Wrap content with page template