Skip to content

Commit e90b741

Browse files
Di PengIgorMinar
authored andcommitted
feat(gen-docs): enable caching the whole site
Generate a manifest file automatically by reading the directories.
1 parent 3af1e7c commit e90b741

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

docs/src/appCache.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Generate appCache Manifest file here
3+
*/
4+
5+
exports.appCache = appCache;
6+
var fs = require('fs');
7+
8+
function appCache(path) {
9+
var blackList = [ "offline.html",
10+
"sitemap.xml",
11+
"robots.txt",
12+
"docs-scenario.html",
13+
"docs-scenario.js",
14+
"app-cache.manifest"
15+
];
16+
17+
var result = ["CACHE MANIFEST",
18+
"# %TIMESTAMP%",
19+
"",
20+
"# cache all of these",
21+
"CACHE:",
22+
"../angular.min.js"];
23+
24+
var resultPostfix = [ "",
25+
"FALLBACK:",
26+
"/offline.html",
27+
"",
28+
"# allow access to google analytics and twitter when we are online",
29+
"NETWORK:",
30+
"*"];
31+
walk(path,result,blackList);
32+
return result.join('\n').replace(/%TIMESTAMP%/, (new Date()).toISOString()) + '\n' + resultPostfix.join('\n');
33+
}
34+
35+
function walk(path, array, blackList) {
36+
var temp = fs.readdirSync(path);
37+
for (var i=0; i< temp.length; i++) {
38+
if(blackList.indexOf(temp[i]) < 0) {
39+
var currentPath = path + '/' + temp[i];
40+
var stat = fs.statSync(currentPath);
41+
42+
if (stat.isDirectory()) {
43+
walk(currentPath, array, blackList);
44+
}
45+
else {
46+
array.push(currentPath.replace('build/docs/',''));
47+
}
48+
}
49+
}
50+
}

docs/src/gen-docs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var reader = require('reader.js'),
44
ngdoc = require('ngdoc.js'),
55
writer = require('writer.js'),
66
callback = require('callback.js'),
7-
SiteMap = require('SiteMap.js').SiteMap;
7+
SiteMap = require('SiteMap.js').SiteMap,
8+
appCache = require('appCache.js');
89

910
var docs = [];
1011
var start;
@@ -31,9 +32,9 @@ var writes = callback.chain(function(){
3132
writer.copy('docs/src/templates/index.html', 'build/docs/index-jq.html', writes.waitFor(),
3233
'<-- jquery place holder -->', '<script src=\"jquery.min.js\"><\/script>');
3334
writer.copyTpl('offline.html', writes.waitFor());
34-
writer.output('app-cache.manifest',
35-
appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
36-
writes.waitFor());
35+
//writer.output('app-cache.manifest',
36+
// appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
37+
// writes.waitFor());
3738
writer.merge(['docs.js',
3839
'doc_widgets.js'],
3940
'docs-combined.js',
@@ -56,6 +57,7 @@ var writes = callback.chain(function(){
5657
'syntaxhighlighter/syntaxhighlighter-combined.css',
5758
writes.waitFor());
5859
writer.copyTpl('jquery.min.js', writes.waitFor());
60+
writer.output('app-cache.manifest', appCache('build/docs/'), writes.waitFor());
5961
});
6062
writes.onDone(function(){
6163
console.log('DONE. Generated ' + docs.length + ' pages in ' +
@@ -80,8 +82,6 @@ function appCacheTemplate() {
8082
"docs-keywords.js",
8183
"docs-combined.css",
8284
"syntaxhighlighter/syntaxhighlighter-combined.css",
83-
"img/texture_1.png",
84-
"img/yellow_bkgnd.jpg",
8585
"",
8686
"FALLBACK:",
8787
"/ offline.html",

0 commit comments

Comments
 (0)