Skip to content

Commit

Permalink
Show the recently commented pages
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Oct 18, 2015
1 parent 85bb5c2 commit ba09e9a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
46 changes: 21 additions & 25 deletions admin/templates/comments.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,28 @@
<p class="center">Showing <span class="totalRetrieved">{{grav.twig.comments.totalRetrieved}}</span> comments of <span class="totalAvailable">{{grav.twig.comments.totalAvailable}}</span></p>
</div>

<h1>Recently commented pages</h1>

<div class="admin-block">
<table>
<tbody class="js__pages-container">
<tr class="h">
<th class="page">Page</th>
<th class="number-of-comments">Number of comments</th>
<th class="last-comment-date">Last commented on</th>
</tr>
{% for page in grav.twig.pages %}
<tr>
<td class="page">{{page.title}}</td>
<td class="number-of-comments">{{page.commentsCount}}</td>
<td class="last-comment-date"><strong>Page</strong>: {{page.lastCommentDate}}</td>
{% if grav.twig.pages %}
<h1>Recently commented pages</h1>

<div class="admin-block">
<table>
<tbody class="js__pages-container">
<tr class="h">
<th class="page">Page</th>
<th class="number-of-comments">Number of comments</th>
<th class="last-comment-date">Last commented on</th>
</tr>
{% endfor %}
</tbody>
</table>

{% if grav.twig.comments.totalRetrieved < grav.twig.comments.totalAvailable %}
<button type="button" class="button center js__load-more">
Load more
</button>
{% endif %}
</div>
{% for page in grav.twig.pages %}
<tr>
<td class="page">{{page.title}}</td>
<td class="number-of-comments">{{page.commentsCount}}</td>
<td class="last-comment-date">{{page.lastCommentDate}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}

{% endblock %}

Expand Down
22 changes: 22 additions & 0 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function onPluginsInitialized()
}

$this->grav['twig']->comments = $comments;
$this->grav['twig']->pages = $this->fetchPages();
}
}

Expand Down Expand Up @@ -295,6 +296,27 @@ private function fetchComments() {
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
*/
Expand Down

0 comments on commit ba09e9a

Please sign in to comment.