fix(menu): remove manual base tag injection since PHP handles it
parent
4c2867b1c4
commit
205af45b72
|
|
@ -121,20 +121,7 @@ export class CreateMenuComponent implements OnInit {
|
||||||
// Ask the backend to compile a preview using this encoded Twig
|
// Ask the backend to compile a preview using this encoded Twig
|
||||||
this.dataService.previewMenuTemplate(base64Content).subscribe({
|
this.dataService.previewMenuTemplate(base64Content).subscribe({
|
||||||
next: (renderedHtml) => {
|
next: (renderedHtml) => {
|
||||||
// Ensure relative paths work in the data URL iframe by injecting a <base> tag
|
const renderedBytes = new TextEncoder().encode(renderedHtml);
|
||||||
const baseTag = `<base href="${this.baseUrl}/">`;
|
|
||||||
|
|
||||||
let finalHtml = renderedHtml;
|
|
||||||
if (finalHtml.toLowerCase().includes('<head>')) {
|
|
||||||
finalHtml = finalHtml.replace(/<head>/i, `<head>${baseTag}`);
|
|
||||||
} else if (finalHtml.toLowerCase().includes('<html>')) {
|
|
||||||
finalHtml = finalHtml.replace(/<html>/i, `<html><head>${baseTag}</head>`);
|
|
||||||
} else {
|
|
||||||
finalHtml = `<head>${baseTag}</head>` + finalHtml;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now encode the definitively rendered HTML to Base64 to populate the iframe preview
|
|
||||||
const renderedBytes = new TextEncoder().encode(finalHtml);
|
|
||||||
const renderedBinaryStr = Array.from(renderedBytes).map(byte => String.fromCharCode(byte)).join('');
|
const renderedBinaryStr = Array.from(renderedBytes).map(byte => String.fromCharCode(byte)).join('');
|
||||||
const renderedBase64 = window.btoa(renderedBinaryStr);
|
const renderedBase64 = window.btoa(renderedBinaryStr);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue