Skip to content

Commit a2672a4

Browse files
committed
Update API Set URL resolution logic
1 parent c3d0bbe commit a2672a4

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

apps/api-documenter/src/yaml/OfficeYamlDocumenter.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ interface ISnippetsFile {
2525
export class OfficeYamlDocumenter extends YamlDocumenter {
2626
private _snippets: ISnippetsFile;
2727

28+
// Default API Set URL when no product match is found.
29+
private _apiSetUrlDefault: string = '/javascript/office/javascript-api-for-office';
30+
31+
// Hash set of API Set URLs based on product.
32+
private _apiSetUrls: Object = {
33+
'Excel': '/javascript/office/requirement-sets/excel-api-requirement-sets',
34+
'OneNote': '/javascript/office/requirement-sets/onenote-api-requirement-sets',
35+
'Visio': '/javascript/office/overview/visio-javascript-reference-overview',
36+
'Outlook': '/javascript/office/requirement-sets/outlook-api-requirement-sets',
37+
'Word': '/javascript/office/requirement-sets/word-api-requirement-sets'
38+
};
39+
2840
public constructor(docItemSet: DocItemSet, inputFolder: string) {
2941
super(docItemSet);
3042

@@ -89,18 +101,18 @@ export class OfficeYamlDocumenter extends YamlDocumenter {
89101
// Hyperlink it like this:
90102
// \[ [API set: ExcelApi 1.1](http://bing.com?type=excel) \]
91103
markup = markup.replace(/Api/, 'API');
92-
if (uid.search(/Excel/i) !== -1) {
93-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com?type=excel) \\]`);
94-
} else if (uid.search(/OneNote/i) !== -1) {
95-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com?type=onenote) \\]`);
96-
} else if (uid.search(/Visio/i) !== -1) {
97-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com?type=visio) \\]`);
98-
} else if (uid.search(/Outlook/i) !== -1) {
99-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com?type=outlook) \\]`);
100-
} else if (uid.search(/Word/i) !== -1) {
101-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com?type=word) \\]`);
102-
} else {
103-
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, `\\[ [$1](http://bing.com) \\]`);
104+
return markup.replace(/\\\[(API set:[^\]]+)\\\]/, '\\[ [$1](' + this._getApiSetUrl(uid) + ') \\]');
105+
}
106+
107+
// Gets the link to the API set based on product context. Seeks a case-insensitve match in the hash set.
108+
private _getApiSetUrl(uid: string): string {
109+
for (const key of Object.keys(this._apiSetUrls)) {
110+
const regexp: RegExp = new RegExp(key, 'i');
111+
if (regexp.test(uid)) {
112+
return this._apiSetUrls[key];
113+
}
104114
}
115+
return this._apiSetUrlDefault; // match not found.
105116
}
117+
106118
}

0 commit comments

Comments
 (0)