mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Merge pull request #467 from jgable/titleFixes
Trim title and don't allow negative pages
This commit is contained in:
commit
fef1aae7be
2 changed files with 7 additions and 1 deletions
|
@ -14,6 +14,12 @@ frontendControllers = {
|
||||||
'homepage': function (req, res) {
|
'homepage': function (req, res) {
|
||||||
// Parse the page number
|
// 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;
|
||||||
|
|
||||||
|
// No negative pages
|
||||||
|
if (pageParam < 1) {
|
||||||
|
return res.redirect("/page/1/");
|
||||||
|
}
|
||||||
|
|
||||||
api.posts.browse({page: pageParam}).then(function (page) {
|
api.posts.browse({page: pageParam}).then(function (page) {
|
||||||
// If page is greater than number of pages we have, redirect to last page
|
// If page is greater than number of pages we have, redirect to last page
|
||||||
if (pageParam > page.pages) {
|
if (pageParam > page.pages) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ Post = GhostBookshelf.Model.extend({
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"`
|
// Remove URL reserved chars: `:/?#[]@!$&'()*+,;=` as well as `\%<>|^~£"`
|
||||||
slug = title.replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '')
|
slug = title.trim().replace(/[:\/\?#\[\]@!$&'()*+,;=\\%<>\|\^~£"]/g, '')
|
||||||
// Replace dots and spaces with a dash
|
// Replace dots and spaces with a dash
|
||||||
.replace(/(\s|\.)/g, '-')
|
.replace(/(\s|\.)/g, '-')
|
||||||
// Convert 2 or more dashes into a single dash
|
// Convert 2 or more dashes into a single dash
|
||||||
|
|
Loading…
Add table
Reference in a new issue