Add publish_date and expiry_date support

This commit is contained in:
Ruben 2026-05-11 20:18:02 +02:00
parent a22281c896
commit 4448798bf5
6 changed files with 148 additions and 3 deletions

View file

@ -120,7 +120,10 @@ function buildNavigation(Context $ctx): array {
$itemPath = "{$ctx->contentDir}/$item";
$metadata = loadMetadata($itemPath);
// Skip invisible content (future publish or expired)
if (!isVisible($metadata)) continue;
// Only include if explicitly marked as menu item
// parse_ini_file returns boolean true as 1, false as empty string, and "true"/"false" as strings
if (!$metadata || !isset($metadata['menu']) || !$metadata['menu']) {

View file

@ -1,5 +1,15 @@
<?php
// Check if content is visible based on publish_date and expiry_date
// No metadata or absent fields = always visible
function isVisible(?array $metadata): bool {
if (!$metadata) return true;
$today = gmdate('Y-m-d');
if (isset($metadata['publish_date']) && $today < $metadata['publish_date']) return false;
if (isset($metadata['expiry_date']) && $today > $metadata['expiry_date']) return false;
return true;
}
function resolveTemplate(string $templateName): string {
$customTemplate = dirname(__DIR__) . "/custom/templates/$templateName.php";
$defaultTemplate = __DIR__ . "/default/templates/$templateName.php";
@ -39,6 +49,9 @@ function buildListItems(string $dir, Context $ctx, ?array $parentMetadata): arra
$items = array_filter(array_map(function($item) use ($dir, $ctx) {
$itemPath = "$dir/$item";
$metadata = loadMetadata($itemPath);
if (!isVisible($metadata)) return null;
$coverImage = findCoverImage($itemPath);
$pdfFile = findPdfFile($itemPath);

View file

@ -194,6 +194,13 @@ switch ($parsedPath['type']) {
exit;
}
$metadata = loadMetadata($dir);
if (!isVisible($metadata)) {
http_response_code(404);
renderTemplate($ctx, "<h1>404 - Page Not Found</h1><p>The requested page could not be found.</p>", 404);
exit;
}
$contentFiles = findAllContentFiles($dir);
if (!empty($contentFiles)) {
renderMultipleFiles($ctx, $contentFiles, $dir);
@ -218,7 +225,13 @@ switch ($parsedPath['type']) {
// Load metadata for this directory
$metadata = loadMetadata($dir);
if (!isVisible($metadata)) {
http_response_code(404);
renderTemplate($ctx, "<h1>404 - Page Not Found</h1><p>The requested page could not be found.</p>", 404);
exit;
}
// Check if hide_list is enabled - if so, treat as page
if (isset($metadata['hide_list']) && $metadata['hide_list']) {
if (!empty($contentFiles)) {