From 075dd8ac9bd3a7b203629c53f3e8a3dc55d34ad6 Mon Sep 17 00:00:00 2001 From: Mark Berger Date: Fri, 27 Dec 2013 18:21:43 -0500 Subject: [PATCH] Static pages do not use dated permalinks closes #1753 - Pages are registered to '/:slug/' route if posts are using dated permalinks --- core/server/controllers/frontend.js | 10 +++++++++- core/server/helpers/index.js | 6 +++++- core/server/routes/frontend.js | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/server/controllers/frontend.js b/core/server/controllers/frontend.js index 6cc733f7b0..8aacc1f9da 100644 --- a/core/server/controllers/frontend.js +++ b/core/server/controllers/frontend.js @@ -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) { @@ -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, diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index e1bc07d91c..ff9a0e2c27 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -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)](); diff --git a/core/server/routes/frontend.js b/core/server/routes/frontend.js index 707a353798..7274fa38bc 100644 --- a/core/server/routes/frontend.js +++ b/core/server/routes/frontend.js @@ -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); + } }); };