Show the recently commented pages
This commit is contained in:
parent
85bb5c2ef4
commit
ba09e9a865
|
@ -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>
|
<p class="center">Showing <span class="totalRetrieved">{{grav.twig.comments.totalRetrieved}}</span> comments of <span class="totalAvailable">{{grav.twig.comments.totalAvailable}}</span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1>Recently commented pages</h1>
|
{% if grav.twig.pages %}
|
||||||
|
<h1>Recently commented pages</h1>
|
||||||
|
|
||||||
<div class="admin-block">
|
<div class="admin-block">
|
||||||
<table>
|
<table>
|
||||||
<tbody class="js__pages-container">
|
<tbody class="js__pages-container">
|
||||||
<tr class="h">
|
<tr class="h">
|
||||||
<th class="page">Page</th>
|
<th class="page">Page</th>
|
||||||
<th class="number-of-comments">Number of comments</th>
|
<th class="number-of-comments">Number of comments</th>
|
||||||
<th class="last-comment-date">Last commented on</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>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% for page in grav.twig.pages %}
|
||||||
</tbody>
|
<tr>
|
||||||
</table>
|
<td class="page">{{page.title}}</td>
|
||||||
|
<td class="number-of-comments">{{page.commentsCount}}</td>
|
||||||
{% if grav.twig.comments.totalRetrieved < grav.twig.comments.totalAvailable %}
|
<td class="last-comment-date">{{page.lastCommentDate}}</td>
|
||||||
<button type="button" class="button center js__load-more">
|
</tr>
|
||||||
Load more
|
{% endfor %}
|
||||||
</button>
|
</tbody>
|
||||||
{% endif %}
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
22
comments.php
22
comments.php
|
@ -129,6 +129,7 @@ class CommentsPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->grav['twig']->comments = $comments;
|
$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 $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
|
* Given a data file route, return the YAML content already parsed
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue