Skip to content

Commit d27a8ce

Browse files
committed
Refactored for Kirby 3
1 parent 520ba15 commit d27a8ce

File tree

6 files changed

+105
-84
lines changed

6 files changed

+105
-84
lines changed

index.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/**
4+
* Kirby Paperback Export
5+
*
6+
* @version 2.0.0
7+
* @author Grant Hutchinson <[email protected]>
8+
* @copyright Grant Hutchinson <[email protected]>
9+
* @link https://github.com/splorp/kirby-paperback-export
10+
* @license MIT
11+
*/
12+
13+
Kirby::plugin('splorp/paperback-export', [
14+
'snippets' => [
15+
'paperback-export/content' => __DIR__ . '/snippets/content.php',
16+
],
17+
'routes' => [
18+
[
19+
'pattern' => 'export/paperback',
20+
'action' => function () {
21+
22+
$includeUnlisted = option('splorp.paperback-export.includeUnlisted', true);
23+
$includeChildren = option('splorp.paperback-export.includeChildren', []);
24+
$excludeTemplate = option('splorp.paperback-export.excludeTemplate', []);
25+
26+
if (! is_array($includeChildren)) {
27+
throw new Exception('The option "splorp.paperback-export.includeChildren" must be an array.');
28+
}
29+
if (! is_array($excludeTemplate)) {
30+
throw new Exception('The option "splorp.paperback-export.excludeTemplate" must be an array.');
31+
}
32+
33+
$languages = site()->languages();
34+
$pages = site()->index();
35+
$title = site()->title();
36+
$description = site()->description();
37+
$version = site()->version();
38+
$filename = str::slug($title);
39+
40+
/* Check whether to include unlisted pages */
41+
42+
if (! $includeUnlisted) {
43+
$pages = $pages->listed();
44+
}
45+
46+
/* Include only the children of the specified page */
47+
48+
if ($includeChildren) {
49+
$pages = $pages->find($includeChildren)->children();
50+
}
51+
52+
/* Exclude pages using certain templates */
53+
54+
$pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate);
55+
56+
$template = __DIR__ . '/snippets/export.php';
57+
$paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'version', 'filename'));
58+
59+
return new response($paperback, 'txt');
60+
}
61+
]
62+
]
63+
]);

package.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
{
2-
"name": "paperback-export",
3-
"author": "Grant Hutchinson <[email protected]>",
4-
"version": "1.0.1",
5-
"description": "Kirby Paperback Export",
6-
"type": "kirby-plugin",
7-
"license": "MIT"
2+
"name": "splorp/paperback-export",
3+
"description": "Export Kirby 3 CMS content for use with the PaperBack Book Maker",
4+
"version": "2.0.0",
5+
"type": "kirby-plugin",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Grant Hutchinson",
10+
"email": "[email protected]",
11+
"homepage": "https://splorp.com/"
12+
}
13+
],
14+
"require": {
15+
"getkirby/composer-installer": "^1.1"
16+
},
17+
"extra": {
18+
"installer-name": "paperback-export"
19+
}
820
}

paperback-export.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

