2022-07-22 02:16:51 +02:00
|
|
|
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 => {
|
2022-07-22 02:16:51 +02:00
|
|
|
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;
|