code convention
This commit is contained in:
+12
-9
@@ -45,19 +45,22 @@ module.exports = (config) => {
|
||||
|
||||
const showError = (resPath, code, res) => {
|
||||
const errorPath = path.join(config['data_dir'],config['home']['error']);
|
||||
if (fs.existsSync(errorPath))
|
||||
render(res, errorPath, {error: code, path: resPath}, code);
|
||||
else
|
||||
res.sendStatus(code);
|
||||
fs.access(errorPath, (err) => {
|
||||
if(err)
|
||||
res.sendStatus(code);
|
||||
else
|
||||
render(res, errorPath, {error: code, path: resPath}, code);
|
||||
});
|
||||
};
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const homePath = `${config['data_dir']}/${config['home']['index']}`;
|
||||
if (fs.existsSync(homePath))
|
||||
render(res, homePath, {articles: articles});
|
||||
else {
|
||||
showError(req.path, 404, res);
|
||||
}
|
||||
fs.access(homePath,(err)=>{
|
||||
if(err)
|
||||
showError(req.path, 404, res);
|
||||
else
|
||||
render(res, homePath, {articles: articles});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('*', express.static(config['data_dir']));
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ const merge = (ref, src) => {
|
||||
return ref;
|
||||
} else if (typeof ref === 'object') {
|
||||
const out = {};
|
||||
Object.keys(ref).forEach(key => out[key] = merge(ref[key], src[key]));
|
||||
Object.keys(ref).forEach((key) =>out[key] = merge(ref[key], src[key]));
|
||||
return out;
|
||||
} else {
|
||||
return src;
|
||||
|
||||
+6
-6
@@ -54,16 +54,16 @@ module.exports = (config) => {
|
||||
if (err)
|
||||
return cb(err);
|
||||
const paths = fileList
|
||||
.map(path => path.substr(config['data_dir'].length))
|
||||
.filter(path => path.indexOf(config['article']['index']) === path.length - config['article']['index'].length)
|
||||
.map(path => path.substr(0, path.length - config['article']['index'].length))
|
||||
.map(path => path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
||||
.filter(matches => matches && matches.length > 1);
|
||||
.map((path) =>path.substr(config['data_dir'].length))
|
||||
.filter((path) =>path.indexOf(config['article']['index']) === path.length - config['article']['index'].length)
|
||||
.map((path) =>path.substr(0, path.length - config['article']['index'].length))
|
||||
.map((path) =>path.match(/^\/(\d{4})\/(\d{2})\/(\d{2})\/$/))
|
||||
.filter((matches) =>matches && matches.length > 1);
|
||||
if (paths.length === 0)
|
||||
cb(null, []);
|
||||
const list = [];
|
||||
let remaining = 0;
|
||||
paths.forEach(matches => {
|
||||
paths.forEach((matches) =>{
|
||||
const article = {
|
||||
path: path.join(config['data_dir'], matches[1], matches[2], matches[3], config['article']['index']),
|
||||
parent: path.join(config['data_dir'], matches[1], matches[2], matches[3]),
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ if (!fs.existsSync('data')) {
|
||||
|
||||
copy(path.join('sample_data','home'), 'data');
|
||||
|
||||
const pad0 = n => ('0' + n).substr(-2);
|
||||
const pad0 = (n) =>('0' + n).substr(-2);
|
||||
|
||||
const datetime = new Date();
|
||||
const dir = path.join('data', datetime.getFullYear().toString(), pad0(datetime.getMonth() + 1), pad0(datetime.getDate()));
|
||||
|
||||
Reference in New Issue
Block a user