Last active
August 29, 2015 13:57
-
-
Save davidblurton/9440434 to your computer and use it in GitHub Desktop.
I wanted the index page to be a static page (which you can write in the Ghost editor) rather than the list of posts (which you can only edit by changing the template). Hacked the router so the index page redirects to a static page at /index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var frontend = require('../controllers/frontend'); | |
module.exports = function (server) { | |
/*jslint regexp: true */ | |
// ### Frontend routes | |
server.get('/rss/', frontend.rss); | |
server.get('/rss/:page/', frontend.rss); | |
server.get('/page/:page/', frontend.homepage); | |
server.get('/blog/', frontend.homepage); | |
// Only capture the :slug part of the URL | |
// This regex will always have two capturing groups, | |
// one for date, and one for the slug. | |
// Examples: | |
// Given `/plain-slug/` the req.params would be [undefined, 'plain-slug'] | |
// Given `/2012/12/24/plain-slug/` the req.params would be ['2012/12/24/', 'plain-slug'] | |
// Given `/plain-slug/edit/` the req.params would be [undefined, 'plain-slug', 'edit'] | |
server.get(/^\/([0-9]{4}\/[0-9]{2}\/[0-9]{2}\/)?([^\/.]*)\/$/, frontend.single); | |
server.get(/^\/([0-9]{4}\/[0-9]{2}\/[0-9]{2}\/)?([^\/.]*)\/edit\/$/, frontend.edit); | |
server.get('/', function(req, res) { | |
req.params[1] = 'index'; | |
return frontend.single(req, res); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment