Created
September 30, 2013 22:09
-
-
Save tivac/6771048 to your computer and use it in GitHub Desktop.
Experimenting with substack's node-trumpet project
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
/*jshint node:true */ | |
"use strict"; | |
var fs = require("fs"), | |
path = require("path"), | |
trumpet = require("trumpet"), | |
Uri = require("jsuri"), | |
tr = trumpet(); | |
tr.pipe(process.stdout); | |
tr.selectAll("script", function(script) { | |
script.getAttribute("src", function(src) { | |
var url = new Uri(src), | |
host = url.host(), | |
file = path.join(__dirname, "test", "specimens", url.path()); | |
// we only want relative uris | |
if(host || !fs.existsSync(file) || fs.statSync(file).size > 1024) { | |
return; | |
} | |
script.removeAttribute("src"); | |
script | |
.createWriteStream() | |
.end(fs.readFileSync(file, { encoding : "utf8" })); | |
}); | |
}); | |
fs.createReadStream(__dirname + "/test/specimens/test.ejs").pipe(tr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment