Skip to content

Commit

Permalink
Added option for specifying the datestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
splorp committed Jul 29, 2022
1 parent c497c58 commit 7594515
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 10 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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 */
Expand All @@ -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'));

Expand Down
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions snippets/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7594515

Please sign in to comment.