Skip to content

Instantly share code, notes, and snippets.

@davidefavia
Last active August 29, 2015 14:21
Show Gist options
  • Save davidefavia/f399a98f9263f6badd6e to your computer and use it in GitHub Desktop.
Save davidefavia/f399a98f9263f6badd6e to your computer and use it in GitHub Desktop.
AngularJS snapshots
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_USER_AGENT} googlebot|yahoo|bingbot|baiduspider [NC]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$ /snapshots/index.html [R=302,NC,L]
RewriteCond %{HTTP_USER_AGENT} googlebot|yahoo|bingbot|baiduspider [NC]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=/?(.*)$
RewriteRule ^(.*)$ /snapshots/%1? [R=302,NC,L]
var fs = require("fs");
var minify = require('html-minifier').minify;
var htmlSnapshots = require('html-snapshots');
var url = 'http://www.example.org/';
var result = htmlSnapshots.run({
input: "sitemap",
source: url + "sitemap.xml",
timeout: 10000,
outputDirClean: false,
snapshotScript: {
script: "removeScripts"
},
processLimit : 1,
}, function(err, snapshotsCompleted) {
if (snapshotsCompleted.length) {
return;
snapshotsCompleted.forEach(function(snapshotFile) {
var content = fs.readFileSync(snapshotFile, { encoding: "utf8"});
content = content.split('src="assets').join('src="/assets');
content = minify(content, {
removeComments : true,
collapseWhitespace : true,
conservativeCollapse : true,
collapseBooleanAttributes : true
});
content = '<!-- '+snapshotFile+' -->\n' + content;
fs.writeFileSync(snapshotFile, content);
});
}
});
{
"name": "Snapshots",
"version": "1.0.0",
"description": "HTML snapshots for AngularJS applications",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Davide Favia <[email protected]>",
"license": "None",
"dependencies": {
"html-minifier": "^0.7.2",
"html-snapshots": "^0.8.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment