Making A Poetry Blog
As you may have noticed, I have added a poetry section to my website :)
This has been a work-in-progress for quite a while now and I had to think if I wanted to publish the poems, plus the implementation in Kirby took me a while to figure out.
I wanted it so that when you open the poems page, it brings you to the first poem, but I ended up just going for a random poem (I may change that in the future, we'll see). I remembered I used routes before for the RSS feed so my idea was to implement a redirect to a random poem whenever you visit /poems.
The code looks like this:
[
"pattern" => "poems",
"action" => function () {
// Fetch all listed poems under the poetry page
$poems = site()->find("poems")->children()->listed();
// If no poems are found, return a 404 page
if ($poems->isEmpty()) {
return go("error");
}
// Select a random poem
$randomPoem = $poems->shuffle()->first();
// Redirect to the random poem's URL
return go($randomPoem->url());
},
],
And that's pretty much it for the technical implementation.
As for my poems, I consider them to be quite mediocre, but I've had some people like them a lot. So you may like them. Go read one!
This was Day 7 of #100DaysToOffload (one week milestone 🎊🎉)