Skip to content

Commit

Permalink
Replaced Redoculous with Asciidoc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 28, 2015
1 parent 7f923e4 commit d29d072
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -30,7 +30,8 @@
"feed" : "0.2.6",
"moment": "2.10.3",
"node-cache": "3.0.0",
"cheerio" : "0.19.0"
"cheerio" : "0.19.0",
"asciidoctor.js" : "1.5.2"
},
"devDependencies": {},
"bundleDependencies": [],
Expand Down
33 changes: 31 additions & 2 deletions server.js
Expand Up @@ -10,7 +10,9 @@ var cc = require('config-multipaas'),
Feed = require('feed'),
exec = require('child_process').exec,
moment = require('moment'),
cheerio = require('cheerio');
cheerio = require('cheerio'),
asciidoctor = require('asciidoctor.js')();

// Git utilities
var Git =
{
Expand All @@ -33,7 +35,8 @@ var config = cc()
'FORGE_WEBSITE_DATA_DIR': (process.env.OPENSHIFT_TMP_DIR || '/tmp') + '/website-data'
}),
app = restify.createServer(),
cache = new NodeCache({stdTTL: 1000, checkperiod: 120 });
cache = new NodeCache({stdTTL: 1000, checkperiod: 120 }),
processor = asciidoctor.Asciidoctor(true);

app.use(restify.gzipResponse());
app.use(restify.queryParser());
Expand Down Expand Up @@ -338,6 +341,32 @@ function fetchContents(col, id, res){
}

function renderAsciidoc(item, res, _callback) {
if (item.renderedBy == 'redoculous') {
fetchFromRedoculous(item,res,_callback);
} else {
// Using Asciidoctor.js
var urlOptions = {
protocol: 'https:',
host : 'raw.githubusercontent.com',
pathname: item.repo.replace('https://github.com/','').replace('.git','/') + item.ref + item.path
};
//console.log(url.format(urlOptions));
fetchUrl(url.format(urlOptions), function(error, meta, response) {
if (meta.status == 200) {
response = processor.$convert(response.toString());
response = transposeImages(item, response);
if (_callback) {
_callback(response);
} else {
res.write(response);
}
}
res.end();
});
}
}

function fetchFromRedoculous(item, res, _callback) {
// Fetching from Redoculous
var urlOptions = {
protocol: 'http:',
Expand Down

0 comments on commit d29d072

Please sign in to comment.