diff --git a/index.php b/index.php index 7b2315f..7f0f9c1 100755 --- a/index.php +++ b/index.php @@ -13,6 +13,7 @@ $includeUnlisted = option('splorp.paperback-export.includeUnlisted', true); $includeChildren = option('splorp.paperback-export.includeChildren', []); $excludeTemplate = option('splorp.paperback-export.excludeTemplate', []); + $includeDatestamp = option('splorp.paperback-export.includeDatestamp', false); if (! is_string($prefix)) { throw new Exception('The option “splorp.paperback-export.prefix” must be a string.'); @@ -29,13 +30,15 @@ if (! is_array($excludeTemplate)) { throw new Exception('The option “splorp.paperback-export.excludeTemplate” must be an array.'); } + if (! is_bool($includeDatestamp)) { + throw new Exception('The option “splorp.paperback-export.includeDatestamp” must be a boolean.'); + } $languages = site()->languages(); $pages = site()->index(); $title = site()->title(); $description = site()->description(); $version = site()->version(); - $datestamp = date('Y-M-d'); $filename = str::slug($title); /* Check whether to include unlisted pages */ @@ -54,6 +57,12 @@ $pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate); + /* Check whether to include a datestamp */ + + if ($includeDatestamp) { $datestamp = date('Y-M-d'); } else { $datestamp = ''; } + + /* Define template and variables */ + $template = __DIR__ . '/snippets/export.php'; $paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'prefix', 'fields', 'version', 'datestamp', 'filename')); diff --git a/readme.md b/readme.md index c5667d5..bc03958 100644 --- a/readme.md +++ b/readme.md @@ -141,8 +141,23 @@ return [ ]; ``` +### Include Datestamp + +The following option can be added to the `site/config/config.php` file, allowing you to add a datestamp that indicates when the data was exported. The datestamp is formatted as YYYY-MMM-DD and is inserted after the site title and description. + +This option is set to false by default. + +```php +return [ + 'splorp.paperback-export.includeUnlisted' => false, +]; +``` + ## Release Notes +### 2.0.5 ++ Added option to specify inclusion of the datestamp + ### 2.0.4 + Added option to specify other content fields diff --git a/snippets/export.php b/snippets/export.php index dd84555..8511d7f 100755 --- a/snippets/export.php +++ b/snippets/export.php @@ -3,8 +3,8 @@ header('Content-Disposition: attachment; filename="' . $filename . '-paperback.txt"'); echo $title . PHP_EOL . PHP_EOL; if ($description != '') { echo ($description . PHP_EOL . PHP_EOL); } - if ($version != '') { echo ('Version ' . $version . ' (' . $datestamp . ')'); } else { echo ('Published ' . $datestamp); } - echo (PHP_EOL . PHP_EOL); + if ($version != '') { echo ('Version ' . $version . PHP_EOL . PHP_EOL); } + if ($datestamp != '') { echo ('Published ' . $datestamp . PHP_EOL . PHP_EOL); } foreach ($pages as $page) : snippet('paperback-export/content', compact('languages', 'page', 'prefix', 'fields')); endforeach;