Skip to content

Commit

Permalink
add ability to override modified date via frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 2, 2023
1 parent e3b0aa0 commit 65aeb82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
13 changes: 9 additions & 4 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit 65aeb82

Please sign in to comment.