Skip to content

Commit

Permalink
Adds a new custom panel section alongside a few other general improve…
Browse files Browse the repository at this point in the history
…ments. This should also fix the version check within the panel.
  • Loading branch information
scottboms committed Feb 16, 2024
1 parent e27e214 commit a4e5be3
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions classes/Microseasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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: `
<k-section class="k-microseason-section">
<k-box style="--width: 1/1">
<k-text size="medium"><b>{{ microSeason['period'] }}</b> &mdash; {{ microSeason['name'] }} {{ microSeason['translation'] }} <span class="k-help">({{ microSeason['start'] }}&ndash;{{ microSeason['end'] }})</span></k-text>
</k-box>
</k-section>`
}
}
});
9 changes: 7 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Kirby Japanese Microseasons Plugin
*
* @version 1.0.3
* @version 1.0.4
* @author Scott Boms <plugins@scottboms.com>
* @copyright Scott Boms <plugins@scottboms.com>
* @link https://github.com/scottboms/kirby-microseasons
Expand All @@ -19,14 +19,19 @@
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,
'dateformat' => 'M d'
],
'snippets' => [
'microseasons' => __DIR__ . '/snippets/microseasons.php'
],
'sections' => [
'microseasons' => require __DIR__ . '/sections/microseasons.php'
]

]);
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "kirby-microseasons",
"description": "Kirby plugin to output the current Japanese microseason information",
"author": "Scott Boms <scottboms@gmail.com>",
"version": "1.0.4",
"type": "kirby-plugin",
"license": "MIT"
}
24 changes: 24 additions & 0 deletions sections/microseasons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Kirby\Toolkit\Date;

return [
'props' => [
'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;
}
]
];
2 changes: 1 addition & 1 deletion snippets/microseasons.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$currentDate = date("Y-m-d");
$currentDate = Scottboms\Microseasons\Season::getCurrentDate();
$jsonSeasons = Scottboms\Microseasons\Season::getAllSeasons();
$matchSeason = Scottboms\Microseasons\Season::getSeason($currentDate, $jsonSeasons);
?>
Expand Down

0 comments on commit a4e5be3

Please sign in to comment.