changed from markdown to textile renderer
This commit is contained in:
parent
62d9bee9bf
commit
cd66f791fa
90
db.js
90
db.js
@ -1,29 +1,93 @@
|
|||||||
var FS = require('fs');
|
var FS = require('fs');
|
||||||
var Path = require('path');
|
var Path = require('path');
|
||||||
var Markdown = require("marked");
|
//var Markdown = require("marked");
|
||||||
//var MdRenderer=require("./md-override")
|
//var MdRenderer=require("./md-override")
|
||||||
var knex = require("knex");
|
var knex = require("knex");
|
||||||
var Bookshelf = require('bookshelf');
|
var Bookshelf = require('bookshelf');
|
||||||
|
var async = require('async');
|
||||||
|
var textile = require('textile-js')
|
||||||
|
|
||||||
|
|
||||||
Markdown.setOptions({
|
var Markdown = textile //Markdown = require('js-markdown-extra').Markdown
|
||||||
renderer: new Markdown.Renderer(),
|
|
||||||
gfm: true,
|
function orderize(files){
|
||||||
tables: true,
|
var pageObjs = []
|
||||||
sanitize: false
|
for (var i = 0; i<files.length; i++){
|
||||||
|
var file = files[i].name
|
||||||
|
var order = parseInt(file.split("_")[0])
|
||||||
|
if(!isNaN(order)) {
|
||||||
|
var divId = file.split("_")[1].split(".markdown")[0]
|
||||||
|
var md = files[i].markdown
|
||||||
|
var html = files[i].html
|
||||||
|
pageObjs.push ({name: file.split(".markdown")[0], order:order, divId:divId, markdown:md, html:html })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pageObjs.sort(function(a,b){ return a.order - b.order });
|
||||||
|
}
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
// This function is used to map wiki page names to files
|
// This function is used to map wiki page names to files
|
||||||
// on the real filesystem.
|
// on the real filesystem.
|
||||||
function pathFromName(name) {
|
function pathFromNameMd(name) {
|
||||||
return Path.join(__dirname, "pages", name + ".markdown");
|
return Path.join(__dirname, "pages", name + ".markdown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pathFromName(name) {
|
||||||
|
return Path.join(__dirname, "pages", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function pathFromDir() {
|
||||||
|
return Path.join(__dirname, "pages");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function fullPath(files) {
|
||||||
|
var paths = []
|
||||||
|
for (var i= 0; i < files.length; i++)
|
||||||
|
paths.push(pathFromName(files[i]))
|
||||||
|
|
||||||
|
return paths
|
||||||
|
}
|
||||||
|
|
||||||
// Load a file, parse the title and generate the HTML
|
// Load a file, parse the title and generate the HTML
|
||||||
exports.loadPage = function (name, callback) {
|
exports.loadPage = function (name, callback) {
|
||||||
var path = pathFromName(name);
|
var path = pathFromNameMd(name);
|
||||||
|
console.log("..."+name)
|
||||||
|
if (name != "home"){
|
||||||
|
return callback(null,{exists: false})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FS.readdir(pathFromDir(), function(err,files){
|
||||||
|
var pathfiles=fullPath(files)
|
||||||
|
var fileObj = []
|
||||||
|
async.map(pathfiles, FS.readFile, function(err, data){
|
||||||
|
for( var i = 0; i < files.length; i++){
|
||||||
|
console.log(files[i])
|
||||||
|
try{
|
||||||
|
var html = Markdown(data[i].toString())
|
||||||
|
console.log(html)
|
||||||
|
fileObj.push({name : files[i], markdown:data[i], html:html} )
|
||||||
|
}
|
||||||
|
catch (err){ }
|
||||||
|
|
||||||
|
}
|
||||||
|
var torender = orderize(fileObj)
|
||||||
|
callback(null,{exists:true, torender:torender})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.editPage = function (name, callback) {
|
||||||
|
var path = pathFromNameMd(name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FS.readFile(path, 'utf8', function (err, markdown) {
|
FS.readFile(path, 'utf8', function (err, markdown) {
|
||||||
|
|
||||||
var exists = true;
|
var exists = true;
|
||||||
@ -49,7 +113,8 @@ exports.loadPage = function (name, callback) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
var html = Markdown(markdown);
|
|
||||||
|
var html = Markdown(markdown);
|
||||||
|
|
||||||
callback(null, {
|
callback(null, {
|
||||||
name: name,
|
name: name,
|
||||||
@ -58,13 +123,14 @@ exports.loadPage = function (name, callback) {
|
|||||||
markdown: markdown,
|
markdown: markdown,
|
||||||
html: html,
|
html: html,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Saving is simple. Just put the markdown in the file
|
// Saving is simple. Just put the markdown in the file
|
||||||
exports.savePage = function (name, value, callback) {
|
exports.savePage = function (name, value, callback) {
|
||||||
var path = pathFromName(name);
|
var path = pathFromNameMd(name);
|
||||||
FS.writeFile(path, value, callback);
|
FS.writeFile(path, value, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"async": "^0.9.0",
|
||||||
"bcrypt-nodejs": "0.0.3",
|
"bcrypt-nodejs": "0.0.3",
|
||||||
"body-parser": "^1.12.2",
|
"body-parser": "^1.12.2",
|
||||||
"bookshelf": "^0.7.9",
|
"bookshelf": "^0.7.9",
|
||||||
@ -13,10 +14,11 @@
|
|||||||
"knex": "^0.7.6",
|
"knex": "^0.7.6",
|
||||||
"markdown": "~0.3.1",
|
"markdown": "~0.3.1",
|
||||||
"marked": "^0.3.3",
|
"marked": "^0.3.3",
|
||||||
"multimarkdown": "0.0.15",
|
|
||||||
"namp": "^0.2.25",
|
"namp": "^0.2.25",
|
||||||
|
"passport": "^0.2.1",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"showdown": "^0.4.0",
|
"showdown": "^0.4.0",
|
||||||
|
"sqlite3": "^3.0.5",
|
||||||
"trycatch": "~0.0.9"
|
"trycatch": "~0.0.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
pages/01_home.markdown
Normal file
8
pages/01_home.markdown
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
h3. Hello THSF
|
||||||
|
|
||||||
|
p(bla). this is a simple and stupid wiki :)
|
||||||
|
|
||||||
|
p(test). it wil blaaa
|
||||||
|
|
||||||
|
!http://stuffpoint.com/lol-cats/image/29077-lol-cats-magical-kitteh.png!
|
||||||
|
|
6
pages/02_zoor.markdown
Normal file
6
pages/02_zoor.markdown
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
h3. zoor
|
||||||
|
|
||||||
|
|_. Tables |_. Are |_. Cool |
|
||||||
|
| col 3 is | p(heay). right-aligned | $1600 |
|
||||||
|
| col 2 is | centered | $12 |
|
||||||
|
| zebra stripes | are neat | $1 |
|
3
pages/03_test.markdown
Normal file
3
pages/03_test.markdown
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
h3. 03 test
|
||||||
|
|
||||||
|
render me that
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
###Hello THSF
|
|
||||||
this is a simple and stupid wiki :)
|
|
||||||
|
|
||||||
![](http://stuffpoint.com/lol-cats/image/29077-lol-cats-magical-kitteh.png)
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
# zoor
|
|
||||||
|
|
||||||
| Tables | Are | Cool |
|
|
||||||
| ------------- |:-------------:| -----:|
|
|
||||||
| col 3 is | right-aligned | $1600 |
|
|
||||||
| col 2 is | centered | $12 |
|
|
||||||
| zebra stripes | are neat | $1 |
|
|
@ -12,6 +12,11 @@ exports.index = function(req, res) {
|
|||||||
exports.view = function (req, res, next) {
|
exports.view = function (req, res, next) {
|
||||||
DB.loadPage(req.params.name, function (err, page) {
|
DB.loadPage(req.params.name, function (err, page) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
if (page.exists==false && !req.isAuthenticated())
|
||||||
|
res.redirect('/')
|
||||||
|
if (page.exists==false && req.isAuthenticated())
|
||||||
|
res.redirect('/'+req.params.name+"/edit")
|
||||||
|
page['isAuth']=req.isAuthenticated()
|
||||||
res.render('view', page);
|
res.render('view', page);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -23,7 +28,7 @@ exports.edit = function (req, res, next) {
|
|||||||
res.redirect('/signin');
|
res.redirect('/signin');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
DB.loadPage(req.params.name, function (err, page) {
|
DB.editPage(req.params.name, function (err, page) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
res.render('edit', page);
|
res.render('edit', page);
|
||||||
});
|
});
|
||||||
@ -38,7 +43,8 @@ exports.save = function (req, res, next) {
|
|||||||
else {
|
else {
|
||||||
DB.savePage(req.params.name, req.body.markdown, function (err) {
|
DB.savePage(req.params.name, req.body.markdown, function (err) {
|
||||||
if (err) return next(err)
|
if (err) return next(err)
|
||||||
res.redirect("/" + req.params.name);
|
//res.redirect("/" + req.params.name);
|
||||||
|
res.redirect("/home");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@ html
|
|||||||
div.container-fluid
|
div.container-fluid
|
||||||
ul.nav.nav-pills
|
ul.nav.nav-pills
|
||||||
li(role="presentation" )
|
li(role="presentation" )
|
||||||
a(href="#") one
|
a(href="#home") THSF
|
||||||
li(role="presentation")
|
li(role="presentation")
|
||||||
a(href="#") two
|
a(href="#presentation") presentation
|
||||||
li(role="presentation" )
|
li(role="presentation" )
|
||||||
a(href="#") three
|
a(href="#programme") preogramme
|
||||||
|
|
||||||
block body
|
block body
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
include ./layout.jade
|
include ./layout.jade
|
||||||
.container-fluid
|
.container-fluid
|
||||||
h1= title
|
each item in torender
|
||||||
|
div(id= item.divId)!= item.html
|
||||||
.document!= html
|
if isAuth
|
||||||
a(href="/" + name + "/edit")= "Edit this Page"
|
a(href="/" + item.name + "/edit")= "Edit this Page"
|
||||||
|
Loading…
Reference in New Issue
Block a user