From e8cc85f733a49ca53e8cda5a96bbaacc9a20ac7e Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Thu, 17 Oct 2013 14:16:32 -0700 Subject: chore(docs): generate header ids for better linking - generate ids for all headers - collect defined anchors - check broken links (even if the page exists, but the anchor/id does not) --- docs/spec/domSpec.js | 65 +++++++++++++++++++++++++++++++++++++++++--- docs/spec/ngdocSpec.js | 52 ++++++++++++++++++----------------- docs/src/dom.js | 73 ++++++++++++++++++++++++++++++++++++++------------ docs/src/gen-docs.js | 2 ++ docs/src/ngdoc.js | 63 ++++++++++++++++++++++++++++++------------- 5 files changed, 193 insertions(+), 62 deletions(-) diff --git a/docs/spec/domSpec.js b/docs/spec/domSpec.js index 7bc6a7f4..d10db9dc 100644 --- a/docs/spec/domSpec.js +++ b/docs/spec/domSpec.js @@ -1,4 +1,5 @@ var DOM = require('../src/dom.js').DOM; +var normalizeHeaderToId = require('../src/dom.js').normalizeHeaderToId; describe('dom', function() { var dom; @@ -7,6 +8,31 @@ describe('dom', function() { dom = new DOM(); }); + describe('html', function() { + it('should add ids to all h tags', function() { + dom.html('
| '); @@ -1211,22 +1223,7 @@ function merge(docs){ }); for(var i = 0; i < docs.length;) { - var doc = docs[i]; - - // check links - do they exist ? - doc.links.forEach(function(link) { - // convert #id to path#id - if (link[0] == '#') { - link = doc.section + '/' + doc.id.split('#').shift() + link; - } - link = link.split('#').shift(); - if (!byFullId[link]) { - console.log('WARNING: In ' + doc.section + '/' + doc.id + ', non existing link: "' + link + '"'); - } - }); - - // merge into parents - if (findParent(doc, 'method') || findParent(doc, 'property') || findParent(doc, 'event')) { + if (findParent(docs[i], 'method') || findParent(docs[i], 'property') || findParent(docs[i], 'event')) { docs.splice(i, 1); } else { i++; @@ -1255,6 +1252,36 @@ function merge(docs){ } ////////////////////////////////////////////////////////// + +function checkBrokenLinks(docs) { + var byFullId = Object.create(null); + + docs.forEach(function(doc) { + byFullId[doc.section + '/' + doc.id] = doc; + }); + + docs.forEach(function(doc) { + doc.links.forEach(function(link) { + // convert #id to path#id + if (link[0] == '#') { + link = doc.section + '/' + doc.id.split('#').shift() + link; + } + + var parts = link.split('#'); + var pageLink = parts[0]; + var anchorLink = parts[1]; + var linkedPage = byFullId[pageLink]; + + if (!linkedPage) { + console.log('WARNING: ' + doc.section + '/' + doc.id + ' (defined in ' + doc.file + ') points to a non existing page "' + link + '"!'); + } else if (anchorLink && linkedPage.anchors.indexOf(anchorLink) === -1) { + console.log('WARNING: ' + doc.section + '/' + doc.id + ' (defined in ' + doc.file + ') points to a non existing anchor "' + link + '"!'); + } + }); + }); +} + + function property(name) { return function(value){ return value[name]; -- cgit v1.2.3 |