mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
Fixed theme preview on theme without styles (#18375)
refs https://ghost.slack.com/archives/C0568LN2CGJ/p1695741379821479 - Fixes a bug in the preview renderer where a theme without styles wouldn't be handled properly as it cannot inject new styles and cause an empty page to be returned. --- <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> copilot:summary
This commit is contained in:
parent
29f98104df
commit
7bebe7daf4
1 changed files with 6 additions and 2 deletions
|
@ -81,8 +81,12 @@ const ThemePreview: React.FC<ThemePreviewProps> = ({settings,url}) => {
|
|||
const htmlDoc = domParser.parseFromString(data, 'text/html');
|
||||
|
||||
const stylesheet = htmlDoc.querySelector('style') as HTMLStyleElement;
|
||||
const originalCSS = stylesheet.innerHTML;
|
||||
const originalCSS = stylesheet?.innerHTML;
|
||||
if (originalCSS) {
|
||||
stylesheet.innerHTML = `${originalCSS}\n\n${injectedCss}`;
|
||||
} else {
|
||||
htmlDoc.head.innerHTML += `<style>${injectedCss}</style>`;
|
||||
}
|
||||
|
||||
// replace the iframe contents with the doctored preview html
|
||||
const doctype = htmlDoc.doctype ? new XMLSerializer().serializeToString(htmlDoc.doctype) : '';
|
||||
|
|
Loading…
Add table
Reference in a new issue