From 65aeb82e2132e1ea3f7d606a43cb0eaccd3909d3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 2 Oct 2023 09:36:22 -0600 Subject: [PATCH] add ability to override modified date via frontmatter --- CHANGELOG.md | 2 ++ system/src/Grav/Common/Page/Page.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8578a1148..846b110d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.7.42.4 ## mm/dd/2023 +1. [](#new) + * Add the ability to programtically set a page's `modified` timestamp via a `modified:` frontmatter entry 2. [](#improved) * Include `phar` in the list of `security.uploads_dangerous_extensions` diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3fc5acb0ae..5cabe99de4 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -415,15 +415,17 @@ public function header($var = null) if (!Utils::isAdminPlugin()) { // If there's a `frontmatter.yaml` file merge that in with the page header // note page's own frontmatter has precedence and will overwrite any defaults - $frontmatterFile = CompiledYamlFile::instance($this->path . '/' . $this->folder . '/frontmatter.yaml'); - if ($frontmatterFile->exists()) { - $frontmatter_data = (array)$frontmatterFile->content(); + $frontmatter_filename = $this->path . '/' . $this->folder . '/frontmatter.yaml'; + if (file_exists($frontmatter_filename)) { + $frontmatter_file = CompiledYamlFile::instance($frontmatter_filename); + $frontmatter_data = $frontmatter_file->content(); $this->header = (object)array_replace_recursive( $frontmatter_data, (array)$this->header ); - $frontmatterFile->free(); + $frontmatter_file->free(); } + // Process frontmatter with Twig if enabled if (Grav::instance()['config']->get('system.pages.frontmatter.process_twig') === true) { $this->processFrontmatter(); @@ -446,6 +448,9 @@ public function header($var = null) } if ($var) { + if (isset($this->header->modified)) { + $this->modified($this->header->modified); + } if (isset($this->header->slug)) { $this->slug($this->header->slug); }