mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat(gen-docs): enable caching the whole site
Generate a manifest file automatically by reading the directories.
This commit is contained in:
parent
3af1e7ca2e
commit
e90b741c94
2 changed files with 56 additions and 6 deletions
50
docs/src/appCache.js
Normal file
50
docs/src/appCache.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Generate appCache Manifest file here
|
||||
*/
|
||||
|
||||
exports.appCache = appCache;
|
||||
var fs = require('fs');
|
||||
|
||||
function appCache(path) {
|
||||
var blackList = [ "offline.html",
|
||||
"sitemap.xml",
|
||||
"robots.txt",
|
||||
"docs-scenario.html",
|
||||
"docs-scenario.js",
|
||||
"app-cache.manifest"
|
||||
];
|
||||
|
||||
var result = ["CACHE MANIFEST",
|
||||
"# %TIMESTAMP%",
|
||||
"",
|
||||
"# cache all of these",
|
||||
"CACHE:",
|
||||
"../angular.min.js"];
|
||||
|
||||
var resultPostfix = [ "",
|
||||
"FALLBACK:",
|
||||
"/offline.html",
|
||||
"",
|
||||
"# allow access to google analytics and twitter when we are online",
|
||||
"NETWORK:",
|
||||
"*"];
|
||||
walk(path,result,blackList);
|
||||
return result.join('\n').replace(/%TIMESTAMP%/, (new Date()).toISOString()) + '\n' + resultPostfix.join('\n');
|
||||
}
|
||||
|
||||
function walk(path, array, blackList) {
|
||||
var temp = fs.readdirSync(path);
|
||||
for (var i=0; i< temp.length; i++) {
|
||||
if(blackList.indexOf(temp[i]) < 0) {
|
||||
var currentPath = path + '/' + temp[i];
|
||||
var stat = fs.statSync(currentPath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
walk(currentPath, array, blackList);
|
||||
}
|
||||
else {
|
||||
array.push(currentPath.replace('build/docs/',''));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@ var reader = require('reader.js'),
|
|||
ngdoc = require('ngdoc.js'),
|
||||
writer = require('writer.js'),
|
||||
callback = require('callback.js'),
|
||||
SiteMap = require('SiteMap.js').SiteMap;
|
||||
SiteMap = require('SiteMap.js').SiteMap,
|
||||
appCache = require('appCache.js');
|
||||
|
||||
var docs = [];
|
||||
var start;
|
||||
|
|
@ -31,9 +32,9 @@ var writes = callback.chain(function(){
|
|||
writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', writes.waitFor(),
|
||||
'<-- jquery place holder -->', '<script src=\"jquery.min.js\"><\/script>');
|
||||
writer.copyTpl('offline.html', writes.waitFor());
|
||||
writer.output('app-cache.manifest',
|
||||
appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
|
||||
writes.waitFor());
|
||||
//writer.output('app-cache.manifest',
|
||||
// appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
|
||||
// writes.waitFor());
|
||||
writer.merge(['docs.js',
|
||||
'doc_widgets.js'],
|
||||
'docs-combined.js',
|
||||
|
|
@ -56,6 +57,7 @@ var writes = callback.chain(function(){
|
|||
'syntaxhighlighter/syntaxhighlighter-combined.css',
|
||||
writes.waitFor());
|
||||
writer.copyTpl('jquery.min.js', writes.waitFor());
|
||||
writer.output('app-cache.manifest', appCache('build/docs/'), writes.waitFor());
|
||||
});
|
||||
writes.onDone(function(){
|
||||
console.log('DONE. Generated ' + docs.length + ' pages in ' +
|
||||
|
|
@ -80,8 +82,6 @@ function appCacheTemplate() {
|
|||
"docs-keywords.js",
|
||||
"docs-combined.css",
|
||||
"syntaxhighlighter/syntaxhighlighter-combined.css",
|
||||
"img/texture_1.png",
|
||||
"img/yellow_bkgnd.jpg",
|
||||
"",
|
||||
"FALLBACK:",
|
||||
"/ offline.html",
|
||||
|
|
|
|||
Loading…
Reference in a new issue