/** Shared site chrome. Public pages and native adapters consume these same templates. */ export const SHARED_FOOTER = ``; export function applySharedFooter(html){ const existing=html.match(/]*>[\s\S]*?<\/footer>/); if(!existing)return html.replace('',SHARED_FOOTER+''); // Keep authored memorial/award artwork when replacing legacy footer navigation. const memorial=existing[0].match(/<(aside|section)\b[^>]*class="[^"]*(?:memorial|tribute)[^"]*"[^>]*>[\s\S]*?<\/\1>/)?.[0]||''; return html.replace(existing[0],SHARED_FOOTER.replace('',memorial+'')); } export const SHARED_FOOTER_SCRIPT=`(()=>{if(window.top!==window.self)return;const html=${JSON.stringify(SHARED_FOOTER)};let footer=document.querySelector('body>footer,.dune-shared-footer');if(footer?.dataset.sharedChrome==='3')return;const memorial=document.querySelector('.dune-memorial');const template=document.createElement('template');template.innerHTML=html;const fresh=template.content.firstElementChild;if(memorial)fresh.append(memorial);if(footer)footer.replaceWith(fresh);else document.body.append(fresh);})();`; export function applySharedHeader(html,header,label){ if(/]*class="[^"]*dune-site-header/.test(html))return html.replace(/]*class="[^"]*dune-site-header[^"]*"[^>]*>[\s\S]*?<\/header>/,header); // Non-homepage legacy mastheads are compiled into the shared header as before. if(html.includes('
')){ const start=html.indexOf('
'),end=html.indexOf('\{if\(window.top!==window.self\)\{document.documentElement.classList.add\('dune-embedded'\);return;\}const links=[\s\S]*?\}\)\(\);/g,'');} export function assertSharedChrome(html,header,label='document'){ const headers=(html.match(/]*class="[^"]*dune-site-header/g)||[]).length; const footers=(html.match(/data-shared-chrome="3"/g)||[]).length; const banners=(html.match(/class="dr-page-banner"/g)||[]).length; const homeHeader=header.replace('class="dr-header-account"','class="dr-header-account" data-play'); if(label==='index.html'&&banners!==0)throw Error('Homepage banner is not allowed'); if(headers!==1||footers!==1||banners>1||!html.includes(header)&&!html.includes(homeHeader))throw Error('Shared chrome contract failed: '+label); return html; }