Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (47 loc) · 1.92 KB
/
Copy pathindex.js
File metadata and controls
52 lines (47 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var swig = require('swig')
var fs = require('fs')
var execSync = require('child_process').execSync
var joinPath = require('path').join
var relativePath = p => joinPath(__dirname, p)
var printLine = character => console.log(new Array(42).join(character))
var markdown = require('markdown').markdown
var write = (path, str) => fs.writeFileSync(path, new Buffer(str))
printLine('.')
console.log('loading config...')
var config = require('./config.js')
console.log('generating project pages...')
var projectPageTemplateFile = joinPath(__dirname, 'templates', 'project.html')
function buildProjectPage (project) {
process.stdout.write(project.title)
var projectPath = relativePath(project.url)
// (destructively) make a path in dist/
var distProjectPath = joinPath(__dirname, 'dist', project.url)
execSync(`mkdir -p ${distProjectPath}`)
// copy assets
var projectAssetsPath = joinPath(projectPath, 'assets')
execSync(`cp -rf ${projectAssetsPath} ${distProjectPath}`)
// generate html from project's index.md
var indexMdPath = joinPath(projectPath, 'index.md')
var indexMd = fs.readFileSync(indexMdPath).toString()
var indexHTML = markdown.toHTML(indexMd)
// put in project template
project.html = indexHTML
var template = swig.compileFile(projectPageTemplateFile)
var output = template(project)
// write index html to the new path
var indexHTMLPath = joinPath(distProjectPath, 'index.html')
write(indexHTMLPath, output)
process.stdout.write('.....done!\n')
}
config.projects.map(buildProjectPage)
console.log('bundling template files...')
execSync('bundledown templates/index.html -o bundled.html')
var templateFile = relativePath('bundled.html')
var template = swig.compileFile(templateFile)
var output = template(config)
console.log('outputting index.html..')
var outputFile = relativePath('dist/index.html')
write(outputFile, output)
console.log('lab site generated! cleaning up..')
execSync('rm bundled.html')
printLine('.')