Last active
August 29, 2015 14:13
-
-
Save lasar/41ac6541a50b92cf6531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jade = require('jade'); | |
var marked = require('marked'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var async = require('async'); | |
var front = require('front-matter'); | |
var moment = require('moment'); | |
var exec = require('child_process').exec; | |
var config = require('./config'); | |
var files, data = []; | |
async.series([ | |
getSourceFiles, | |
parseFiles, | |
sortFiles, | |
clearOut, | |
copyStatic, | |
generateIndex, | |
debug | |
], function(err) { | |
if(err) { | |
console.log('ERROR', err); | |
} | |
console.log('DONE'); | |
}) | |
function getSourceFiles(cb) { | |
fs.readdir(config.src, function(err, _files) { | |
files = _files; | |
cb(err); | |
}); | |
} | |
function parseFiles(cb) { | |
async.each(files, function(file, cb2) { | |
var filePath = path.join(config.src, file); | |
fs.readFile(filePath, {encoding: 'utf8'}, function(err, text) { | |
var contents = front(text); | |
contents.path = filePath; | |
contents.html = marked(contents.body); | |
if(!contents.attributes.draft) { | |
data.push(contents); | |
} | |
cb2(err); | |
}) | |
}, cb); | |
} | |
function sortFiles(cb) { | |
data.sort(function(a, b) { | |
return a.path.localeCompare(b.path) | |
}); | |
data = data.reverse(); | |
cb(null); | |
} | |
function clearOut(cb) { | |
exec('/bin/rm -rf '+path.join(config.out, '*'), cb); | |
} | |
function copyStatic(cb) { | |
exec('rsync -r '+path.join(config.static)+'/ '+config.out, cb); | |
} | |
function generateIndex(cb) { | |
var html = jade.renderFile(config.indexTpl, { | |
data: data, | |
moment: moment | |
}); | |
fs.writeFile(path.join(config.out, 'index.html'), html, cb); | |
} | |
function debug(cb) { | |
// console.log(data); | |
// for(var f in data) { console.log(data[f].path); } | |
cb(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
module.exports = { | |
src: path.join(__dirname, 'src'), | |
static: path.join(__dirname, 'static'), | |
out: path.join(__dirname, 'out'), | |
indexTpl: path.join(__dirname, 'tpl', 'index.jade'), | |
publishDestination: 'user@myserver:/var/www/audio.country/' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
out/ | |
src/ | |
myfiles.md | |
static/ | |
img/ | |
assets/ | |
styles.css | |
tpl/ | |
index.jade | |
build.js | |
config.js | |
package.json | |
publish.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "audio.country", | |
"version": "1.0.0", | |
"description": "", | |
"dependencies": { | |
"async": "^0.9.0", | |
"front-matter": "^0.2.1", | |
"jade": "^1.9.0", | |
"marked": "^0.3.2", | |
"moment": "^2.9.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var async = require('async'); | |
var exec = require('child_process').exec; | |
var config = require('./config'); | |
async.series([ | |
upload, | |
debug | |
], function(err) { | |
if(err) { | |
console.log('ERROR', err); | |
} | |
console.log('DONE'); | |
}) | |
function upload(cb) { | |
var cmd = [ | |
'rsync', | |
'-ar', | |
'--delete', | |
config.out+'/', | |
config.publishDestination | |
]; | |
console.log(cmd.join(' ')); | |
exec(cmd.join(' '), cb); | |
} | |
function debug(cb) { | |
// console.log(data); | |
// for(var f in data) { console.log(data[f].path); } | |
cb(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
draft: true | |
number: "TODO" | |
date: TODO | |
img: TODO.jpg | |
artist: TODO | |
album: TODO | |
adn: TODO | |
--- | |
Markdown content goes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment