QWiki can now be required as a module. If run directly, an instance of QWiki is created and started, as per before.
parent
2144e6d877
commit
7501ca4e41
84
index.js
84
index.js
|
|
@ -165,47 +165,49 @@ QWiki.prototype.savePage = function(wiki_page, content, cb) {
|
|||
QWiki.prototype.deleteFile = function(file, cb) {
|
||||
fs.unlink('wiki/'+file, cb);
|
||||
};
|
||||
/*********************************
|
||||
* qwiki instance *
|
||||
*********************************/
|
||||
var qwiki = new QWiki();
|
||||
|
||||
qwiki.addMIMEtype('png', 'image/png');
|
||||
qwiki.addMIMEtype('jpg', 'image/jpg');
|
||||
qwiki.addMIMEtype('svg', 'image/svg+xml');
|
||||
qwiki.addMIMEtype('css', 'text/css');
|
||||
|
||||
var m_markdownit = require('markdown-it')({
|
||||
typographer: true
|
||||
});
|
||||
m_markdownit.use(require('markdown-it-anchor'));
|
||||
m_markdownit.use(require('markdown-it-table-of-contents'), {includeLevel: "2-8"});
|
||||
m_markdownit.use(require('markdown-it-deflist'));
|
||||
m_markdownit.use(require('markdown-it-header-sections'));
|
||||
m_markdownit.use(require('markdown-it-sup'));
|
||||
qwiki.addFormat('md', 'Markdown', function(source) {
|
||||
// source is a Buffer, but render seems to need a String
|
||||
return m_markdownit.render(source.toString());
|
||||
});
|
||||
|
||||
qwiki.setDefault('format', 'md');
|
||||
|
||||
var port = 8080;
|
||||
process.argv.forEach(function (val, index, array) {
|
||||
var parts = val.split('=');
|
||||
var key = '';
|
||||
var value = '';
|
||||
if (parts[0].substr(0, 2) == '--') {
|
||||
key = parts[0].substr(2);
|
||||
value = parts[1];
|
||||
}
|
||||
if (key == 'port') {
|
||||
if (value == '') {
|
||||
console.log(key + ' needs a value');
|
||||
} else {
|
||||
port = Number(value);
|
||||
if (require.main === module) {
|
||||
var port = 8080;
|
||||
process.argv.forEach(function (val, index, array) {
|
||||
var parts = val.split('=');
|
||||
var key = '';
|
||||
var value = '';
|
||||
if (parts[0].substr(0, 2) == '--') {
|
||||
key = parts[0].substr(2);
|
||||
value = parts[1];
|
||||
}
|
||||
}
|
||||
});
|
||||
if (key == 'port') {
|
||||
if (value == '') {
|
||||
console.log(key + ' needs a value');
|
||||
} else {
|
||||
port = Number(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
qwiki.listen(port, function() { qwiki.loadWikiIndex(); });
|
||||
var qwiki = new QWiki();
|
||||
|
||||
qwiki.addMIMEtype('png', 'image/png');
|
||||
qwiki.addMIMEtype('jpg', 'image/jpg');
|
||||
qwiki.addMIMEtype('svg', 'image/svg+xml');
|
||||
qwiki.addMIMEtype('css', 'text/css');
|
||||
|
||||
var m_markdownit = require('markdown-it')({
|
||||
typographer: true
|
||||
});
|
||||
m_markdownit.use(require('markdown-it-anchor'));
|
||||
m_markdownit.use(require('markdown-it-table-of-contents'), {includeLevel: "2-8"});
|
||||
m_markdownit.use(require('markdown-it-deflist'));
|
||||
m_markdownit.use(require('markdown-it-header-sections'));
|
||||
m_markdownit.use(require('markdown-it-sup'));
|
||||
qwiki.addFormat('md', 'Markdown', function(source) {
|
||||
// source is a Buffer, but render seems to need a String
|
||||
return m_markdownit.render(source.toString());
|
||||
});
|
||||
|
||||
qwiki.setDefault('format', 'md');
|
||||
|
||||
qwiki.listen(port, function() { qwiki.loadWikiIndex(); });
|
||||
}
|
||||
|
||||
module.exports = QWiki;
|
||||
|
|
|
|||
Loading…
Reference in New Issue