-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
681 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
Icon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# kirby-microseasons | ||
Japanese micro seasons plugin for Kirby. | ||
# Japanese Micro Seasons Plugin for Kirby | ||
|
||
Output information for one of the [72 Japanese micro season](https://www.nippon.com/en/features/h00124/) based on the current date directly into your Kirby templates and customize using the provided options in your Kirby `config.php` file. | ||
|
||
## Requirements | ||
|
||
- [**Kirby**](https://getkirby.com/) 4.x | ||
|
||
## Installation | ||
|
||
### [Kirby CLI](https://github.com/getkirby/cli) | ||
|
||
kirby plugin:install scottboms/kirby-microseasons | ||
|
||
### Git Submodule | ||
|
||
$ git submodule add https://github.com/scottboms/kirby-microseasons.git site/plugins/kirby-microseasons | ||
|
||
### Copy and Paste | ||
|
||
1. [Download](https://github.com/scottboms/kirby-microseasons/archive/master.zip) the contents of this repository as Zip file. | ||
2. Rename the extracted folder to `kirby-microseasons` and copy it into the `site/plugins/` directory in your Kirby project. | ||
|
||
## Usage | ||
|
||
In any template, drop in the following line to include the output from this plugin in your site. | ||
|
||
<?= snippet('microseasons') ?> | ||
|
||
## Configuration Options | ||
|
||
If you want to modify the wrapper HTML element, change the wrapper class, or output the date information in a custom format, you can configure this using the included plugin options. Date formatting follows the [available format options from PHP](https://www.php.net/manual/en/function.date.php). | ||
|
||
'scottboms.microseasons' => [ | ||
'wrapper' => 'div', | ||
'class' => 'microseasons', | ||
'dateformat' => 'M d, Y' | ||
], | ||
|
||
## 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. | ||
|
||
## License | ||
|
||
[MIT](https://opensource.org/licenses/MIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Scottboms\Microseasons; | ||
use Kirby\Toolkit\Date; | ||
|
||
class Season { | ||
|
||
public static function getAllSeasons(): string { | ||
return __DIR__ . '/../microseasons.json'; | ||
} | ||
|
||
public static function getSeason($currentDate, $jsonFileUrl): array { | ||
// fetch and decode the JSON data from the external link | ||
$json = file_get_contents($jsonFileUrl); | ||
$seasonsArray = json_decode($json, true); | ||
|
||
// convert $currentDate passed to 4-character mmdd format | ||
// since we don't care about the specific year | ||
$timestamp = date("m-d", strtotime($currentDate)); | ||
|
||
// create $currentSeason to hold an array of data to return | ||
$currentSeason = array(); | ||
|
||
// check which season the current date falls within | ||
foreach ($seasonsArray as $season) { | ||
$start = $season["start"]; | ||
$end = $season["end"]; | ||
|
||
// adjust the start and end dates to handle year transitions | ||
if ($start > $end) { | ||
if ($timestamp >= $start || $timestamp < $end) { | ||
// convert the date information to dates object | ||
$season["start"] = Date::createFromFormat('m-d', $start); | ||
$season["end"] = Date::createFromFormat('m-d', $end); | ||
return $currentSeason[] = $season; // return the matching season | ||
} | ||
} else { | ||
if ($timestamp >= $start && $timestamp < $end) { | ||
$season["start"] = Date::createFromFormat('m-d', $start); | ||
$season["end"] = Date::createFromFormat('m-d', $end); | ||
return $currentSeason[] = $season; // return the matching season | ||
} | ||
} | ||
} | ||
return $currentSeason; // no match fallback | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "scottboms/microseasons", | ||
"description": "Kirby Micro Seasons plugin", | ||
"type": "kirby-plugin", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/scottboms/kirby-microseasons", | ||
"authors": [ | ||
{ | ||
"name": "Scott Boms", | ||
"email": "[email protected]", | ||
"homepage": "https://scottboms.com" | ||
} | ||
], | ||
"license": "MIT", | ||
|
||
"keywords": [ | ||
"kirby3", | ||
"kirby3-cms", | ||
"kirby3-plugin" | ||
], | ||
"require": { | ||
"getkirby/composer-installer": "^1.1" | ||
}, | ||
"extra": { | ||
"installer-name": "kirby-microseasons" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
//namespace scottboms\kirby-microseasons; | ||
|
||
/** | ||
* Kirby Japanese Microseasons Plugin | ||
* | ||
* @version 1.0.0 | ||
* @author Scott Boms <[email protected]> | ||
* @copyright Scott Boms <[email protected]> | ||
* @link https://github.com/scottboms/kirby-microseasons | ||
* @license MIT | ||
**/ | ||
|
||
load([ | ||
'scottboms\Microseasons\Season' => __DIR__ . '/classes/Microseasons.php' | ||
]); | ||
|
||
use Scottboms\Microseasons\Season; | ||
use Kirby\Toolkit\Date; | ||
|
||
Kirby::plugin('scottboms/microseasons', [ | ||
'options' => [ | ||
'wrapper' => 'div', | ||
'class' => 'microseasons', | ||
'dateformat' => 'M d' | ||
], | ||
'snippets' => [ | ||
'microseasons' => __DIR__ . '/snippets/microseasons.php' | ||
] | ||
]); |
Oops, something went wrong.