mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 05:25:47 +00:00
Added SiteMap generation to the documentation
This commit is contained in:
parent
c2f2587a79
commit
bf03eb007c
3 changed files with 58 additions and 1 deletions
23
docs/spec/sitemapSpec.js
Normal file
23
docs/spec/sitemapSpec.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
var SiteMap = require('sitemap.js').SiteMap;
|
||||||
|
var Doc = require('ngdoc.js').Doc;
|
||||||
|
|
||||||
|
|
||||||
|
describe('sitemap', function(){
|
||||||
|
it('should render empty sitemap', function(){
|
||||||
|
var map = new SiteMap([]);
|
||||||
|
expect(map.render()).toEqual([
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||||
|
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
||||||
|
'</sitemapindex>', ''].join('\n'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render ngdoc url', function(){
|
||||||
|
var map = new SiteMap([new Doc({name: 'a.b.c<>\'"&'})]);
|
||||||
|
expect(map.render()).toContain([
|
||||||
|
' <url>',
|
||||||
|
'<loc>http://docs.angularjs.org/#!a.b.c<>'"&</loc>',
|
||||||
|
'<changefreq>weekly</changefreq>',
|
||||||
|
'</url>'].join(''));
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
31
docs/src/SiteMap.js
Normal file
31
docs/src/SiteMap.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
exports.SiteMap = SiteMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see http://www.sitemaps.org/protocol.php
|
||||||
|
*
|
||||||
|
* @param docs
|
||||||
|
* @returns {SiteMap}
|
||||||
|
*/
|
||||||
|
function SiteMap(docs){
|
||||||
|
this.render = function(){
|
||||||
|
var map = [];
|
||||||
|
map.push('<?xml version="1.0" encoding="UTF-8"?>');
|
||||||
|
map.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
|
||||||
|
docs.forEach(function(doc){
|
||||||
|
map.push(' <url><loc>http://docs.angularjs.org/#!' +
|
||||||
|
encode(doc.name) + '</loc><changefreq>weekly</changefreq></url>');
|
||||||
|
});
|
||||||
|
map.push('</sitemapindex>');
|
||||||
|
map.push('');
|
||||||
|
return map.join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
|
function encode(text){
|
||||||
|
return text
|
||||||
|
.replace(/&/mg, '&')
|
||||||
|
.replace(/</mg, '<')
|
||||||
|
.replace(/>/mg, '>')
|
||||||
|
.replace(/'/mg, ''')
|
||||||
|
.replace(/"/mg, '"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,8 @@ require.paths.push('lib');
|
||||||
var reader = require('reader.js'),
|
var reader = require('reader.js'),
|
||||||
ngdoc = require('ngdoc.js'),
|
ngdoc = require('ngdoc.js'),
|
||||||
writer = require('writer.js'),
|
writer = require('writer.js'),
|
||||||
callback = require('callback.js');
|
callback = require('callback.js'),
|
||||||
|
SiteMap = require('SiteMap.js').SiteMap;
|
||||||
|
|
||||||
var docs = [];
|
var docs = [];
|
||||||
var start;
|
var start;
|
||||||
|
|
@ -30,6 +31,8 @@ var writes = callback.chain(function(){
|
||||||
writer.copy('doc_widgets.css', writes.waitFor());
|
writer.copy('doc_widgets.css', writes.waitFor());
|
||||||
writer.copy('docs-scenario.html', writes.waitFor());
|
writer.copy('docs-scenario.html', writes.waitFor());
|
||||||
writer.output('docs-scenario.js', ngdoc.scenarios(docs), writes.waitFor());
|
writer.output('docs-scenario.js', ngdoc.scenarios(docs), writes.waitFor());
|
||||||
|
writer.output('sitemap.xml', new SiteMap(docs).render(), writes.waitFor());
|
||||||
|
writer.output('robots.txt', 'Sitemap: http://docs.angularjs.org/sitemap.xml\n', writes.waitFor());
|
||||||
writer.copy('syntaxhighlighter/shBrushJScript.js', writes.waitFor());
|
writer.copy('syntaxhighlighter/shBrushJScript.js', writes.waitFor());
|
||||||
writer.copy('syntaxhighlighter/shBrushXml.js', writes.waitFor());
|
writer.copy('syntaxhighlighter/shBrushXml.js', writes.waitFor());
|
||||||
writer.copy('syntaxhighlighter/shCore.css', writes.waitFor());
|
writer.copy('syntaxhighlighter/shCore.css', writes.waitFor());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue