doc.silverstripe.org/src/utils/rewriteAPILink.ts

18 lines
518 B
TypeScript
Raw Normal View History

import { getCurrentVersion } from './nodes';
2019-11-19 04:29:29 +01:00
/**
* If an href is preceded with api:, rewrite it to the api.silverstripe.org site
* @param link
*/
2019-11-08 03:40:20 +01:00
const rewriteAPILink = (link: string): string => {
const version = getCurrentVersion();
2019-11-08 03:40:20 +01:00
const match = link.match(/api\:(.*)/);
if (!match) {
console.error(`Unable to resolve api link ${link}!`);
return link;
}
return `https://api.silverstripe.org/search/lookup?q=${match[1]}&version=${version}`;
};
export default rewriteAPILink;