# We can require stylus files for our stylesheet styleElement = document.createElement "style" styleElement.textContent = require "./style" document.head.appendChild styleElement script = document.createElement 'script' script.src = "https://danielx.net/cdn/stylus/0.54.5.min.js" document.head.appendChild script # We can require .jadelet files to get templates ItemTemplate = require "./li" buildCSS = -> # Update main.css system.host.readFile("./source/style.styl") .then (blob) -> blob.text() .then (text) -> stylus.render(text) .then (css) -> system.host.writeFile("./main.css", new Blob([css], type: "text/css")) buildJS = -> # Update main.js system.host.readFile("./source/script") .then (blob) -> blob.text() .then (source) -> system.host.compileCoffee(source) .then (js) -> system.host.writeFile("./main.js", new Blob([js], type: "application/javascript")) buildEverything = -> buildCSS() buildJS() templatePromise = system.host.readFile("./source/template.html") .then (blob) -> blob.text() gatherPages("./pages/") .then (pages) -> pages.forEach (page) -> {source, relativePath, title} = page content = marked(source) templatePromise.then (templateHTML) -> pageHTML = simpleTemplate templateHTML, title: title content: content navigation: pages.navigation root: "https://danielx.net/wiki" pageBlob = new Blob([pageHTML], type: "text/html") system.host.writeFile("./#{relativePath}.html", pageBlob) button = document.createElement "button" button.innerText = "Build" button.onclick = buildEverything document.body.appendChild button button = document.createElement "button" button.innerText = "Build CSS" button.onclick = buildCSS document.body.appendChild button # Appendix # gatherPages reads all pages from the file system and updates them with their # content and metadata. # # Page # relativePath # source # title gatherPages = (path) -> system.readTree(path).then (data) -> Promise.all data.map (datum) -> system.readFile(datum.path) .then (blob) -> blob.text() .then (source) -> datum.source = source datum.title = extractTitle source datum.relativePath = extractPath(datum.path) return datum .then (pages) -> pages.navigation = pages.map (page) -> # TODO: Html safety "#{page.title}" .join("") return pages extractPath = (systemPath) -> [..., last] = systemPath.split("/") last.replace(/\.md$/, "") extractTitle = (markdownSource) -> firstNewline = markdownSource.indexOf("\n") if firstNewline > 0 markdownSource.substr(0, firstNewline) else "Untitled" # Replace strings within a template like $something with content from a lookup. simpleTemplate = (template, data) -> template.replace /\$[a-z]+/g, (match) -> data[match.substr(1)] or ""