readme.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,15 @@ Paperback is a simple cross-platform utility created by [David Fedor](https://we
1616

1717
## Installation
1818

19-
After installing the plugin using one of the methods listed below, visiting `yoursite.com/export/paperback` should automatically download a text file without any additional configuration.
19+
After installing the plugin using one of the methods below, visiting `yoursite.com/export/paperback` should automatically download a text file without any additional configuration.
2020

2121
### Download
2222

2323
To install the plugin manually, [download the current release](https://github.com/splorp/kirby-paperback-export/releases), decompress the archive, and put the files in:
2424

2525
`site/plugins/paperback-export`
2626

27-
### Kirby CLI
28-
29-
Installing the plugin using the Kirby [command line interface](https://github.com/getkirby/cli):
30-
31-
$ kirby plugin:install splorp/kirby-paperback-export
32-
33-
Updating the plugin using the Kirby CLI:
34-
35-
$ kirby plugin:update splorp/kirby-paperback-export
27+
For [Kirby 2](https://github.com/getkirby-v2), download version [1.0.1](https://github.com/splorp/kirby-paperback-export/releases/tag/1.0.1) of the plugin.
3628

3729
### Git Submodule
3830

@@ -53,17 +45,23 @@ Updating the plugin as a Git submodule:
5345

5446
## Options
5547

56-
By default, Kirby Paperback Export will include the text from the title and description fields for every page on your Kirby site, including invisible pages. The following options allow you to select and filter which pages are included.
48+
By default, Kirby Paperback Export will include the text from the title and description fields for every page on your Kirby site, including unlisted pages. The following options allow you to filter which pages are included in the exported data.
5749

5850
```php
59-
// Include invisible pages
60-
c::set('paperback.include.invisible', true);
51+
// Include unlisted pages
52+
return [
53+
'splorp.paperback-export.includeUnlisted' => true,
54+
];
6155

6256
// Include only the children of a specific page
63-
c::set('paperback.include.children', []);
57+
return [
58+
'splorp.paperback-export.includeChildren' => [],
59+
];
6460

6561
// Exclude specific templates
66-
c::set('paperback.exclude.template', []);
62+
return [
63+
'splorp.paperback-export.excludeTemplate' => [],
64+
];
6765
```
6866

6967
## Known Issues
@@ -74,6 +72,12 @@ c::set('paperback.exclude.template', []);
7472

7573
## Release Notes
7674

75+
### 2.0.0
76+
+ Refactored and updated for Kirby 3
77+
+ Tweaked the option names to be more consistent and self explanatory
78+
+ Moved the file export code into `snippets/export.php`
79+
+ Renamed `snippets/page.php` to `snippets/content.php`
80+
7781
### 1.0.1
7882
+ Refactored filtering options
7983
+ Fixed formatting of paragraph breaks in `$page->text()`
@@ -87,7 +91,7 @@ A tip of the hat to [Pedro Borges](https://pedroborg.es/) and his [Kirby XML Sit
8791

8892
## License
8993

90-
Copyright © 2017 Grant Hutchinson
94+
Copyright © 2017–2021 Grant Hutchinson
9195

9296
This project is licensed under the short and sweet [MIT License](https://opensource.org/licenses/MIT). This license allows you to do anything pretty much anything you want with the contents of the repository, as long as you provide proper attribution and don’t hold anyone liable.
9397

snippets/page.php renamed to snippets/content.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php echo '@@TOC ' . $page->title() . PHP_EOL . PHP_EOL ?>
22
<?php $buffer = str_replace(array("</p>\r<p>", "</p>\r <p>", "</p> \r<p>", "</p>\n<p>", "</p>\n <p>", "</p> \n<p>", "</p>\r\n<p>", "</p>\r\n <p>", "</p> \r\n<p>"), '</p>' . PHP_EOL . PHP_EOL . '<p>', $page->text()->kirbytext()); ?>
33
<?php echo html_entity_decode(strip_tags($buffer)) . PHP_EOL . PHP_EOL ?>
4-
<?php if($page->content()->has('Source')): ?>
5-
<?php if($page->source()->pages()->count() > 1) { echo 'Sources: '; } else { echo 'Source: '; } ?>
6-
<?php $n=0; foreach($page->source()->pages() as $source): $n++; ?>
4+
<?php if($page->source()->exists()): ?>
5+
<?php if($page->source()->toPages()->count() > 1) { echo 'Sources: '; } else { echo 'Source: '; } ?>
6+
<?php $n=0; foreach($page->source()->toPages() as $source): $n++; ?>
77
<?php echo $source->title() . PHP_EOL ?>
88
<?php endforeach ?>
99
<?php echo PHP_EOL ?>

paperback-export.txt.php renamed to snippets/export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<?php if ($description != '') { echo ($description . PHP_EOL . PHP_EOL); } ?>
55
<?php if ($version != '') { echo ('Version ' . $version . PHP_EOL . PHP_EOL); } ?>
66
<?php foreach ($pages as $page) : ?>
7-
<?php snippet('paperback.page', compact('languages', 'page')) ?>
7+
<?php snippet('paperback-export/content', compact('languages', 'page')) ?>
88
<?php endforeach ?>

0 commit comments

Comments
 (0)