Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit be51fb3

Browse files
chore(api-builder): enable configurable link disambuators
1 parent 8d2290c commit be51fb3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tools/api-builder/links-package/services/getLinkInfo.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ var path = require('canonical-path');
1010
* @return {Object} The link information
1111
*
1212
* @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc
13+
* @property {array<function(url, title, currentDoc, ambiguousDocs) : array} disambiguators a collection of functions
14+
* that attempt to resolve ambiguous links. Each disambiguator returns a new collection of docs with
15+
* unwanted ambiguous docs removed (see moduleScopeLinkDisambiguator service for an example).
1316
*/
1417
module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
1518

16-
return function getLinkInfoImpl(url, title, currentDoc) {
19+
getLinkInfoImpl.disambiguators = [];
20+
21+
return getLinkInfoImpl;
22+
23+
function getLinkInfoImpl(url, title, currentDoc) {
1724
var linkInfo = {
1825
url: url,
1926
type: 'url',
@@ -27,6 +34,11 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
2734

2835
var docs = getDocFromAlias(url, currentDoc);
2936

37+
// Give each disambiguator a chance to reduce the number of ambiguous docs
38+
docs = getLinkInfoImpl.disambiguators.reduce(function(docs, disambiguator) {
39+
return disambiguator(url, title, currentDoc, docs);
40+
}, docs);
41+
3042
if ( !getLinkInfoImpl.useFirstAmbiguousLink && docs.length > 1 ) {
3143

3244
linkInfo.valid = false;
@@ -68,4 +80,5 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
6880

6981
return linkInfo;
7082
};
83+
7184
};

0 commit comments

Comments
 (0)