Skip to content

Commit 7594515

Browse files
committed
Added option for specifying the datestamp
1 parent c497c58 commit 7594515

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

index.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
$includeUnlisted = option('splorp.paperback-export.includeUnlisted', true);
1414
$includeChildren = option('splorp.paperback-export.includeChildren', []);
1515
$excludeTemplate = option('splorp.paperback-export.excludeTemplate', []);
16+
$includeDatestamp = option('splorp.paperback-export.includeDatestamp', false);
1617

1718
if (! is_string($prefix)) {
1819
throw new Exception('The option “splorp.paperback-export.prefix” must be a string.');
@@ -29,13 +30,15 @@
2930
if (! is_array($excludeTemplate)) {
3031
throw new Exception('The option “splorp.paperback-export.excludeTemplate” must be an array.');
3132
}
33+
if (! is_bool($includeDatestamp)) {
34+
throw new Exception('The option “splorp.paperback-export.includeDatestamp” must be a boolean.');
35+
}
3236

3337
$languages = site()->languages();
3438
$pages = site()->index();
3539
$title = site()->title();
3640
$description = site()->description();
3741
$version = site()->version();
38-
$datestamp = date('Y-M-d');
3942
$filename = str::slug($title);
4043

4144
/* Check whether to include unlisted pages */
@@ -54,6 +57,12 @@
5457

5558
$pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate);
5659

60+
/* Check whether to include a datestamp */
61+
62+
if ($includeDatestamp) { $datestamp = date('Y-M-d'); } else { $datestamp = ''; }
63+
64+
/* Define template and variables */
65+
5766
$template = __DIR__ . '/snippets/export.php';
5867
$paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'prefix', 'fields', 'version', 'datestamp', 'filename'));
5968

readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,23 @@ return [
141141
];
142142
```
143143

144+
### Include Datestamp
145+
146+
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.
147+
148+
This option is set to false by default.
149+
150+
```php
151+
return [
152+
'splorp.paperback-export.includeUnlisted' => false,
153+
];
154+
```
155+
144156
## Release Notes
145157

158+
### 2.0.5
159+
+ Added option to specify inclusion of the datestamp
160+
146161
### 2.0.4
147162
+ Added option to specify other content fields
148163

snippets/export.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
header('Content-Disposition: attachment; filename="' . $filename . '-paperback.txt"');
44
echo $title . PHP_EOL . PHP_EOL;
55
if ($description != '') { echo ($description . PHP_EOL . PHP_EOL); }
6-
if ($version != '') { echo ('Version ' . $version . ' (' . $datestamp . ')'); } else { echo ('Published ' . $datestamp); }
7-
echo (PHP_EOL . PHP_EOL);
6+
if ($version != '') { echo ('Version ' . $version . PHP_EOL . PHP_EOL); }
7+
if ($datestamp != '') { echo ('Published ' . $datestamp . PHP_EOL . PHP_EOL); }
88
foreach ($pages as $page) :
99
snippet('paperback-export/content', compact('languages', 'page', 'prefix', 'fields'));
1010
endforeach;

0 commit comments

Comments
 (0)