Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

Commit

Permalink
feat(ngdocs): check broken links
Browse files Browse the repository at this point in the history
  • Loading branch information
m7r committed Jan 9, 2014
1 parent 986972b commit 6d22869
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions spec/ngdocSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('ngdoc', function() {


describe('checkBrokenLinks', function() {
var docs;
var docs, apis = {'api': true};

beforeEach(function() {
spyOn(console, 'log');
Expand All @@ -304,7 +304,7 @@ describe('ngdoc', function() {

it('should log warning when a linked page does not exist', function() {
docs.push(new Doc({section: 'api', id: 'with-broken.link', links: ['non-existing-link']}))
ngdoc.checkBrokenLinks(docs);
ngdoc.checkBrokenLinks(docs, apis);
expect(console.log).toHaveBeenCalled();
var warningMsg = console.log.argsForCall[0][0]
expect(warningMsg).toContain('WARNING:');
Expand All @@ -314,7 +314,7 @@ describe('ngdoc', function() {

it('should log warning when a linked anchor does not exist', function() {
docs.push(new Doc({section: 'api', id: 'with-broken.link', links: ['api/fake.id1#non-existing']}))
ngdoc.checkBrokenLinks(docs);
ngdoc.checkBrokenLinks(docs, apis);
expect(console.log).toHaveBeenCalled();
var warningMsg = console.log.argsForCall[0][0]
expect(warningMsg).toContain('WARNING:');
Expand Down
7 changes: 5 additions & 2 deletions src/ngdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,18 +1252,21 @@ function merge(docs){
//////////////////////////////////////////////////////////


function checkBrokenLinks(docs) {
function checkBrokenLinks(docs, apis, options) {
var byFullId = Object.create(null);

docs.forEach(function(doc) {
byFullId[doc.section + '/' + doc.id] = doc;
if (doc.section === 'api') {
if (apis[doc.section]) {
doc.anchors.push('directive', 'service', 'filter', 'function');
}
});

docs.forEach(function(doc) {
doc.links.forEach(function(link) {
if (options && !options.html5mode) {
link = link.substring(2);
}
// convert #id to path#id
if (link[0] == '#') {
link = doc.section + '/' + doc.id.split('#').shift() + link;
Expand Down
1 change: 1 addition & 0 deletions tasks/grunt-ngdocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ module.exports = function(grunt) {
});

ngdoc.merge(reader.docs);
ngdoc.checkBrokenLinks(reader.docs, setup.apis, options);

reader.docs.forEach(function(doc){
// this hack is here because on OSX angular.module and angular.Module map to the same file.
Expand Down

0 comments on commit 6d22869

Please sign in to comment.