From aeaed44fcdcf677d9cae31424d4c5ce4c99c8b9f Mon Sep 17 00:00:00 2001 From: Dreytac Date: Fri, 17 Apr 2026 04:14:28 +1000 Subject: [PATCH] Add a created and updated date field blueprint and a hook that automatically updates the updated date when saving a page. --- blueprints/fields/dates.yml | 19 +++++++++++++++++++ index.php | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 blueprints/fields/dates.yml diff --git a/blueprints/fields/dates.yml b/blueprints/fields/dates.yml new file mode 100644 index 0000000..fb3f871 --- /dev/null +++ b/blueprints/fields/dates.yml @@ -0,0 +1,19 @@ +type: fields + +fields: + created: + label: Created + type: date + default: now + required: true + time: + notation: 12 + step: 1 + updated: + label: Updated + type: date + default: now + required: true + time: + notation: 12 + step: 1 diff --git a/index.php b/index.php index 569c895..1356557 100644 --- a/index.php +++ b/index.php @@ -24,6 +24,7 @@ Kirby::plugin( "blueprints" => [ "fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml", "fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml", + "fields/dates" => __DIR__ . "/blueprints/fields/dates.yml", ], "snippets" => [ "navbar/primary" => __DIR__ . "/snippets/navbar/primary.php", @@ -114,6 +115,14 @@ Kirby::plugin( return $links; }, + "page.update:after" => function ($newPage, $oldPage) { + if ($newPage->updated()->exists()) { + # Set the last updated time to now. + $newPage->update([ + "updated" => date("Y-m-d H:i"), + ]); + } + }, ], "siteMethods" => [ /**