Skip to content

Commit

Permalink
Various tweaks and hopefully improvements to file change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 10, 2014
1 parent 18e79ce commit 41f4d26
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
11 changes: 4 additions & 7 deletions system/src/Grav/Common/Filesystem/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,10 @@ public static function lastModifiedFile($path)

/** @var \RecursiveDirectoryIterator $file */
foreach ($itr as $file) {
if (!$file->isDir()) {
$file_modified = $file->getMTime();
if ($file_modified > $last_modified) {
$last_modified = $file_modified;
}
$file_modified = $file->getMTime();
if ($file_modified > $last_modified) {
$last_modified = $file_modified;
}

}

return $last_modified;
Expand Down Expand Up @@ -277,7 +274,7 @@ protected static function doDelete($folder)
class GravRecursiveFilterIterator extends \RecursiveFilterIterator
{
public static $FILTERS = array(
'.', '..', '.DS_Store'
'..', '.DS_Store'
);

public function accept()
Expand Down
45 changes: 24 additions & 21 deletions system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,33 +750,36 @@ public function metadata()
$this->metadata = array();
$page_header = $this->header;


// Set the Generator tag
$this->metadata['generator'] = array('name'=>'generator', 'content'=>'Grav ' . GRAV_VERSION);

// Merge any site.metadata settings in with page metadata
$defaults = (array) self::$grav['config']->get('site.metadata');
if (isset($page_header->metadata)) {
$page_header->metadata = array_merge($defaults, $page_header->metadata);
} else {
$page_header->metadata = $defaults;
}

// Build an array of meta objects..
foreach((array)$page_header->metadata as $key => $value) {
// Safety check to ensure we have a header
if ($page_header) {
// Merge any site.metadata settings in with page metadata
$defaults = (array) self::$grav['config']->get('site.metadata');

// If this is a property type metadata: "og", "twitter", "facebook" etc
if (is_array($value)) {
foreach ($value as $property => $prop_value) {
$prop_key = $key.":".$property;
$this->metadata[$prop_key] = array('property'=>$prop_key, 'content'=>$prop_value);
}
// If it this is a standard meta data type
if (isset($page_header->metadata)) {
$page_header->metadata = array_merge($defaults, $page_header->metadata);
} else {
if (in_array($key, $header_tag_http_equivs)) {
$this->metadata[$key] = array('http_equiv'=>$key, 'content'=>$value);
$page_header->metadata = $defaults;
}

// Build an array of meta objects..
foreach((array)$page_header->metadata as $key => $value) {

// If this is a property type metadata: "og", "twitter", "facebook" etc
if (is_array($value)) {
foreach ($value as $property => $prop_value) {
$prop_key = $key.":".$property;
$this->metadata[$prop_key] = array('property'=>$prop_key, 'content'=>$prop_value);
}
// If it this is a standard meta data type
} else {
$this->metadata[$key] = array('name'=>$key, 'content'=>$value);
if (in_array($key, $header_tag_http_equivs)) {
$this->metadata[$key] = array('http_equiv'=>$key, 'content'=>$value);
} else {
$this->metadata[$key] = array('name'=>$key, 'content'=>$value);
}
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,18 @@ protected function recurse($directory = PAGES_DIR, Page &$parent = null)
// set current modified of page
$last_modified = $page->modified();

// flat for content availability
$content_exists = false;

/** @var \DirectoryIterator $file */
foreach ($iterator as $file) {
$name = $file->getFilename();
$modified = $file->getMTime();

if ($file->isFile() && Utils::endsWith($name, CONTENT_EXT)) {

$page->init($file);
$content_exists = true;

if ($config->get('system.pages.events.page')) {
$this->grav->fireEvent('onPageProcessed', new Event(['page' => $page]));
Expand All @@ -494,24 +499,23 @@ protected function recurse($directory = PAGES_DIR, Page &$parent = null)

// set the modified time if not already set
if (!$page->date()) {
$page->date($file->getMTime());
$page->date($modified);
}

// set the last modified time on pages
$this->lastModified($file->getMTime());

if ($config->get('system.pages.events.page')) {
$this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page]));
}
}

// Update the last modified if it's newer than already found
$date = $file->getMTime();
if ($date > $last_modified) {
$last_modified = $date;
if ($modified > $last_modified) {
$last_modified = $modified;
}
}


// Set routability to false if no page found
if (!$content_exists) {
$page->routable(false);
}

// Override the modified and ID so that it takes the latest change into account
Expand Down

0 comments on commit 41f4d26

Please sign in to comment.