2015-03-30 13:48:54 -07:00
|
|
|
var _ = require('lodash'),
|
|
|
|
debug = require('debug')('freecc:cntr:wiki'),
|
|
|
|
Wiki = require('./../models/Wiki'),
|
|
|
|
resources = require('./resources'),
|
|
|
|
R = require('ramda');
|
|
|
|
|
|
|
|
exports.returnIndividualWiki = function(req, res, next) {
|
|
|
|
var dashedName = req.params.wikiName;
|
|
|
|
|
|
|
|
var wikiName = dashedName.replace(/\-/g, ' ');
|
|
|
|
|
|
|
|
Wiki.find({'name': new RegExp(wikiName, 'i')}, function(err, wiki) {
|
|
|
|
if (err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wiki.length < 1) {
|
|
|
|
req.flash('errors', {
|
|
|
|
msg: "404: We couldn't find a wiki entry with that name. Please double check the name."
|
|
|
|
});
|
|
|
|
|
|
|
|
return res.redirect('/wiki');
|
|
|
|
}
|
|
|
|
|
|
|
|
wiki = wiki.pop();
|
2015-03-30 18:02:50 -07:00
|
|
|
var dashedNameFull = wiki.name.toLowerCase().replace(/\s/g, '-').replace(/\?/g, '');
|
2015-03-30 13:48:54 -07:00
|
|
|
if (dashedNameFull != dashedName) {
|
|
|
|
return res.redirect('../wiki/' + dashedNameFull);
|
|
|
|
}
|
|
|
|
res.render('wiki/show', {
|
|
|
|
title: wiki.name,
|
|
|
|
description: wiki.description.join('')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.showAllWikis = function(req, res) {
|
2015-03-30 15:55:00 -07:00
|
|
|
var data = {};
|
2015-03-30 13:48:54 -07:00
|
|
|
data.wikiList = resources.allWikiNames();
|
|
|
|
res.send(data);
|
|
|
|
};
|
2015-03-30 18:02:50 -07:00
|
|
|
|
|
|
|
exports.returnHomeWiki = function(req, res) {
|
|
|
|
var dashedName = req.params.wikiName;
|
|
|
|
|
|
|
|
Wiki.find({'name': 'A Guide to our Wiki'}, function(err, wiki) {
|
|
|
|
if (err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wiki.length < 1) {
|
|
|
|
req.flash('errors', {
|
|
|
|
msg: "404: We couldn't find a wiki entry with that name. Please double check the name."
|
|
|
|
});
|
|
|
|
|
|
|
|
return res.redirect('/wiki');
|
|
|
|
}
|
|
|
|
|
|
|
|
wiki = wiki.pop();
|
|
|
|
var dashedNameFull = wiki.name.toLowerCase().replace(/\s/g, '-');
|
|
|
|
if (dashedNameFull != dashedName) {
|
|
|
|
return res.redirect('../wiki/' + dashedNameFull);
|
|
|
|
}
|
|
|
|
res.render('wiki/show', {
|
|
|
|
title: wiki.name,
|
|
|
|
description: wiki.description.join('')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|