0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Fixed Pintura url not handling relative config url on import (#18343)

no issue

- Fixed the Pintura hook not handling relative urls passed to it from the config.

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 2be0e30</samp>

Fixed Pintura asset loading from subdirectories by using the admin root
path. Updated `usePinturaEditor` hook to import and use a helper
function for getting Ghost paths.
This commit is contained in:
Ronald Langeveld 2023-09-26 08:57:01 +07:00 committed by GitHub
parent 328a785065
commit 41576d2dc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
import * as Sentry from '@sentry/react';
import {Config} from '../api/config';
import {Setting} from '../api/settings';
import {getGhostPaths} from '../utils/helpers';
import {getSettingValues} from '../api/settings';
import {useCallback, useEffect, useState} from 'react';
import {useGlobalData} from '../components/providers/GlobalDataProvider';
@ -71,10 +72,17 @@ export default function usePinturaEditor({
};
let jsUrl = pinturaJsUrl();
// load the script from admin root if relative
if (!jsUrl) {
return;
}
// load the script from admin root if relative
if (jsUrl.startsWith('/')) {
const {adminRoot} = getGhostPaths();
jsUrl = window.location.origin + adminRoot.replace(/\/$/, '') + jsUrl;
}
if (window.pintura) {
setScriptLoaded(true);
return;
@ -109,6 +117,11 @@ export default function usePinturaEditor({
return;
}
if (cssUrl.startsWith('/')) {
const {adminRoot} = getGhostPaths();
cssUrl = window.location.origin + adminRoot.replace(/\/$/, '') + cssUrl;
}
try {
// Check if the CSS file is already present in the document's head
let cssLink = document.querySelector(`link[href="${cssUrl}"]`);