From e90b741c9492a65e159c842afe49383f1868308e Mon Sep 17 00:00:00 2001 From: Di Peng Date: Fri, 24 Jun 2011 18:09:59 -0700 Subject: feat(gen-docs): enable caching the whole site Generate a manifest file automatically by reading the directories. --- docs/src/appCache.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/src/gen-docs.js | 12 ++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 docs/src/appCache.js 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 diff --git a/docs/src/gen-docs.js b/docs/src/gen-docs.js index dfdbdf45..8ed0c563 100755 --- a/docs/src/gen-docs.js +++ b/docs/src/gen-docs.js @@ -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 -->', '