diff options
| author | Di Peng | 2011-06-24 18:09:59 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-07-20 17:09:40 -0700 |
| commit | e90b741c9492a65e159c842afe49383f1868308e (patch) | |
| tree | 3f0b16574e27ffa4878dab76389a15e9a7f4b477 /docs/src/appCache.js | |
| parent | 3af1e7ca2ee8c2acd69e5bcbb3ffc1bf51239285 (diff) | |
| download | angular.js-e90b741c9492a65e159c842afe49383f1868308e.tar.bz2 | |
feat(gen-docs): enable caching the whole site
Generate a manifest file automatically by reading the directories.
Diffstat (limited to 'docs/src/appCache.js')
| -rw-r--r-- | docs/src/appCache.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/docs/src/appCache.js b/docs/src/appCache.js new file mode 100644 index 00000000..994054c2 --- /dev/null +++ b/docs/src/appCache.js @@ -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/','')); + } + } + } +}
\ No newline at end of file |
