diff --git a/plugins/story-blocks/shortcodes/ChapterBreakShortcode.php b/plugins/story-blocks/shortcodes/ChapterBreakShortcode.php new file mode 100644 index 0000000..5a6edc8 --- /dev/null +++ b/plugins/story-blocks/shortcodes/ChapterBreakShortcode.php @@ -0,0 +1,39 @@ +shortcode->getHandlers()->add('chapter-break', function (ShortcodeInterface $sc) { + $plugin = $this->grav['plugins']->getPlugin('story-blocks'); + $page = $plugin ? $plugin->getCurrentPage() : null; + + $imageName = $sc->getParameter('image', ''); + $title = htmlspecialchars($sc->getParameter('title', ''), ENT_QUOTES); + $number = htmlspecialchars($sc->getParameter('number', ''), ENT_QUOTES); + $alt = htmlspecialchars($sc->getParameter('alt', $title), ENT_QUOTES); + $imageUrl = ($page && $imageName) ? $page->url() . '/' . $imageName : $imageName; + + $numberHtml = $number + ? '' + : ''; + + return << +
+ {$alt} + +
+
+ {$numberHtml} +

{$title}

+ +
+ +HTML; + }); + } +} diff --git a/plugins/story-blocks/story-blocks.php b/plugins/story-blocks/story-blocks.php new file mode 100644 index 0000000..da24e94 --- /dev/null +++ b/plugins/story-blocks/story-blocks.php @@ -0,0 +1,33 @@ + ['onShortcodeHandlers', 0], + 'onPageContentRaw' => ['onPageContentRaw', 1000], + ]; + } + + public function onPageContentRaw(Event $event): void + { + $this->currentPage = $event['page']; + } + + public function getCurrentPage() + { + return $this->currentPage; + } + + public function onShortcodeHandlers(): void + { + $this->grav['shortcode']->registerAllShortcodes(__DIR__ . '/shortcodes'); + } +} diff --git a/plugins/story-blocks/story-blocks.yaml b/plugins/story-blocks/story-blocks.yaml new file mode 100644 index 0000000..d0c9999 --- /dev/null +++ b/plugins/story-blocks/story-blocks.yaml @@ -0,0 +1,13 @@ +name: Story Blocks +version: 1.0.0 +description: Storytelling shortcode blocks for long-form travel stories +author: + name: Mischa +homepage: https://github.com/m-cluitmans +keywords: shortcode, story, storytelling +bugs: '' +license: MIT +dependencies: + - { name: grav, version: '>=2.0.0-rc.1' } + - { name: shortcode-core, version: '>=5.0.0' } +enabled: true