mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
refs https://github.com/TryGhost/Toolbox/issues/594 - this is the first of a set of commits to move our "apps" into the `apps/` folder, so we don't mix Ghost core and standalone apps
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import App from './App';
|
|
|
|
const ROOT_DIV_ID = 'sodo-search-root';
|
|
|
|
function addRootDiv() {
|
|
const elem = document.createElement('div');
|
|
elem.id = ROOT_DIV_ID;
|
|
document.body.appendChild(elem);
|
|
}
|
|
|
|
function getSiteData() {
|
|
/**
|
|
* @type {HTMLElement}
|
|
*/
|
|
const scriptTag = document.querySelector('script[data-sodo-search]');
|
|
if (scriptTag) {
|
|
const adminUrl = scriptTag.dataset.sodoSearch;
|
|
const apiKey = scriptTag.dataset.key;
|
|
const stylesUrl = scriptTag.dataset.styles;
|
|
return {adminUrl, apiKey, stylesUrl};
|
|
}
|
|
return {};
|
|
}
|
|
|
|
function setup() {
|
|
addRootDiv();
|
|
}
|
|
|
|
function init() {
|
|
const {adminUrl, apiKey, stylesUrl} = getSiteData();
|
|
const adminBaseUrl = (adminUrl || window.location.origin)?.replace(/\/+$/, '');
|
|
setup();
|
|
ReactDOM.render(
|
|
<React.StrictMode>
|
|
<App
|
|
adminUrl={adminBaseUrl} apiKey={apiKey}
|
|
stylesUrl={stylesUrl}
|
|
/>
|
|
</React.StrictMode>,
|
|
document.getElementById(ROOT_DIV_ID)
|
|
);
|
|
}
|
|
|
|
init();
|