Merge pull request #634 from sebgie/issue#593

Add setting for posts per page
This commit is contained in:
Hannah Wolfe 2013-09-06 08:45:44 -07:00
commit 2f6828ed6c
4 changed files with 27 additions and 5 deletions

View File

@ -57,10 +57,15 @@
<label for="activeTheme"><strong>Theme</strong></label>
<select id="activeTheme" name="general[activeTheme]">
{{#each availableThemes}}
<option value="{{ name }}" {{#if active}}selected{{/if}}>{{ name }}</option>
<option value="{{name}}" {{#if active}}selected{{/if}}>{{name}}</option>
{{/each}}
</select>
</div>
<div class="form-group">
<label for="postsPerPage"><strong>Posts per page</strong></label>
<input id="postsPerPage" name="general[postsPerPage]" type="number" value="{{postsPerPage}}">
<p>Number of posts per page displayed</p>
</div>
</fieldset>

View File

@ -164,7 +164,8 @@
email: this.$('#email-address').val(),
logo: this.$('#logo').attr("src"),
icon: this.$('#icon').attr("src"),
activeTheme: this.$('#activeTheme').val()
activeTheme: this.$('#activeTheme').val(),
postsPerPage: this.$('#postsPerPage').val()
}, {
success: this.saveSuccess,
error: this.saveError

View File

@ -14,14 +14,24 @@ var Ghost = require('../../ghost'),
frontendControllers = {
'homepage': function (req, res) {
// Parse the page number
var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
postsPerPage = parseInt(ghost.settings().postsPerPage, 10),
options = {};
// No negative pages
if (pageParam < 1) {
if (isNaN(pageParam) || pageParam < 1) {
//redirect to 404 page?
return res.redirect("/page/1/");
}
options.page = pageParam;
// No negative posts per page, must be number
if (!isNaN(postsPerPage) && postsPerPage > 0) {
options.limit = postsPerPage;
}
api.posts.browse(options).then(function (page) {
api.posts.browse({page: pageParam}).then(function (page) {
var maxPage = page.pages;
// A bit of a hack for situations with no content.

View File

@ -43,5 +43,11 @@
"key": "icon",
"value": "",
"type": "blog"
},
{
"key": "postsPerPage",
"value": "6",
"type": "blog"
}
]