Show the recently commented pages

This commit is contained in:
Flavio Copes 2015-10-18 11:12:28 +02:00
parent 85bb5c2ef4
commit ba09e9a865
2 changed files with 42 additions and 24 deletions

View file

@ -129,6 +129,7 @@ class CommentsPlugin extends Plugin
}
$this->grav['twig']->comments = $comments;
$this->grav['twig']->pages = $this->fetchPages();
}
}
@ -295,6 +296,27 @@ class CommentsPlugin extends Plugin
return $this->getDataFromFilename($filename)['comments'];
}
/**
* Return the latest commented pages
*/
private function fetchPages() {
$files = [];
$files = $this->getFilesOrderedByModifiedDate();
$pages = [];
foreach($files as $file) {
$pages[] = [
'title' => $file->data['title'],
'commentsCount' => count($file->data['comments']),
'lastCommentDate' => gmdate('D, d M Y H:i:s', $file->modifiedDate)
];
}
return $pages;
}
/**
* Given a data file route, return the YAML content already parsed
*/