Compare commits

..

No commits in common. "f94b50f2987c7a7364f9f6ef2533da7266fa02b7" and "f212e320cb5987d144829602b995bca69b823bf8" have entirely different histories.

5 changed files with 28 additions and 48 deletions

View file

@ -1,9 +1,9 @@
<?php <?php
function getCachedMarkdown(string $filePath, string $langPrefix = ''): ?string { function getCachedMarkdown(string $filePath): ?string {
$cacheDir = '/tmp/folderweb_cache'; $cacheDir = '/tmp/folderweb_cache';
$mtime = filemtime($filePath); $mtime = filemtime($filePath);
$cacheKey = md5($filePath . $mtime . $langPrefix); $cacheKey = md5($filePath . $mtime);
$cachePath = "$cacheDir/$cacheKey"; $cachePath = "$cacheDir/$cacheKey";
if (file_exists($cachePath)) { if (file_exists($cachePath)) {
@ -13,14 +13,14 @@ function getCachedMarkdown(string $filePath, string $langPrefix = ''): ?string {
return null; return null;
} }
function setCachedMarkdown(string $filePath, string $html, string $langPrefix = ''): void { function setCachedMarkdown(string $filePath, string $html): void {
$cacheDir = '/tmp/folderweb_cache'; $cacheDir = '/tmp/folderweb_cache';
if (!is_dir($cacheDir)) { if (!is_dir($cacheDir)) {
mkdir($cacheDir, 0755, true); mkdir($cacheDir, 0755, true);
} }
$mtime = filemtime($filePath); $mtime = filemtime($filePath);
$cacheKey = md5($filePath . $mtime . $langPrefix); $cacheKey = md5($filePath . $mtime);
$cachePath = "$cacheDir/$cacheKey"; $cachePath = "$cacheDir/$cacheKey";
file_put_contents($cachePath, $html); file_put_contents($cachePath, $html);

View file

@ -1,13 +1,12 @@
<?php <?php
// Dynamisk hero-seksjon som viser PHP-muligheter // Dynamisk hero-seksjon som viser PHP-muligheter
$prefix = $langPrefix ?? '';
$features = [ $features = [
['icon' => '📁', 'title' => 'Filbasert', 'description' => 'Mapper blir URL-er automatisk', 'url' => $prefix . '/examples/file-based-routing/'], ['icon' => '📁', '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' => $prefix . '/examples/no-build-step/'], ['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' => $prefix . '/examples/mix-formats/'], ['icon' => '🎨', 'title' => 'Bland formater', 'description' => 'Kombiner .md, .html og .php', 'url' => '/examples/mix-formats/'],
['icon' => '🌍', 'title' => 'Flerspråklig', 'description' => 'Innebygd i18n-støtte', 'url' => $prefix . '/multilingual/'], ['icon' => '🌍', 'title' => 'Flerspråklig', 'description' => 'Innebygd i18n-støtte', 'url' => '/multilingual/'],
['icon' => '📝', 'title' => 'Markdown', 'description' => 'Skriv innhold i markdown', 'url' => $prefix . '/examples/2024-12-15-markdown-demo/'], ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Skriv innhold i markdown', 'url' => '/examples/2024-12-15-markdown-demo/'],
['icon' => '🎭', 'title' => 'Maler', 'description' => 'Egendefinerte layout og stiler', 'url' => $prefix . '/examples/templates-demo/'], ['icon' => '🎭', 'title' => 'Maler', 'description' => 'Egendefinerte layout og stiler', 'url' => '/examples/templates-demo/'],
]; ];
$stats = [ $stats = [

View file

@ -1,13 +1,12 @@
<?php <?php
// Dynamic hero section showcasing PHP capabilities // Dynamic hero section showcasing PHP capabilities
$prefix = $langPrefix ?? '';
$features = [ $features = [
['icon' => '📁', 'title' => 'File-Based', 'description' => 'Folders become URLs automatically', 'url' => $prefix . '/examples/file-based-routing/'], ['icon' => '📁', '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' => $prefix . '/examples/no-build-step/'], ['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' => $prefix . '/examples/mix-formats/'], ['icon' => '🎨', 'title' => 'Mix Formats', 'description' => 'Combine .md, .html, and .php', 'url' => '/examples/mix-formats/'],
['icon' => '🌍', 'title' => 'Multilingual', 'description' => 'Built-in i18n support', 'url' => $prefix . '/multilingual/'], ['icon' => '🌍', 'title' => 'Multilingual', 'description' => 'Built-in i18n support', 'url' => '/multilingual/'],
['icon' => '📝', 'title' => 'Markdown', 'description' => 'Write content in markdown', 'url' => $prefix . '/examples/2024-12-15-markdown-demo/'], ['icon' => '📝', 'title' => 'Markdown', 'description' => 'Write content in markdown', 'url' => '/examples/2024-12-15-markdown-demo/'],
['icon' => '🎭', 'title' => 'Templates', 'description' => 'Custom layouts and styles', 'url' => $prefix . '/examples/templates-demo/'], ['icon' => '🎭', 'title' => 'Templates', 'description' => 'Custom layouts and styles', 'url' => '/examples/templates-demo/'],
]; ];
$stats = [ $stats = [

View file

@ -1,19 +1,16 @@
<?php <?php
function renderContentFile(string $filePath, ?Context $ctx = null): string { function renderContentFile(string $filePath): string {
$ext = pathinfo($filePath, PATHINFO_EXTENSION); $ext = pathinfo($filePath, PATHINFO_EXTENSION);
ob_start(); ob_start();
if ($ext === 'md') { if ($ext === 'md') {
require_once __DIR__ . '/cache.php'; require_once __DIR__ . '/cache.php';
$langPrefix = $ctx ? $ctx->get('langPrefix', '') : ''; $cached = getCachedMarkdown($filePath);
$cached = getCachedMarkdown($filePath, $langPrefix);
if ($cached !== null) { if ($cached !== null) {
echo $cached; echo $cached;
} else { } else {
// Update to newer versions before PHP 9.0 release
// Current versions have been patched for PHP 8.4+ compatibility
if (!class_exists('Parsedown')) { if (!class_exists('Parsedown')) {
require_once __DIR__ . '/vendor/Parsedown.php'; require_once __DIR__ . '/vendor/Parsedown.php';
} }
@ -21,25 +18,10 @@ function renderContentFile(string $filePath, ?Context $ctx = null): string {
require_once __DIR__ . '/vendor/ParsedownExtra.php'; require_once __DIR__ . '/vendor/ParsedownExtra.php';
} }
$html = '<article>' . (new ParsedownExtra())->text(file_get_contents($filePath)) . '</article>'; $html = '<article>' . (new ParsedownExtra())->text(file_get_contents($filePath)) . '</article>';
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; echo $html;
} }
} elseif (in_array($ext, ['html', 'php'])) { } 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; include $filePath;
} }
return ob_get_clean(); return ob_get_clean();
@ -47,12 +29,12 @@ function renderContentFile(string $filePath, ?Context $ctx = null): string {
function renderTemplate(Context $ctx, string $content, int $statusCode = 200): void { function renderTemplate(Context $ctx, string $content, int $statusCode = 200): void {
global $GLOBALS; global $GLOBALS;
// Get basic template vars // Get basic template vars
$navigation = $ctx->navigation; $navigation = $ctx->navigation;
$homeLabel = $ctx->homeLabel; $homeLabel = $ctx->homeLabel;
$pageTitle = null; $pageTitle = null;
// Let plugins add template variables // Let plugins add template variables
$templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [ $templateVars = Hooks::apply(Hook::TEMPLATE_VARS, [
'content' => $content, 'content' => $content,
@ -60,7 +42,7 @@ function renderTemplate(Context $ctx, string $content, int $statusCode = 200): v
'homeLabel' => $homeLabel, 'homeLabel' => $homeLabel,
'pageTitle' => $pageTitle 'pageTitle' => $pageTitle
], $ctx); ], $ctx);
extract($templateVars); extract($templateVars);
http_response_code($statusCode); http_response_code($statusCode);
@ -77,7 +59,7 @@ function renderFile(Context $ctx, string $filePath): void {
$ext = pathinfo($realPath, PATHINFO_EXTENSION); $ext = pathinfo($realPath, PATHINFO_EXTENSION);
if (in_array($ext, CONTENT_EXTENSIONS)) { if (in_array($ext, CONTENT_EXTENSIONS)) {
$content = renderContentFile($realPath, $ctx); $content = renderContentFile($realPath);
$pageDir = dirname($realPath); $pageDir = dirname($realPath);
$pageMetadata = loadMetadata($pageDir); $pageMetadata = loadMetadata($pageDir);
@ -115,7 +97,7 @@ function renderFile(Context $ctx, string $filePath): void {
'pageCssHash' => $pageCssHash, 'pageCssHash' => $pageCssHash,
'socialImageUrl' => $socialImageUrl 'socialImageUrl' => $socialImageUrl
], $ctx); ], $ctx);
extract($templateVars); extract($templateVars);
// Wrap content with page template // Wrap content with page template
@ -134,11 +116,11 @@ function renderFile(Context $ctx, string $filePath): void {
function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void { function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void {
$content = ''; $content = '';
foreach ($files as $file) { foreach ($files as $file) {
$content .= renderContentFile($file, $ctx); $content .= renderContentFile($file);
} }
$pageMetadata = loadMetadata($pageDir); $pageMetadata = loadMetadata($pageDir);
// Load page-level plugins // Load page-level plugins
getPluginManager()->loadPagePlugins($pageMetadata); getPluginManager()->loadPagePlugins($pageMetadata);
@ -172,7 +154,7 @@ function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void
'pageCssHash' => $pageCssHash, 'pageCssHash' => $pageCssHash,
'socialImageUrl' => $socialImageUrl 'socialImageUrl' => $socialImageUrl
], $ctx); ], $ctx);
extract($templateVars); extract($templateVars);
// Wrap content with page template // Wrap content with page template

View file

@ -508,7 +508,7 @@ class ParsedownExtra extends Parsedown
), ),
); );
uasort($this->DefinitionData['Footnote'], [$this, 'sortFootnotes']); uasort($this->DefinitionData['Footnote'], 'self::sortFootnotes');
foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData) foreach ($this->DefinitionData['Footnote'] as $definitionId => $DefinitionData)
{ {