Add publish_date and expiry_date support
This commit is contained in:
parent
a22281c896
commit
4448798bf5
6 changed files with 148 additions and 3 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue