feat: add story-blocks plugin with chapter-break shortcode
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Grav\Plugin\Shortcodes;
|
||||
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
class ChapterBreakShortcode extends Shortcode
|
||||
{
|
||||
public function init(): void
|
||||
{
|
||||
$this->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
|
||||
? '<span class="chapter-break__number" aria-hidden="true">' . $number . '</span>'
|
||||
: '';
|
||||
|
||||
return <<<HTML
|
||||
<div class="chapter-break" aria-label="Chapter: {$title}">
|
||||
<div class="chapter-break__bg">
|
||||
<img src="{$imageUrl}" alt="{$alt}" class="chapter-break__img" loading="lazy">
|
||||
<div class="chapter-break__tint" aria-hidden="true"></div>
|
||||
</div>
|
||||
<div class="chapter-break__panel">
|
||||
{$numberHtml}
|
||||
<h2 class="chapter-break__title">{$title}</h2>
|
||||
<div class="chapter-break__rule" aria-hidden="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Plugin;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class StoryBlocksPlugin extends Plugin
|
||||
{
|
||||
private $currentPage = null;
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'onShortcodeHandlers' => ['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');
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user