Merge pull request #634 from sebgie/issue#593
Add setting for posts per page
This commit is contained in:
commit
2f6828ed6c
@ -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>
|
||||
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -43,5 +43,11 @@
|
||||
"key": "icon",
|
||||
"value": "",
|
||||
"type": "blog"
|
||||
},
|
||||
{
|
||||
"key": "postsPerPage",
|
||||
"value": "6",
|
||||
"type": "blog"
|
||||
}
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user