diff --git a/tools/api-builder/links-package/index.js b/tools/api-builder/links-package/index.js index 5391399055..4d4a06c82b 100644 --- a/tools/api-builder/links-package/index.js +++ b/tools/api-builder/links-package/index.js @@ -10,6 +10,8 @@ module.exports = new Package('links', []) .factory(require('dgeni-packages/links/services/getDocFromAlias')) .factory(require('./services/getLinkInfo')) .factory(require('./services/parseArgString')) +.factory(require('./services/moduleScopeLinkDisambiguator')) +.factory(require('./services/deprecatedDocsLinkDisambiguator')) .factory(require('./services/getApiFragmentFileName')) .config(function(inlineTagProcessor, linkInlineTagDef, linkDocsInlineTagDef, exampleInlineTagDef, exampleTabsInlineTagDef) { @@ -17,4 +19,9 @@ module.exports = new Package('links', []) inlineTagProcessor.inlineTagDefinitions.push(linkDocsInlineTagDef); inlineTagProcessor.inlineTagDefinitions.push(exampleInlineTagDef); inlineTagProcessor.inlineTagDefinitions.push(exampleTabsInlineTagDef); +}) + +.config(function(getLinkInfo, moduleScopeLinkDisambiguator, deprecatedDocsLinkDisambiguator) { + getLinkInfo.disambiguators.push(moduleScopeLinkDisambiguator); + getLinkInfo.disambiguators.push(deprecatedDocsLinkDisambiguator); }); diff --git a/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js b/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js new file mode 100644 index 0000000000..3db79ffbd6 --- /dev/null +++ b/tools/api-builder/links-package/services/deprecatedDocsLinkDisambiguator.js @@ -0,0 +1,13 @@ +var _ = require('lodash'); + +module.exports = function deprecatedDocsLinkDisambiguator() { + return function(url, title, currentDoc, docs) { + if (docs.length != 2) return docs; + + var filteredDocs = _.filter(docs, function(doc) { + return !doc.fileInfo.relativePath.match(/\/(\w+)-deprecated\//); + }); + + return filteredDocs.length > 0 ? filteredDocs : docs; + }; +}; diff --git a/tools/api-builder/links-package/services/getLinkInfo.js b/tools/api-builder/links-package/services/getLinkInfo.js index a180984c69..c0dad0025a 100644 --- a/tools/api-builder/links-package/services/getLinkInfo.js +++ b/tools/api-builder/links-package/services/getLinkInfo.js @@ -10,10 +10,17 @@ var path = require('canonical-path'); * @return {Object} The link information * * @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc + * @property {array 1 ) { linkInfo.valid = false; @@ -68,4 +80,5 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) { return linkInfo; }; + }; \ No newline at end of file diff --git a/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js b/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js new file mode 100644 index 0000000000..ec1758fe99 --- /dev/null +++ b/tools/api-builder/links-package/services/moduleScopeLinkDisambiguator.js @@ -0,0 +1,15 @@ +var _ = require('lodash'); + +module.exports = function moduleScopeLinkDisambiguator() { + return function(url, title, currentDoc, docs) { + if (docs.length > 1) { + // filter out target docs that are not in the same module as the source doc + var filteredDocs = _.filter(docs, function(doc) { + return doc.moduleDoc === currentDoc.moduleDoc; + }); + // if all target docs are in a different module then just return the full collection of ambiguous docs + return filteredDocs.length > 0 ? filteredDocs : docs; + } + return docs; + }; +};