mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 00:54:50 +03:00
c97cc08455
refs https://github.com/TryGhost/DevOps/issues/50 - `react-app` comes from `eslint-config-react-app`, which is a CRA package - we're moving away from that so this commit switches the linting over to a more recently updated plugin - once that was removed, we started using a newer version of `@typescript-eslint/eslint-plugin`, so there were plenty of updates/exemptions to make
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import './index.css';
|
|
import App from './App';
|
|
|
|
const ROOT_DIV_ID = 'ghost-portal-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-ghost]');
|
|
if (scriptTag) {
|
|
const siteI18nEnabled = scriptTag.dataset.i18n === 'true';
|
|
const siteUrl = scriptTag.dataset.ghost;
|
|
const apiKey = scriptTag.dataset.key;
|
|
const apiUrl = scriptTag.dataset.api;
|
|
return {siteUrl, apiKey, apiUrl, siteI18nEnabled};
|
|
}
|
|
return {};
|
|
}
|
|
|
|
function handleTokenUrl() {
|
|
const url = new URL(window.location.href);
|
|
if (url.searchParams.get('token')) {
|
|
url.searchParams.delete('token');
|
|
window.history.replaceState({}, document.title, url.href);
|
|
}
|
|
}
|
|
|
|
function setup() {
|
|
addRootDiv();
|
|
handleTokenUrl();
|
|
}
|
|
|
|
function init() {
|
|
// const customSiteUrl = getSiteUrl();
|
|
const {siteUrl: customSiteUrl, apiKey, apiUrl, siteI18nEnabled} = getSiteData();
|
|
const siteUrl = customSiteUrl || window.location.origin;
|
|
setup({siteUrl});
|
|
ReactDOM.render(
|
|
<React.StrictMode>
|
|
<App siteUrl={siteUrl} customSiteUrl={customSiteUrl} apiKey={apiKey} apiUrl={apiUrl} siteI18nEnabled={siteI18nEnabled} />
|
|
</React.StrictMode>,
|
|
document.getElementById(ROOT_DIV_ID)
|
|
);
|
|
}
|
|
|
|
init();
|