From 8291a8637337ec9ba3949f90e8f908d36482527b Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 30 Nov 2025 22:26:37 +0100 Subject: [PATCH 1/3] Add language prefix support to cached markdown rendering Add language prefix parameter to cache functions Update renderContentFile to handle language prefixes Add language prefix to internal links in markdown Make template variables available to PHP content files --- app/cache.php | 8 ++++---- app/rendering.php | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 15 deletions(-) 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 From 1db80ebf384bfadafeeca003253283c7f145aa20 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 30 Nov 2025 22:26:47 +0100 Subject: [PATCH 2/3] Add language prefix to hero section feature URLs --- app/default/content/00-hero.no.php | 13 +++++++------ app/default/content/00-hero.php | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/default/content/00-hero.no.php b/app/default/content/00-hero.no.php index 22e2f5d..3f3387a 100644 --- a/app/default/content/00-hero.no.php +++ b/app/default/content/00-hero.no.php @@ -1,12 +1,13 @@ '📁', 'title' => 'Filbasert', 'description' => 'Mapper blir URL-er automatisk', 'url' => '/examples/file-based-routing/'], - ['icon' => '⚡', 'title' => 'Uten byggesteg', 'description' => 'Rediger og oppdater—det er alt', 'url' => '/examples/no-build-step/'], - ['icon' => '🎨', 'title' => 'Bland formater', 'description' => 'Kombiner .md, .html og .php', 'url' => '/examples/mix-formats/'], - ['icon' => '🌍', 'title' => 'Flerspråklig', 'description' => 'Innebygd i18n-støtte', 'url' => '/multilingual/'], - ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Skriv innhold i markdown', 'url' => '/examples/2024-12-15-markdown-demo/'], - ['icon' => '🎭', 'title' => 'Maler', 'description' => 'Egendefinerte layout og stiler', 'url' => '/examples/templates-demo/'], + ['icon' => '📁', 'title' => 'Filbasert', 'description' => 'Mapper blir URL-er automatisk', 'url' => $prefix . '/examples/file-based-routing/'], + ['icon' => '⚡', 'title' => 'Uten byggesteg', 'description' => 'Rediger og oppdater—det er alt', 'url' => $prefix . '/examples/no-build-step/'], + ['icon' => '🎨', 'title' => 'Bland formater', 'description' => 'Kombiner .md, .html og .php', 'url' => $prefix . '/examples/mix-formats/'], + ['icon' => '🌍', 'title' => 'Flerspråklig', 'description' => 'Innebygd i18n-støtte', 'url' => $prefix . '/multilingual/'], + ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Skriv innhold i markdown', 'url' => $prefix . '/examples/2024-12-15-markdown-demo/'], + ['icon' => '🎭', 'title' => 'Maler', 'description' => 'Egendefinerte layout og stiler', 'url' => $prefix . '/examples/templates-demo/'], ]; $stats = [ diff --git a/app/default/content/00-hero.php b/app/default/content/00-hero.php index 13d8567..e2c2708 100644 --- a/app/default/content/00-hero.php +++ b/app/default/content/00-hero.php @@ -1,12 +1,13 @@ '📁', 'title' => 'File-Based', 'description' => 'Folders become URLs automatically', 'url' => '/examples/file-based-routing/'], - ['icon' => '⚡', 'title' => 'No Build Step', 'description' => 'Edit and refresh—that\'s it', 'url' => '/examples/no-build-step/'], - ['icon' => '🎨', 'title' => 'Mix Formats', 'description' => 'Combine .md, .html, and .php', 'url' => '/examples/mix-formats/'], - ['icon' => '🌍', 'title' => 'Multilingual', 'description' => 'Built-in i18n support', 'url' => '/multilingual/'], - ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Write content in markdown', 'url' => '/examples/2024-12-15-markdown-demo/'], - ['icon' => '🎭', 'title' => 'Templates', 'description' => 'Custom layouts and styles', 'url' => '/examples/templates-demo/'], + ['icon' => '📁', 'title' => 'File-Based', 'description' => 'Folders become URLs automatically', 'url' => $prefix . '/examples/file-based-routing/'], + ['icon' => '⚡', 'title' => 'No Build Step', 'description' => 'Edit and refresh—that\'s it', 'url' => $prefix . '/examples/no-build-step/'], + ['icon' => '🎨', 'title' => 'Mix Formats', 'description' => 'Combine .md, .html, and .php', 'url' => $prefix . '/examples/mix-formats/'], + ['icon' => '🌍', 'title' => 'Multilingual', 'description' => 'Built-in i18n support', 'url' => $prefix . '/multilingual/'], + ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Write content in markdown', 'url' => $prefix . '/examples/2024-12-15-markdown-demo/'], + ['icon' => '🎭', 'title' => 'Templates', 'description' => 'Custom layouts and styles', 'url' => $prefix . '/examples/templates-demo/'], ]; $stats = [ From f94b50f2987c7a7364f9f6ef2533da7266fa02b7 Mon Sep 17 00:00:00 2001 From: Ruben Date: Sun, 30 Nov 2025 22:27:03 +0100 Subject: [PATCH 3/3] Patch: Update footnote sorting method reference Use static method reference for footnote sorting --- app/vendor/ParsedownExtra.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/vendor/ParsedownExtra.php b/app/vendor/ParsedownExtra.php index d192e2b..2adcbaa 100644 --- a/app/vendor/ParsedownExtra.php +++ b/app/vendor/ParsedownExtra.php @@ -508,7 +508,7 @@ class ParsedownExtra extends Parsedown ), ); - uasort($this->DefinitionData['Footnote'], 'self::sortFootnotes'); + uasort($this->DefinitionData['Footnote'], [$this, 'sortFootnotes']); foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData) {