Skip to content

Commit 166e2ff

Browse files
committed
Add option for table of contents prefix
1 parent 6fc1c92 commit 166e2ff

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'pattern' => 'export/paperback',
99
'action' => function () {
1010

11+
$prefix = option('splorp.paperback-export.prefix', '');
1112
$includeUnlisted = option('splorp.paperback-export.includeUnlisted', true);
1213
$includeChildren = option('splorp.paperback-export.includeChildren', []);
1314
$excludeTemplate = option('splorp.paperback-export.excludeTemplate', []);
@@ -32,7 +33,7 @@
3233
if (! $includeUnlisted) {
3334
$pages = $pages->listed();
3435
}
35-
36+
3637
/* Include only the children of specified pages */
3738

3839
if ($includeChildren) {
@@ -44,7 +45,7 @@
4445
$pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate);
4546

4647
$template = __DIR__ . '/snippets/export.php';
47-
$paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'version', 'datestamp', 'filename'));
48+
$paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'prefix', 'version', 'datestamp', 'filename'));
4849

4950
return new response($paperback, 'txt');
5051
}

readme.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,30 @@ Updating the plugin as a Git submodule:
4545

4646
## Options
4747

48-
By default, text located in the `$page->title()` and `$page->text()` fields for every page on your Kirby site will be included in the exported data. The following options can be added to the `site/config/config.php` file, allowing you to filter which pages are included based on certain criteria.
48+
### Table of contents prefix
49+
50+
Paperback books can include a table of contents created from the text found located in the `$page->title()` field. The following option can be added to the `site/config/config.php` file, allowing you to specify a custom table of contents prefix.
51+
52+
This option is not set by default.
53+
54+
```php
55+
return [
56+
'splorp.paperback-export.tocPrefix' => '',
57+
];
58+
```
59+
60+
Specify a prefix.
61+
62+
```php
63+
return [
64+
'splorp.paperback-export.tocPrefix' => ['@@TOC '],
65+
];
66+
```
4967

5068
### Include unlisted pages
5169

70+
By default, text located in the `$page->title()` and `$page->text()` fields for every page on your Kirby site will be included in the exported data. The following options can be added to the `site/config/config.php` file, allowing you to filter which pages are included based on certain criteria.
71+
5272
This option is set to true by default.
5373

5474
```php

snippets/content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
echo '@@TOC ' . $page->title() . PHP_EOL . PHP_EOL;
2+
echo $prefix . $page->title() . PHP_EOL . PHP_EOL;
33
$buffer = $page->text()->kirbytext();
44
// Standardize line breaks between block elements
55
$buffer = preg_replace('/>\s?[\r\n]\s?</', '>' . PHP_EOL . PHP_EOL . '<', $buffer);

snippets/export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
if ($version != '') { echo ('Version ' . $version . ' (' . $datestamp . ')'); } else { echo ('Published ' . $datestamp); }
77
echo (PHP_EOL . PHP_EOL);
88
foreach ($pages as $page) :
9-
snippet('paperback-export/content', compact('languages', 'page'));
9+
snippet('paperback-export/content', compact('languages', 'page', 'prefix'));
1010
endforeach;
1111
?>

0 commit comments

Comments
 (0)