File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var SiteMap = require ( 'sitemap.js' ) . SiteMap ;
2+ var Doc = require ( 'ngdoc.js' ) . Doc ;
3+
4+
5+ describe ( 'sitemap' , function ( ) {
6+ it ( 'should render empty sitemap' , function ( ) {
7+ var map = new SiteMap ( [ ] ) ;
8+ expect ( map . render ( ) ) . toEqual ( [
9+ '<?xml version="1.0" encoding="UTF-8"?>' ,
10+ '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' ,
11+ '</sitemapindex>' , '' ] . join ( '\n' ) ) ;
12+ } ) ;
13+
14+ it ( 'should render ngdoc url' , function ( ) {
15+ var map = new SiteMap ( [ new Doc ( { name : 'a.b.c<>\'"&' } ) ] ) ;
16+ expect ( map . render ( ) ) . toContain ( [
17+ ' <url>' ,
18+ '<loc>http://docs.angularjs.org/#!a.b.c<>'"&</loc>' ,
19+ '<changefreq>weekly</changefreq>' ,
20+ '</url>' ] . join ( '' ) ) ;
21+
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ exports . SiteMap = SiteMap ;
2+
3+ /**
4+ * @see http://www.sitemaps.org/protocol.php
5+ *
6+ * @param docs
7+ * @returns {SiteMap }
8+ */
9+ function SiteMap ( docs ) {
10+ this . render = function ( ) {
11+ var map = [ ] ;
12+ map . push ( '<?xml version="1.0" encoding="UTF-8"?>' ) ;
13+ map . push ( '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' ) ;
14+ docs . forEach ( function ( doc ) {
15+ map . push ( ' <url><loc>http://docs.angularjs.org/#!' +
16+ encode ( doc . name ) + '</loc><changefreq>weekly</changefreq></url>' ) ;
17+ } ) ;
18+ map . push ( '</sitemapindex>' ) ;
19+ map . push ( '' ) ;
20+ return map . join ( '\n' ) ;
21+ } ;
22+
23+ function encode ( text ) {
24+ return text
25+ . replace ( / & / mg, '&' )
26+ . replace ( / < / mg, '<' )
27+ . replace ( / > / mg, '>' )
28+ . replace ( / ' / mg, ''' )
29+ . replace ( / " / mg, '"' ) ;
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ require.paths.push('lib');
33var reader = require ( 'reader.js' ) ,
44 ngdoc = require ( 'ngdoc.js' ) ,
55 writer = require ( 'writer.js' ) ,
6- callback = require ( 'callback.js' ) ;
6+ callback = require ( 'callback.js' ) ,
7+ SiteMap = require ( 'SiteMap.js' ) . SiteMap ;
78
89var docs = [ ] ;
910var start ;
@@ -30,6 +31,8 @@ var writes = callback.chain(function(){
3031 writer . copy ( 'doc_widgets.css' , writes . waitFor ( ) ) ;
3132 writer . copy ( 'docs-scenario.html' , writes . waitFor ( ) ) ;
3233 writer . output ( 'docs-scenario.js' , ngdoc . scenarios ( docs ) , writes . waitFor ( ) ) ;
34+ writer . output ( 'sitemap.xml' , new SiteMap ( docs ) . render ( ) , writes . waitFor ( ) ) ;
35+ writer . output ( 'robots.txt' , 'Sitemap: http://docs.angularjs.org/sitemap.xml\n' , writes . waitFor ( ) ) ;
3336 writer . copy ( 'syntaxhighlighter/shBrushJScript.js' , writes . waitFor ( ) ) ;
3437 writer . copy ( 'syntaxhighlighter/shBrushXml.js' , writes . waitFor ( ) ) ;
3538 writer . copy ( 'syntaxhighlighter/shCore.css' , writes . waitFor ( ) ) ;
You can’t perform that action at this time.
0 commit comments