Fix article loading on direct link to wiki

This commit is contained in:
Berkeley Martinez
2016-03-25 13:48:42 -07:00
parent 87ef97f59e
commit 94a9bcea5a
2 changed files with 15 additions and 5 deletions

View File

@ -1,11 +1,17 @@
module.exports = function(app) {
var router = app.loopback.Router();
router.get('/wiki/*', showWiki);
router.get('/wiki', showWiki);
router.get('/wiki', (req, res) => res.redirect(301, '/wiki/en/'));
app.use(router);
function showWiki(req, res) {
res.render('wiki/show', { title: 'Wiki | Free Code Camp' });
res.render(
'wiki/show',
{
title: 'Wiki | Free Code Camp',
path: req.path.replace(/^\/wiki/, '')
}
);
}
};

View File

@ -2,6 +2,10 @@ extends ../layout-wide
block content
iframe#wikiFrame(frameborder='no')
script.
var lang = window.location.toString().match(/\/\w{2}\//);
lang = (lang) ? lang[0] : '/en/';
$('#wikiFrame').attr('src','//freecodecamp.github.io/wiki' + lang);
var requestedPath = !{JSON.stringify(path) || ''};
var lang = window.location.toString().match(/\/\w{2}\//);
lang = (lang) ? lang[0] : '/en/';
$('#wikiFrame').attr(
'src',
'//freecodecamp.github.io/wiki' + (requestedPath ? requestedPath : lang)
);