Last active
August 29, 2015 13:55
-
-
Save ryanflorence/8702265 to your computer and use it in GitHub Desktop.
This file contains 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
// this file is designed to freak you out | |
const fs = require('fs') | |
const path = require('path') | |
const hbs = require('handlebars') | |
const cheerio = require('cheerio') | |
!function main() { | |
return process.stdout.write( | |
template()( | |
templateLocals()))}() | |
function defaultFilesPath() { | |
return 'data'} | |
function filesPath() { | |
return path.resolve( | |
defaultFilesPath())} | |
function filePath(file) { | |
return ''+filesPath()+'/'+file} | |
function makeFileObject(fileName) { | |
return { | |
id: fileName.replace(/\.html$/, ''), | |
content: fs.readFileSync( | |
filePath(fileName)).toString() }} | |
function files() { | |
return fs.readdirSync( | |
filesPath())} | |
function processFile(fileName) { | |
return parseFile( | |
makeFileObject(fileName))} | |
function templatePath() { | |
return path.join(__dirname, 'template.hbs')} | |
function template() { | |
return hbs.compile( | |
fs.readFileSync( | |
templatePath()).toString())} | |
function parseFile(fileObject) { | |
return templateFileObject( | |
cheerio.load( | |
fileObject.content))} | |
function templateFileObject($) { | |
return { | |
name: $('title').html(), | |
id: fileObject.id, | |
introduction: $('introduction').html(), | |
textIntroduction: $('introduction').text().trim().replace(/\s+/g, ' '), | |
incorrect: { | |
description: $('incorrect description').html(), | |
demo: $('incorrect demo').html().trim(), | |
}, | |
correct: { | |
description: $('correct description').html(), | |
demo: $('correct demo').html().trim() }}} | |
function readCss() { | |
return fs.readFileSync( | |
path.resolve(__dirname, 'styles.css')).toString()} | |
function templateLocals() { | |
return { | |
files: files().sort().map(processFile), | |
css: readCss()}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment