Optimize content rendering and plugin loading order
Load metadata and plugins before content rendering to ensure plugin-provided variables are available to PHP content files
This commit is contained in:
parent
d54cdc7ce1
commit
d446ab1896
1 changed files with 10 additions and 8 deletions
|
|
@ -20,7 +20,7 @@ function renderContentFile(string $filePath, ?Context $ctx = null): string {
|
|||
if (!class_exists('ParsedownExtra')) {
|
||||
require_once __DIR__ . '/vendor/ParsedownExtra.php';
|
||||
}
|
||||
$html = '<article>' . (new ParsedownExtra())->text(file_get_contents($filePath)) . '</article>';
|
||||
$html = (new ParsedownExtra())->text(file_get_contents($filePath));
|
||||
|
||||
if ($langPrefix) {
|
||||
$html = preg_replace(
|
||||
|
|
@ -73,13 +73,14 @@ function renderFile(Context $ctx, string $filePath): void {
|
|||
$ext = pathinfo($realPath, PATHINFO_EXTENSION);
|
||||
|
||||
if (in_array($ext, CONTENT_EXTENSIONS)) {
|
||||
$content = renderContentFile($realPath, $ctx);
|
||||
|
||||
// Load metadata and page plugins BEFORE rendering content
|
||||
// so that plugin-provided template variables are available to PHP content files
|
||||
$pageDir = dirname($realPath);
|
||||
$pageMetadata = loadMetadata($pageDir);
|
||||
|
||||
getPluginManager()->loadPagePlugins($pageMetadata);
|
||||
|
||||
$content = renderContentFile($realPath, $ctx);
|
||||
|
||||
$navigation = $ctx->navigation;
|
||||
$homeLabel = $ctx->homeLabel;
|
||||
$pageTitle = $pageMetadata['title'] ?? null;
|
||||
|
|
@ -122,15 +123,16 @@ function renderFile(Context $ctx, string $filePath): void {
|
|||
}
|
||||
|
||||
function renderMultipleFiles(Context $ctx, array $files, string $pageDir): void {
|
||||
// Load metadata and page plugins BEFORE rendering content files
|
||||
// so that plugin-provided template variables are available to PHP content files
|
||||
$pageMetadata = loadMetadata($pageDir);
|
||||
getPluginManager()->loadPagePlugins($pageMetadata);
|
||||
|
||||
$content = '';
|
||||
foreach ($files as $file) {
|
||||
$content .= renderContentFile($file, $ctx);
|
||||
}
|
||||
|
||||
$pageMetadata = loadMetadata($pageDir);
|
||||
|
||||
getPluginManager()->loadPagePlugins($pageMetadata);
|
||||
|
||||
$navigation = $ctx->navigation;
|
||||
$homeLabel = $ctx->homeLabel;
|
||||
$pageTitle = $pageMetadata['title'] ?? null;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue