0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Updated site url fetch from data attribute

closes https://github.com/TryGhost/members.js/issues/54

- Site url is added as data attribute on script tag load in Ghost head
- was previously fetched via meta tag which was inserted on site
This commit is contained in:
Rish 2020-06-22 17:46:40 +05:30
parent aaa8fd3535
commit 7a9d7497fb

View file

@ -12,10 +12,10 @@ function addRootDiv() {
document.body.appendChild(elem); document.body.appendChild(elem);
} }
function getSiteUrlFromMeta() { function getSiteUrl() {
const ghostSiteMeta = document.querySelector('meta[name="ghost:site"]'); const scriptTag = document.querySelector('script[data-ghost]');
if (ghostSiteMeta) { if (scriptTag) {
return ghostSiteMeta.getAttribute('content'); return scriptTag.dataset.ghost;
} }
return ''; return '';
} }
@ -53,7 +53,7 @@ function setup({siteUrl}) {
} }
function init() { function init() {
const siteUrl = getSiteUrlFromMeta() || window.location.origin; const siteUrl = getSiteUrl() || window.location.origin;
setup({siteUrl}); setup({siteUrl});
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>