|
|
|
@ -2,12 +2,13 @@
|
|
|
|
|
|
|
|
|
|
var remark = require('remark');
|
|
|
|
|
var man = require('remark-man');
|
|
|
|
|
var remarkUnlink = require('remark-unlink');
|
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
|
var fsReadFile = Promise.promisify(require('fs').readFile);
|
|
|
|
|
var getArticlePath = require('../lib/util').getArticlePath;
|
|
|
|
|
var fsWriteFile = Promise.promisify(require('fs').writeFile);
|
|
|
|
|
var fsUnlink = Promise.promisify(require('fs').unlink);
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var getArticlePath = require('./util').getArticlePath;
|
|
|
|
|
|
|
|
|
|
var tmpFile = path.resolve('./tmp/tmpfile');
|
|
|
|
|
|
|
|
|
@ -15,19 +16,17 @@ exports.convert = convert;
|
|
|
|
|
exports.getContents = getContents;
|
|
|
|
|
exports.tmpSave = tmpSave;
|
|
|
|
|
exports.removeTmp = removeTmp;
|
|
|
|
|
exports.processMd = processMd;
|
|
|
|
|
|
|
|
|
|
function convert(contents, options) {
|
|
|
|
|
return remark.use(man, options).process(contents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getContents(article) {
|
|
|
|
|
article.path = getArticlePath(article.path);
|
|
|
|
|
return fsReadFile(article.path, 'utf-8').then(function readArticle(contents) {
|
|
|
|
|
return {
|
|
|
|
|
path: getArticlePath(article.path),
|
|
|
|
|
title: article.title,
|
|
|
|
|
description: article.description,
|
|
|
|
|
contents: contents,
|
|
|
|
|
};
|
|
|
|
|
article.contents = contents;
|
|
|
|
|
return article;
|
|
|
|
|
}).catch(function failReadArticle(err) {
|
|
|
|
|
console.log('Can\'t read ' + article.path + '. This should never happen. Try refreshing the database?');
|
|
|
|
|
console.log('Error: ' + err);
|
|
|
|
@ -51,3 +50,8 @@ function removeTmp() {
|
|
|
|
|
console.log('Error: ', + err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function processMd(article) {
|
|
|
|
|
article.contents = remark().use(remarkUnlink).process(article.contents);
|
|
|
|
|
return article;
|
|
|
|
|
}
|
|
|
|
|