2023-10-02 22:32:05 +03:00
|
|
|
import config from 'ghost-admin/config/environment';
|
|
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
|
|
|
|
2023-09-28 18:43:12 +03:00
|
|
|
export default async function fetchKoenigLexical() {
|
|
|
|
if (window['@tryghost/koenig-lexical']) {
|
|
|
|
return window['@tryghost/koenig-lexical'];
|
|
|
|
}
|
|
|
|
|
2023-10-02 22:32:05 +03:00
|
|
|
// If we pass an editor URL (the env var from the dev script), use that
|
|
|
|
// Else, if we pass a CDN URL, use that
|
|
|
|
// Else, use the asset root from the ghostPaths util
|
|
|
|
const baseUrl = (config.editorUrl || (config.cdnUrl ? `${config.cdnUrl}assets/koenig-lexical/` : `${ghostPaths().assetRootWithHost}koenig-lexical/`));
|
2023-10-05 12:59:00 +03:00
|
|
|
const url = new URL(`${baseUrl}${config.editorFilename}?v=${config.editorHash}`);
|
2023-09-28 18:43:12 +03:00
|
|
|
|
|
|
|
if (url.protocol === 'http:') {
|
2023-10-05 12:59:00 +03:00
|
|
|
await import(`http://${url.host}${url.pathname}${url.search}`);
|
2023-09-28 18:43:12 +03:00
|
|
|
} else {
|
2023-10-05 12:59:00 +03:00
|
|
|
await import(`https://${url.host}${url.pathname}${url.search}`);
|
2023-09-28 18:43:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return window['@tryghost/koenig-lexical'];
|
|
|
|
}
|