Skip to content

Commit

Permalink
Static pages do not use dated permalinks
Browse files Browse the repository at this point in the history
closes TryGhost#1753
- Pages are registered to '/:slug/' route if posts are using dated permalinks
  • Loading branch information
markberger committed Dec 28, 2013
1 parent 32f6575 commit 075dd8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion core/server/controllers/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ frontendControllers = {
});
},
'single': function (req, res, next) {
api.posts.read(_.pick(req.params, ['id', 'slug'])).then(function (post) {
api.posts.read(_.pick(req.params, ['id', 'slug', 'page'])).then(function (post) {
if (post) {
filters.doFilter('prePostsRender', post).then(function (post) {
api.settings.read('activeTheme').then(function (activeTheme) {
Expand All @@ -90,6 +90,14 @@ frontendControllers = {
return next(e);
});
},
'post': function (req, res, next) {
req.params.page = 0;
return frontendControllers.single(req, res, next);
},
'page': function (req, res, next) {
req.params.page = 1;
return frontendControllers.single(req, res, next);
},
'rss': function (req, res, next) {
// Initialize RSS
var siteUrl = config().url,
Expand Down
6 changes: 5 additions & 1 deletion core/server/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ coreHelpers.url = function (options) {
output += path;
}
if (models.isPost(self)) {
output += permalinks.value;
if (self.page === 1) {
output += '/:slug/';
} else {
output += permalinks.value;
}
output = output.replace(/(:[a-z]+)/g, function (match) {
if (_.has(tags, match.substr(1))) {
return tags[match.substr(1)]();
Expand Down
7 changes: 6 additions & 1 deletion core/server/routes/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module.exports = function (server) {
server.get('/', frontend.homepage);

api.settings.read('permalinks').then(function (permalinks) {
server.get(permalinks.value, frontend.single);
if (permalinks.value !== '/:slug/') {
server.get('/:slug/', frontend.page);
server.get(permalinks.value, frontend.post);
} else {
server.get(permalinks.value, frontend.single);
}
});
};

0 comments on commit 075dd8a

Please sign in to comment.