From a4e5be3e7f9c395a5f83d680abef853f7780cd1d Mon Sep 17 00:00:00 2001 From: Scott Boms Date: Thu, 15 Feb 2024 23:25:44 -0800 Subject: [PATCH] Adds a new custom panel section alongside a few other general improvements. This should also fix the version check within the panel. --- README.md | 8 ++++++++ classes/Microseasons.php | 18 ++++++++++++++---- composer.json | 4 ++-- index.js | 22 ++++++++++++++++++++++ index.php | 9 +++++++-- package.json | 8 ++++++++ sections/microseasons.php | 24 ++++++++++++++++++++++++ snippets/microseasons.php | 2 +- 8 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 index.js create mode 100644 package.json create mode 100644 sections/microseasons.php diff --git a/README.md b/README.md index 90720c3..6333ea2 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,14 @@ If you want to modify the wrapper HTML element, change the wrapper class, or out 'dateformat' => 'M d, Y' // e.g. 'M d', 'Y-m-d', etc. ], +## Section + +The plugin also includes a custom `section` type called `microseasons` that you can use to display information within the panel. This can be added to a blueprint and also adopts any defined configuration options. + + sections: + microseasons: + type: microseasons + ## Disclaimer This plugin is provided "as is" with no guarantee. Use it at your own risk and always test before using it in a production environment. If you identify an issue, typo, etc, please [create a new issue](https://github.com/scottboms/kirby-microseasons/issues/new) so I can investigate. diff --git a/classes/Microseasons.php b/classes/Microseasons.php index 91915b4..31fd9a9 100644 --- a/classes/Microseasons.php +++ b/classes/Microseasons.php @@ -5,6 +5,11 @@ class Season { + public static function getCurrentDate(): string { + $currentDate = date('Y-m-d'); + return $currentDate; + } + public static function getAllSeasons(): string { return __DIR__ . '/../microseasons.json'; } @@ -35,8 +40,8 @@ public static function getSeason($today, $jsonFileUrl): array { // adjust the start and end dates to handle year transitions if ($start > $end) { if ($timestamp >= $start || $timestamp <= $end) { - $season['start'] = $start->format(option("scottboms.microseasons.dateformat")) ?? $start->format('M d'); - $season['end'] = $end->format(option("scottboms.microseasons.dateformat")) ?? $end->format('M d'); + $season['start'] = Season::convertDateFormat($start); + $season['end'] = Season::convertDateFormat($end); $season['wrapper'] = $wrapper; $season['class'] = $class; $season['includedates'] = $includedates; @@ -47,8 +52,8 @@ public static function getSeason($today, $jsonFileUrl): array { } } else { if ($timestamp >= $start && $timestamp <= $end) { - $season['start'] = $start->format(option("scottboms.microseasons.dateformat")) ?? $start->format('M d'); - $season['end'] = $end->format(option("scottboms.microseasons.dateformat")) ?? $end->format('M d'); + $season['start'] = Season::convertDateFormat($start); + $season['end'] = Season::convertDateFormat($end); $season['wrapper'] = $wrapper; $season['class'] = $class; $season['includedates'] = $includedates; @@ -61,4 +66,9 @@ public static function getSeason($today, $jsonFileUrl): array { } return $currentSeason; } + + public static function convertDateFormat($dateString): string { + $reformattedDate = $dateString->format(option("scottboms.microseasons.dateformat")) ?? $dateString->format('M d'); + return $reformattedDate; + } } \ No newline at end of file diff --git a/composer.json b/composer.json index d85081c..c5c0df7 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { - "name": "scottboms/microseasons", + "name": "scottboms/kirby-microseasons", "description": "Kirby Micro Seasons plugin", "type": "kirby-plugin", - "version": "1.0.3", + "version": "1.0.4", "homepage": "https://github.com/scottboms/kirby-microseasons", "authors": [ { diff --git a/index.js b/index.js new file mode 100644 index 0000000..71139ad --- /dev/null +++ b/index.js @@ -0,0 +1,22 @@ +panel.plugin('scottboms/microseasons', { + sections: { + microseasons: { + data: function () { + return { + microSeason: null + } + }, + created: function() { + this.load().then(response => { + this.microSeason = response.microSeason; + }); + }, + template: ` + + + {{ microSeason['period'] }} — {{ microSeason['name'] }} {{ microSeason['translation'] }} ({{ microSeason['start'] }}–{{ microSeason['end'] }}) + + ` + } + } +}); diff --git a/index.php b/index.php index bbe2daa..c26d0eb 100644 --- a/index.php +++ b/index.php @@ -5,7 +5,7 @@ /** * Kirby Japanese Microseasons Plugin * - * @version 1.0.3 + * @version 1.0.4 * @author Scott Boms * @copyright Scott Boms * @link https://github.com/scottboms/kirby-microseasons @@ -19,8 +19,9 @@ use Scottboms\Microseasons\Season; use Kirby\Toolkit\Date; -Kirby::plugin('scottboms/microseasons', [ +Kirby::plugin('scottboms/kirby-microseasons', [ 'options' => [ + 'cache' => True, 'wrapper' => 'div', 'class' => 'microseasons', 'includedates' => True, @@ -28,5 +29,9 @@ ], 'snippets' => [ 'microseasons' => __DIR__ . '/snippets/microseasons.php' + ], + 'sections' => [ + 'microseasons' => require __DIR__ . '/sections/microseasons.php' ] + ]); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4d079fd --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "kirby-microseasons", + "description": "Kirby plugin to output the current Japanese microseason information", + "author": "Scott Boms ", + "version": "1.0.4", + "type": "kirby-plugin", + "license": "MIT" +} diff --git a/sections/microseasons.php b/sections/microseasons.php new file mode 100644 index 0000000..5ee8b2c --- /dev/null +++ b/sections/microseasons.php @@ -0,0 +1,24 @@ + [ + 'label' => function(string $label = "Current Microseason") { + return $label; + }, + 'layout' => function(string $layout = "list") { + return $layout; + } + ], + + 'computed' => [ + 'microSeason' => function() { + $currentDate = Scottboms\Microseasons\Season::getCurrentDate(); + $jsonSeasons = Scottboms\Microseasons\Season::getAllSeasons(); + $matchSeason = Scottboms\Microseasons\Season::getSeason($currentDate, $jsonSeasons); + + return $matchSeason; + } + ] +]; \ No newline at end of file diff --git a/snippets/microseasons.php b/snippets/microseasons.php index a898db4..ce79d21 100644 --- a/snippets/microseasons.php +++ b/snippets/microseasons.php @@ -1,5 +1,5 @@