angular.js/docs/src/appCache.js
Vojta Jina 13f92de624 feat(docs): use html5 history api for all routing in the docs app
- Configure our docs app to use new $location with html5 history api!

- Update simple node web server to serve index.html for all links
  (rewritting).

- Update .htaccess file to serve index.html for all links (rewritting).

- At runtime determine the base href path and attach it to the DOM. We
  needed the absolute URL to get all browsers to work well.

- Because of the above, we also need to dynamically determine all needed
  js/css resources and add them to the DOM. This was needed because FF6
  would eagerly fetch resources with wrong URL since the base element is
  added to the dom at runtime.

- All content html files were moved to the partials directory, because
  with the new html5 urls it was impossible to tell if request for
  http://domain/api/angular.filter.html was an html5 url for the html
  filter doc page, or an xhr/appcache request for the content html file
  for the html filter.

f
2011-09-26 23:51:53 +02:00

76 lines
2.3 KiB
JavaScript

/**
* Generate appCache Manifest file here
*/
exports.appCache = appCache;
var fs = require('q-fs');
var Q = require('qq');
function identity($) {return $;}
function appCache(path) {
if(!path) {
return appCacheTemplate();
}
var blackList = ["build/docs/offline.html",
"build/docs/sitemap.xml",
"build/docs/robots.txt",
"build/docs/docs-scenario.html",
"build/docs/docs-scenario.js",
"build/docs/appcache.manifest",
"build/docs/.htaccess"
];
var result = ["CACHE MANIFEST",
"# " + new Date().toISOString(),
"",
"# cache all of these",
"CACHE:",
"../angular.min.js"];
var resultPostfix = ["",
"FALLBACK:",
"/ /build/docs/index.html",
"",
"# allow access to google analytics and twitter when we are online",
"NETWORK:",
"*"];
var promise = fs.listTree(path).then(function(files){
var fileFutures = [];
files.forEach(function(file){
fileFutures.push(fs.isFile(file).then(function(isFile){
if (isFile && blackList.indexOf(file) == -1) {
return file.replace('build/docs/','');
}
}));
});
return Q.deep(fileFutures);
}).then(function(files){
return result.concat(files.filter(identity)).concat(resultPostfix).join('\n');
});
return promise;
}
function appCacheTemplate() {
return ["CACHE MANIFEST",
"# " + new Date().toISOString(),
"",
"# cache all of these",
"CACHE:",
"syntaxhighlighter/syntaxhighlighter-combined.js",
"../angular.min.js",
"docs-combined.js",
"docs-keywords.js",
"docs-combined.css",
"syntaxhighlighter/syntaxhighlighter-combined.css",
"img/texture_1.png",
"img/yellow_bkgnd.jpg",
"",
"FALLBACK:",
"/ /build/docs/offline.html",
"",
"# allow access to google analytics and twitter when we are online",
"NETWORK:",
"*"].join('\n');
}