fix(menu): remove manual base tag injection since PHP handles it

main
Juan Manuel Bardallo 2026-09-17 14:48:28 +02:00
parent 4c2867b1c4
commit 205af45b72
1 changed files with 1 additions and 14 deletions

View File

@ -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);