From 166e2ff500cab3cc851fad29f38a8ad60efba528 Mon Sep 17 00:00:00 2001 From: Grant Hutchinson Date: Fri, 15 Jul 2022 14:43:21 -0600 Subject: [PATCH] Add option for table of contents prefix --- index.php | 5 +++-- readme.md | 22 +++++++++++++++++++++- snippets/content.php | 2 +- snippets/export.php | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 72a80a3..d6072f4 100755 --- a/index.php +++ b/index.php @@ -8,6 +8,7 @@ 'pattern' => 'export/paperback', 'action' => function () { + $prefix = option('splorp.paperback-export.prefix', ''); $includeUnlisted = option('splorp.paperback-export.includeUnlisted', true); $includeChildren = option('splorp.paperback-export.includeChildren', []); $excludeTemplate = option('splorp.paperback-export.excludeTemplate', []); @@ -32,7 +33,7 @@ if (! $includeUnlisted) { $pages = $pages->listed(); } - + /* Include only the children of specified pages */ if ($includeChildren) { @@ -44,7 +45,7 @@ $pages = $pages->filterBy('intendedTemplate', 'not in', $excludeTemplate); $template = __DIR__ . '/snippets/export.php'; - $paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'version', 'datestamp', 'filename')); + $paperback = tpl::load($template, compact('languages', 'pages', 'title', 'description', 'prefix', 'version', 'datestamp', 'filename')); return new response($paperback, 'txt'); } diff --git a/readme.md b/readme.md index 10c0493..218581c 100644 --- a/readme.md +++ b/readme.md @@ -45,10 +45,30 @@ Updating the plugin as a Git submodule: ## Options -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. +### Table of contents prefix + +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. + +This option is not set by default. + +```php +return [ + 'splorp.paperback-export.tocPrefix' => '', +]; +``` + +Specify a prefix. + +```php +return [ + 'splorp.paperback-export.tocPrefix' => ['@@TOC '], +]; +``` ### Include unlisted pages +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. + This option is set to true by default. ```php diff --git a/snippets/content.php b/snippets/content.php index 270e054..dcb0e13 100755 --- a/snippets/content.php +++ b/snippets/content.php @@ -1,5 +1,5 @@ title() . PHP_EOL . PHP_EOL; + echo $prefix . $page->title() . PHP_EOL . PHP_EOL; $buffer = $page->text()->kirbytext(); // Standardize line breaks between block elements $buffer = preg_replace('/>\s?[\r\n]\s?' . PHP_EOL . PHP_EOL . '<', $buffer); diff --git a/snippets/export.php b/snippets/export.php index 833607f..c1ec0c8 100755 --- a/snippets/export.php +++ b/snippets/export.php @@ -6,6 +6,6 @@ if ($version != '') { echo ('Version ' . $version . ' (' . $datestamp . ')'); } else { echo ('Published ' . $datestamp); } echo (PHP_EOL . PHP_EOL); foreach ($pages as $page) : - snippet('paperback-export/content', compact('languages', 'page')); + snippet('paperback-export/content', compact('languages', 'page', 'prefix')); endforeach; ?>