Skip to content
Snippets Groups Projects
Commit 32fcb749 authored by Jean-Matthieu BARBIER's avatar Jean-Matthieu BARBIER
Browse files

Merge branch 'release/0.0.0'

parents 5e9f435c 6e2f250f
Branches
Tags 0.0.0
No related merge requests found
node_modules
{
"name": "stevenson",
"version": "0.0.0",
"description": "Static Website Generator",
"main": "index.coffee",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"website",
"static",
"generator",
"pandoc",
"nodejs",
"jekyll"
],
"author": "BARBIER Jean-Matthieu",
"license": "MIT",
"dependencies": {
"async": "^0.9.0",
"jade": "^1.5.0",
"js-yaml": "^3.2.1",
"mkdirp": "^0.5.0",
"readdirp": "^1.1.0",
"rimraf": "^2.2.8",
"swig": "^1.4.2"
}
}
readdirp = require 'readdirp'
path = require 'path'
fs = require 'fs'
rimraf = require 'rimraf'
yaml = require 'js-yaml'
spawn = require('child_process').spawn
mkdirp = require "mkdirp"
swig = require "swig"
async = require "async"
# GET ROOT DIRECTORY
ROOT = process.cwd()
# GET CONFIG
META = {
site:
files: {}
config: yaml.load fs.readFileSync path.join ROOT, "_config.yml"
root: ROOT
}
# REMOVE OLD SITE ? update it ?
clean = (cb) ->
async.parallel [
(cb) ->
rimraf path.join(META.root, "_site"), cb
(cb) ->
rimraf path.join(META.root, "_tmp"), cb
], cb
# READS FILE METADATA
metadatize = (file) ->
buf = new Buffer(8192)
f = fs.openSync(file.fullPath, "r")
fs.readSync(f, buf , 0, 8192)
fs.closeSync(f)
if buf.toString('utf-8', 0,3)=="---"
re = /^(-{3}(?:\n|\r)([\w\W]+?)-{3})?([\w\W]*)*/
results = re.exec(buf.toString('utf-8'))
file.data = yaml.load(results[2])
if not file.data.process?
file.data.process = true
if not file.data.copy?
file.data.copy = false
else
file.data = {}
file.data.copy = true
file.data.process = false
# Copy file if data.copy is true
store = (file, cb) ->
if not file.data.copy
return cb(null)
destdir = path.join(ROOT, "_site", file.parentDir)
dest = path.join(destdir, file.name)
mkdirp destdir, {}, (err, made) ->
if err
return cb(err)
fs.createReadStream(file.fullPath)
.pipe(fs.createWriteStream(dest))
.on("close", cb)
# Pandocs a file, storing it in _tmp
pandocize = (file, cb) ->
if not file.data.process
return cb(null)
console.log "PANDOC", file.name
destdir = path.join(ROOT, "_tmp", file.parentDir)
dest = path.join(destdir, file.name+'.html')
mkdirp destdir, {}, (err, made) ->
if err
return cb("Unable to create %{destdir}", made)
pdoc = spawn("pandoc", [
"-o"
dest
file.fullPath
])
pdoc.stdout.on 'data', (data) ->
console.log 'stdout: ', data.toString()
pdoc.stderr.on 'data', (data) ->
console.log 'stderr: ', data.toString()
pdoc.on 'close', (code) ->
cb(null, code)
templatize = (file, site, cb) ->
if not file.data.process
return cb(null)
console.log "TEMPLATIZE", file.name
template = (file.data.template || site.template || "default")+".html"
srcdir = path.join(ROOT, "_tmp", file.parentDir)
src = path.join(srcdir, file.name+'.html')
destdir = path.join(ROOT, "_site", file.parentDir)
dest = path.join(
destdir
path.basename(file.name, path.extname(file.name))+'.html'
)
data = {
page: file
site: site
filename: src
}
mkdirp destdir, {}, (err, made) ->
if err
cb("Unable to create %{destdir}", made)
else
data.page.contents = swig.renderFile src, data
fs.writeFileSync(
dest
swig.renderFile path.join(ROOT, "_templates", template), data
)
# GET ALL FILES
getfiles = (cb) ->
# RECURSE IN EVERY FILE
filestream = readdirp {
root: path.join(ROOT)
fileFilter: ["!_*", "!.*"]
directoryFilter: ["!_*", "!.*"]
depth: 8
entryType: 'both'
}, cb
## TODO: Use async.audo
async.auto
config: (cb) ->
cb(
null
yaml.load(fs.readFileSync(path.join(ROOT, "_config.yml")))
)
clean: [ "config", (cb, data) ->
clean(cb)
]
files: ["config", (cb, data) ->
getfiles (err, files) ->
data.config.files = files
cb(null, files)
]
metadata: ["files", (cb, data) ->
for file in data.files.files
metadatize(file)
cb(null)
]
copy: ["clean", "files", "metadata", (cb2, data) ->
async.eachLimit(data.files.files, 10, (f, cb) ->
store(f, cb)
, cb2)
]
pandoc: ["clean", "files", "metadata", (cb2, data) ->
async.eachLimit(data.files.files, 10, (f, cb) ->
pandocize(f, cb)
, cb2)
]
templatize: ["pandoc", (cb2, data) ->
data.config.files = data.files
async.eachLimit(data.files.files, 10, (f, cb) ->
templatize(f, data.config, cb)
, cb2)
]
, (err) ->
console.log "EUUUH", err
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment