Skip to content

Commit a4e5be3

Browse files
committed
Adds a new custom panel section alongside a few other general improvements. This should also fix the version check within the panel.
1 parent e27e214 commit a4e5be3

File tree

8 files changed

+86
-9
lines changed

8 files changed

+86
-9
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ If you want to modify the wrapper HTML element, change the wrapper class, or out
3838
'dateformat' => 'M d, Y' // e.g. 'M d', 'Y-m-d', etc.
3939
],
4040

41+
## Section
42+
43+
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.
44+
45+
sections:
46+
microseasons:
47+
type: microseasons
48+
4149
## Disclaimer
4250

4351
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.

classes/Microseasons.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
class Season {
77

8+
public static function getCurrentDate(): string {
9+
$currentDate = date('Y-m-d');
10+
return $currentDate;
11+
}
12+
813
public static function getAllSeasons(): string {
914
return __DIR__ . '/../microseasons.json';
1015
}
@@ -35,8 +40,8 @@ public static function getSeason($today, $jsonFileUrl): array {
3540
// adjust the start and end dates to handle year transitions
3641
if ($start > $end) {
3742
if ($timestamp >= $start || $timestamp <= $end) {
38-
$season['start'] = $start->format(option("scottboms.microseasons.dateformat")) ?? $start->format('M d');
39-
$season['end'] = $end->format(option("scottboms.microseasons.dateformat")) ?? $end->format('M d');
43+
$season['start'] = Season::convertDateFormat($start);
44+
$season['end'] = Season::convertDateFormat($end);
4045
$season['wrapper'] = $wrapper;
4146
$season['class'] = $class;
4247
$season['includedates'] = $includedates;
@@ -47,8 +52,8 @@ public static function getSeason($today, $jsonFileUrl): array {
4752
}
4853
} else {
4954
if ($timestamp >= $start && $timestamp <= $end) {
50-
$season['start'] = $start->format(option("scottboms.microseasons.dateformat")) ?? $start->format('M d');
51-
$season['end'] = $end->format(option("scottboms.microseasons.dateformat")) ?? $end->format('M d');
55+
$season['start'] = Season::convertDateFormat($start);
56+
$season['end'] = Season::convertDateFormat($end);
5257
$season['wrapper'] = $wrapper;
5358
$season['class'] = $class;
5459
$season['includedates'] = $includedates;
@@ -61,4 +66,9 @@ public static function getSeason($today, $jsonFileUrl): array {
6166
}
6267
return $currentSeason;
6368
}
69+
70+
public static function convertDateFormat($dateString): string {
71+
$reformattedDate = $dateString->format(option("scottboms.microseasons.dateformat")) ?? $dateString->format('M d');
72+
return $reformattedDate;
73+
}
6474
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "scottboms/microseasons",
2+
"name": "scottboms/kirby-microseasons",
33
"description": "Kirby Micro Seasons plugin",
44
"type": "kirby-plugin",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"homepage": "https://github.com/scottboms/kirby-microseasons",
77
"authors": [
88
{

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
panel.plugin('scottboms/microseasons', {
2+
sections: {
3+
microseasons: {
4+
data: function () {
5+
return {
6+
microSeason: null
7+
}
8+
},
9+
created: function() {
10+
this.load().then(response => {
11+
this.microSeason = response.microSeason;
12+
});
13+
},
14+
template: `
15+
<k-section class="k-microseason-section">
16+
<k-box style="--width: 1/1">
17+
<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>
18+
</k-box>
19+
</k-section>`
20+
}
21+
}
22+
});

index.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Kirby Japanese Microseasons Plugin
77
*
8-
* @version 1.0.3
8+
* @version 1.0.4
99
* @author Scott Boms <[email protected]>
1010
* @copyright Scott Boms <[email protected]>
1111
* @link https://github.com/scottboms/kirby-microseasons
@@ -19,14 +19,19 @@
1919
use Scottboms\Microseasons\Season;
2020
use Kirby\Toolkit\Date;
2121

22-
Kirby::plugin('scottboms/microseasons', [
22+
Kirby::plugin('scottboms/kirby-microseasons', [
2323
'options' => [
24+
'cache' => True,
2425
'wrapper' => 'div',
2526
'class' => 'microseasons',
2627
'includedates' => True,
2728
'dateformat' => 'M d'
2829
],
2930
'snippets' => [
3031
'microseasons' => __DIR__ . '/snippets/microseasons.php'
32+
],
33+
'sections' => [
34+
'microseasons' => require __DIR__ . '/sections/microseasons.php'
3135
]
36+
3237
]);

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "kirby-microseasons",
3+
"description": "Kirby plugin to output the current Japanese microseason information",
4+
"author": "Scott Boms <[email protected]>",
5+
"version": "1.0.4",
6+
"type": "kirby-plugin",
7+
"license": "MIT"
8+
}

sections/microseasons.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Kirby\Toolkit\Date;
4+
5+
return [
6+
'props' => [
7+
'label' => function(string $label = "Current Microseason") {
8+
return $label;
9+
},
10+
'layout' => function(string $layout = "list") {
11+
return $layout;
12+
}
13+
],
14+
15+
'computed' => [
16+
'microSeason' => function() {
17+
$currentDate = Scottboms\Microseasons\Season::getCurrentDate();
18+
$jsonSeasons = Scottboms\Microseasons\Season::getAllSeasons();
19+
$matchSeason = Scottboms\Microseasons\Season::getSeason($currentDate, $jsonSeasons);
20+
21+
return $matchSeason;
22+
}
23+
]
24+
];

snippets/microseasons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$currentDate = date("Y-m-d");
2+
$currentDate = Scottboms\Microseasons\Season::getCurrentDate();
33
$jsonSeasons = Scottboms\Microseasons\Season::getAllSeasons();
44
$matchSeason = Scottboms\Microseasons\Season::getSeason($currentDate, $jsonSeasons);
55
?>

0 commit comments

Comments
 (0)