mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Updated site url to read from ghost:site
meta tag on theme
closes https://github.com/TryGhost/members.js/issues/39 - Script needs correct ghost site url to initialize correct API endpoints for fetching site/members data - `window.location.origin` won't work as correct ghost site url in all cases, specially for sites using subdirectory setup - New meta tag `ghost:site` is inserted on themes with correct `siteUrl`, which is used to initialize api
This commit is contained in:
parent
8df822d317
commit
432caae79c
1 changed files with 13 additions and 4 deletions
|
@ -12,6 +12,14 @@ function addRootDiv() {
|
|||
document.body.appendChild(elem);
|
||||
}
|
||||
|
||||
function getSiteUrlFromMeta() {
|
||||
const ghostSiteMeta = document.querySelector('meta[name="ghost:site"]');
|
||||
if (ghostSiteMeta) {
|
||||
return ghostSiteMeta.getAttribute('content');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function loadStripe() {
|
||||
// We don't want to load Stripe again if already loaded
|
||||
if (!window.Stripe) {
|
||||
|
@ -34,21 +42,22 @@ function handleTokenUrl() {
|
|||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
function setup({siteUrl}) {
|
||||
const allowDataAttributeHandling = true;
|
||||
loadStripe();
|
||||
addRootDiv();
|
||||
if (allowDataAttributeHandling) {
|
||||
handleDataAttributes({siteUrl: window.location.origin});
|
||||
handleDataAttributes({siteUrl});
|
||||
}
|
||||
handleTokenUrl();
|
||||
}
|
||||
|
||||
function init() {
|
||||
setup();
|
||||
const siteUrl = getSiteUrlFromMeta() || window.location.origin;
|
||||
setup({siteUrl});
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<App siteUrl={siteUrl} />
|
||||
</React.StrictMode>,
|
||||
document.getElementById(ROOT_DIV_ID)
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue