Merge pull request 'Template Fix 6000' (#603) from dev/MC:fix/header-dropdown-regression-20261125 into main
All checks were successful
DuneRealms Web CI / web (push) Successful in 4m21s

This commit is contained in:
unimatrix 2026-11-25 08:21:11 +00:00
commit a69320d9f7
17 changed files with 288 additions and 20 deletions

View file

@ -33,13 +33,13 @@ function dune_sections_index(){
if($system){$label=empty($collapsed[$key.'_e'])?'Collapse System Boards':'Expand System Boards';$toggle='<div class="expcolimage"><img src="'.dune_sections_escape($theme['imgdir'].'/collapse'.($collapsedimg[$key]??'').'.png').'" id="'.$key.'_img" class="expander" alt="'.$label.'" title="'.$label.'"></div>';}
$html.='<section class="dune-board-category"><div class="dune-board-heading'.($system?($collapsedthead[$key]??''):'').'">'.$toggle.'<p>COMMUNITY FORUMS</p><h2>'.dune_sections_escape($root['name']).'</h2></div>';
if($system)$html.='<div id="'.$key.'_e" style="'.($collapsed[$key.'_e']??'').'">';
$html.='<div class="dune-board-children"><span>Subcategories</span>'.dune_sections_links($panels).'</div><div class="dune-board-panels">';
$html.='<div class="dune-board-panels">';
foreach($panels as$panel){
$children=dune_sections_children((int)$panel['fid'],$all);
$html.='<section class="dune-board-panel"><div class="dune-board-panel-title"><img src="https://www.dunerealms.com/assets/nav-boards-v2.webp" alt="" width="44" height="44"><div><h3><a href="'.dune_sections_escape(get_forum_link($panel['fid'])).'">'.dune_sections_escape($panel['name']).'</a></h3><p>'.dune_sections_escape(strip_tags($panel['description'])).'</p></div><span>SUBCATEGORY</span></div>';
$previous=$mybb->settings['hideprivateforums'];$mybb->settings['hideprivateforums']=1;
try{
if($children){$html.='<div class="dune-board-children"><span>Forums</span>'.dune_sections_links($children).'</div>';$rows=build_forumbits((int)$panel['fid'],2);}
if($children){$rows=build_forumbits((int)$panel['fid'],2);}
elseif($panel['type']==='f'){
$copy=$panel;$copy['name']='Discussions';$copy['description']='';$virtual=-991;
$before=$fcache[$virtual]??null;$fcache[$virtual]=[0=>[(int)$panel['fid']=>$copy]];
@ -47,6 +47,7 @@ function dune_sections_index(){
}else $rows=null;
}finally{$mybb->settings['hideprivateforums']=$previous;}
if($rows&&!empty($rows['forum_list']))$html.='<table class="tborder dune-board-forums"><thead><tr><th colspan="2">Forum</th><th>Threads</th><th>Posts</th><th>Last post</th></tr></thead><tbody>'.$rows['forum_list'].'</tbody></table>';
else if($children)$html.='<div class="dune-board-children"><span>Forums</span>'.dune_sections_links($children).'</div>';
else $html.='<p class="dune-board-empty">No visible forums in this section.</p>';
$html.='</section>';
}

View file

@ -6,8 +6,8 @@ release=pathlib.Path('/home/dunerealms/apps/dunerealms/current').resolve(strict=
assert release.name=='ci-'+args.expected_release
base=pathlib.Path('/home/dunerealms/apps/integrations').resolve(strict=True)
node='/home/dunerealms/.nvm/versions/node/v22.23.3/bin/node'
result=subprocess.run([node,'--input-type=module','-e',"import {SHARED_HEADER,SHARED_HEAD} from './scripts/portal-navigation.mjs';console.log(JSON.stringify({header:SHARED_HEADER,head:SHARED_HEAD}));"],cwd=release,capture_output=True,text=True,check=True)
chrome=json.loads(result.stdout);script=(release/'web/realm-design.js').read_text();css=(release/'web/realm-design.css').read_text();assert '__duneRealmDesign' in script and 'dr-native' in css and 'dr-header-brand' in chrome['header']
result=subprocess.run([node,'--input-type=module','-e',"import {SHARED_HEADER,SHARED_HEAD} from './scripts/portal-navigation.mjs';import {sharedHomepageHeaderScript} from './scripts/homepage-header.mjs';console.log(JSON.stringify({header:SHARED_HEADER,head:SHARED_HEAD,runtime:sharedHomepageHeaderScript()}));"],cwd=release,capture_output=True,text=True,check=True)
chrome=json.loads(result.stdout);script=(release/'web/realm-design.js').read_text()+chrome['runtime'];support_css=(release/'scripts/osticket-presentation.css').read_text();forum_css=(release/'scripts/mybb-presentation.css').read_text();css=(release/'web/realm-design.css').read_text()+'\n'+(release/'scripts/homepage-header.css').read_text()+'\n'+support_css+'\n'+forum_css;assert '__duneRealmDesign' in script and 'dr-native' in css and 'data-shared-header-source="homepage"' in chrome['header']
start='/* DUNE REALM DESIGN START */';end='/* DUNE REALM DESIGN END */'
def append(old,content):
if start in old:
@ -19,12 +19,17 @@ native_head=chrome['head'].replace('href="/portal-navigation.css"','href="https:
# already includes realm-design.js. Keep their existing script security policy.
native_head=re.sub(r'<script\b[^>]*src="[^"]*/realm-design\.js[^>]*></script>','',native_head)
changes={'shared-header.html':chrome['header'],'shared-header-head.html':native_head}
hook=base/'shared-header.php';original_hook=hook.read_text();assert 'v=canonical-362' in original_hook or 'v=realm-design-1' in original_hook
changes['shared-header.php']=original_hook.replace('v=canonical-362','v=realm-design-1')
hook=base/'shared-header.php';original_hook=hook.read_text();assert any(v in original_hook for v in ('v=canonical-362','v=realm-design-1','v=template-fix-6000'))
changes['shared-header.php']=original_hook.replace('v=canonical-362','v=template-fix-6000').replace('v=realm-design-1','v=template-fix-6000').replace('dune-osticket-theme.css?v=20261103-alpha','dune-osticket-theme.css?v=template-fix-6000').replace('dune-forum-polish.css?v=328-1','dune-forum-polish.css?v=template-fix-6000')
for app in ['mybb','osticket']:
for ext,content in [('js',(release/'dist/shared-chrome/portal-navigation.js').read_text()),('css',(release/'dist/shared-chrome/portal-navigation.css').read_text()+'\n'+re.sub(r'^@import[^;]+;\s*','',css))]:
relative=app+'/dune-navigation.'+ext;target=(base/relative).resolve(strict=True);assert target.is_relative_to(base)
changes[relative]=content
support_theme=(base/'osticket/dune-osticket-theme.css').resolve(strict=True);assert support_theme.is_relative_to(base)
changes['osticket/dune-osticket-theme.css']=append(support_theme.read_text(),support_css)
forum_theme=(base/'mybb/dune-forum-polish.css').resolve(strict=True);assert forum_theme.is_relative_to(base)
changes['mybb/dune-forum-polish.css']=append(forum_theme.read_text(),forum_css)
changes['mybb/inc/plugins/dune_sections.php']=(release/'integrations/mybb/inc/plugins/dune_sections.php').read_text()
targets={name:(base/name).resolve(strict=True) for name in changes}
assert all(target.is_relative_to(base) for target in targets.values())
# The standalone shop host keeps its own document and iframe bridge.

View file

@ -1,5 +1,6 @@
import {applySharedHeader,applySharedFooter,SHARED_FOOTER_SCRIPT,cleanLegacyChromeScript,assertSharedChrome} from './site-chrome.mjs';
import {SHARED_HEADER} from './portal-navigation.mjs';
import {sharedHomepageHeaderScript} from './homepage-header.mjs';
import {applyRealmPageDesign} from './realm-page-design.mjs';
import {publishExchangeAssets} from './public-exchange-assets.mjs';
import {createHash} from 'node:crypto';
@ -13,8 +14,10 @@ import{updatePortalNavigation}from'./portal-navigation.mjs';
import {readFileSync,writeFileSync as writePlain,renameSync,unlinkSync,openSync,writeSync,closeSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url';
function writeFileSync(file,content){const temporary=file+'.build-'+process.pid;writePlain(temporary,content);renameSync(temporary,file);}
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist');
const sharedRealmRuntime=readFileSync(path.join(web,'realm-design.js'),'utf8')+sharedHomepageHeaderScript();
const sharedRealmCSS=Buffer.concat([readFileSync(path.join(web,'realm-design.css')),readFileSync(new URL('./homepage-header.css',import.meta.url)),readFileSync(new URL('./osticket-presentation.css',import.meta.url)),readFileSync(new URL('./mybb-presentation.css',import.meta.url))]);
// Embedded workspaces execute the same runtime through their permitted origin.
writeFileSync(path.join(root,'control-panel/public/cp-v2/cp-v2-realm-design.mjs'),readFileSync(path.join(web,'realm-design.js')));
writeFileSync(path.join(root,'control-panel/public/cp-v2/cp-v2-realm-design.mjs'),sharedRealmRuntime);
// CP entry documents are served directly by the existing CP process. Compile their
// shared chrome from the same templates as public pages, without altering forms.
function compileCPChrome(directory){for(const entry of readdirSync(directory,{withFileTypes:true})){const file=path.join(directory,entry.name);if(entry.isDirectory()){if(entry.name!=='native-editor')compileCPChrome(file);continue;}if(!entry.name.endsWith('.html'))continue;const old=readFileSync(file,'utf8');if(!old.includes('dune-site-header'))continue;const next=assertSharedChrome(applySharedFooter(applySharedHeader(old,SHARED_HEADER)),SHARED_HEADER,file);if(next!==old)writeFileSync(file,next);}}
@ -38,10 +41,10 @@ if(!legalNotice)throw Error('Homepage legal notice is missing');
function preparePublicHtml(html,file){
html=applyRealmPageDesign(html,file);
// A single template owns the chrome; page content and service forms remain local.
html=applySharedHeader(html,SHARED_HEADER);
html=applySharedHeader(html,SHARED_HEADER,file);
html=applySharedFooter(html);
// All page families retain one shared notice, including generated documents.
let result=/<html lang="en" data-dune-(?:portal-preview|realm-shell)>/.test(html)?html:updatePortalNavigation(html);
let result=file==='index.html'||/<html lang="en" data-dune-(?:portal-preview|realm-shell)>/.test(html)?html:updatePortalNavigation(html);
if(!result.includes('class="legal-notice"')){
if(!result.includes('</body>'))throw Error('Public HTML page missing closing body');
result=result.replace('</body>',legalNotice+'</body>');
@ -52,7 +55,7 @@ function preparePublicHtml(html,file){
publishExchangeAssets(path.join(root,'control-panel/public'),web);
writeFileSync(path.join(web,'rates-and-charges.html'),applyRealmPageDesign(bankRatesPage(),'rates-and-charges.html'));
let assetCount=0;let assetWriter=null,shardSize=0;const shardNames=[];let shardTemporary;function openShard(){shardTemporary=path.join(dist,'server','.assets-build-'+process.pid);assetWriter=openSync(shardTemporary,'w');writeSync(assetWriter,'export default {');shardSize=0;}function closeShard(){writeSync(assetWriter,'};\n');closeSync(assetWriter);const hash=createHash('sha256').update(readFileSync(shardTemporary)).digest('hex'),name='assets-'+hash+'.mjs',target=path.join(dist,'server',name);if(existsSync(target))unlinkSync(shardTemporary);else renameSync(shardTemporary,target);shardNames.push(name);}function writeAsset(entry){if(shardSize>32*1024*1024){closeShard();openShard();}writeSync(assetWriter,entry);shardSize+=Buffer.byteLength(entry);}const types={'.html':'text/html; charset=utf-8','.css':'text/css; charset=utf-8','.js':'text/javascript; charset=utf-8','.mjs':'text/javascript; charset=utf-8','.json':'application/json; charset=utf-8','.webp':'image/webp','.png':'image/png','.mp4':'video/mp4','.pdf':'application/pdf','.zip':'application/zip','.svg':'image/svg+xml'};
function collect(directory){for(const entry of readdirSync(directory).sort()){const p=path.join(directory,entry);if(statSync(p).isDirectory())collect(p);else{const relative=path.relative(web,p).split(path.sep).join('/');if(/^assets\/seals\/[^/]+-provenance\.txt$/.test(relative)||/^assets\/organisation-deed(?:s)?-[a-z0-9-]+\.png$/.test(relative))continue;const type=types[path.extname(entry)];if(!type)throw Error('Unexpected asset: '+entry);const bytes=readFileSync(p);const payload=relative.endsWith('.html')?Buffer.from(preparePublicHtml(bytes.toString('utf8'),relative)):relative==='portal-navigation.js'?Buffer.from(SHARED_FOOTER_SCRIPT+withRealmSwitch(withCanonicalMenu(withMenuBadges(cleanLegacyChromeScript(bytes.toString('utf8')))))+readFileSync(path.join(web,'realm-design.js'),'utf8')):relative==='portal-navigation.css'?Buffer.concat([bytes,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS+readFileSync(path.join(web,"realm-comfort.css"),"utf8"))]):bytes;writeAsset(JSON.stringify('/'+relative)+':['+JSON.stringify(type)+','+JSON.stringify(payload.toString('base64'))+'],');assetCount++}}}
function collect(directory){for(const entry of readdirSync(directory).sort()){const p=path.join(directory,entry);if(statSync(p).isDirectory())collect(p);else{const relative=path.relative(web,p).split(path.sep).join('/');if(/^assets\/seals\/[^/]+-provenance\.txt$/.test(relative)||/^assets\/organisation-deed(?:s)?-[a-z0-9-]+\.png$/.test(relative))continue;const type=types[path.extname(entry)];if(!type)throw Error('Unexpected asset: '+entry);const bytes=readFileSync(p);const payload=relative.endsWith('.html')?Buffer.from(preparePublicHtml(bytes.toString('utf8'),relative)):relative==='realm-design.js'?Buffer.from(sharedRealmRuntime):relative==='realm-design.css'?sharedRealmCSS:relative==='portal-navigation.js'?Buffer.from(SHARED_FOOTER_SCRIPT+withRealmSwitch(withCanonicalMenu(withMenuBadges(cleanLegacyChromeScript(bytes.toString('utf8')))))+sharedRealmRuntime):relative==='portal-navigation.css'?Buffer.concat([bytes,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS+readFileSync(path.join(web,"realm-comfort.css"),"utf8"))]):bytes;writeAsset(JSON.stringify('/'+relative)+':['+JSON.stringify(type)+','+JSON.stringify(payload.toString('base64'))+'],');assetCount++}}}
mkdirSync(path.join(dist,'server'),{recursive:true});mkdirSync(path.join(dist,'.openai'),{recursive:true});const workerTemporary=path.join(dist,'server/index.js.build-'+process.pid);process.once('exit',()=>{if(existsSync(workerTemporary))try{unlinkSync(workerTemporary);}catch{}});openShard();collect(web);const buildCommit=process.env.GITHUB_SHA;if(buildCommit&&/^[0-9a-f]{40}$/.test(buildCommit)){writeAsset(JSON.stringify('/ci-build.json')+':'+JSON.stringify(['application/json; charset=utf-8',Buffer.from(JSON.stringify({commit:buildCommit})).toString('base64')])+',');}closeShard();
let api=['public-item-metadata.mjs','feed-api.mjs','exchange-api.mjs','forum-api.mjs','community-api.mjs','portal-api.mjs'].map(file=>readFileSync(path.join(root,'worker',file),'utf8').replace(/^import .*;$/gm,'').replace(/export /g,'')).join('\n');let runtime=readFileSync(path.join(root,'worker/runtime.mjs'),'utf8').replace(/^import .*;$/gm,'');
writeFileSync(path.join(dist,'server/index.js'),shardNames.map((name,i)=>'import DATA'+i+' from '+JSON.stringify('./'+name)+';').join('\n')+'\nconst ASSET_DATA=Object.assign({},'+shardNames.map((_,i)=>'DATA'+i).join(',')+');\n'+api+'\n'+runtime);cpSync(path.join(root,'.openai/hosting.json'),path.join(dist,'.openai/hosting.json'));console.log('Built Worker with',assetCount,'embedded website assets');
@ -63,7 +66,7 @@ if(existsSync(path.join(root,'drizzle')))cpSync(path.join(root,'drizzle'),path.j
const shared=path.join(dist,'shared-chrome');mkdirSync(shared,{recursive:true});
for(const name of ['portal-navigation.js','portal-navigation.css','release.json','menu-new-items.json','rates-and-charges.html','bank-rates.css']){
let content=readFileSync(path.join(web,name));
if(name==='portal-navigation.js')content=Buffer.from(SHARED_FOOTER_SCRIPT+withRealmSwitch(withCanonicalMenu(withMenuBadges(cleanLegacyChromeScript(content.toString('utf8')))))+readFileSync(path.join(web,'realm-design.js'),'utf8'));
if(name==='portal-navigation.js')content=Buffer.from(SHARED_FOOTER_SCRIPT+withRealmSwitch(withCanonicalMenu(withMenuBadges(cleanLegacyChromeScript(content.toString('utf8')))))+sharedRealmRuntime);
if(name==='portal-navigation.css')content=Buffer.concat([content,Buffer.from(HOUSE_STYLE_CSS+REALM_SWITCH_CSS+readFileSync(path.join(web,"realm-comfort.css"),"utf8"))]);
if(name.endsWith('.html'))content=Buffer.from(preparePublicHtml(content.toString('utf8'),name));
writeFileSync(path.join(shared,name),content);

View file

@ -0,0 +1,17 @@
/* Shared host is intentionally isolated from native forum/CP/shop styles. The original
homepage portal.css and sections.css supply the component's actual layout. */
dune-shared-header{display:block!important;width:100%!important;max-width:none!important;margin:0!important;padding:0!important;position:relative!important;z-index:120!important;flex:none!important}
dune-shared-header[hidden]{display:none!important}
:host{display:block;color-scheme:dark;--ink:#071a16;--surface:#102a23;--surface-raised:#17372c;--gold:#c9a85a;--gold-light:#f2d593;--cream:#f5ead0;--muted:#a8b8ac;--line:#6b613d;--font:'DM Sans',Arial,sans-serif;--serif:'Cinzel',Georgia,serif;color:var(--cream);font:16px/1.65 var(--font);text-align:left}
:host .nav-bar{position:relative;z-index:20}
:host [hidden]{display:none!important}
:host .nav-actions .button{min-height:42px;font-size:14px;border-radius:4px;font-family:var(--font);font-weight:700}
:host .shared-account-group{position:relative}
:host .shared-account-group>summary{list-style:none;cursor:pointer}
:host .shared-account-group>.dropdown{right:0;left:auto}
:host .shared-current{color:var(--gold-light);position:relative}
:host .shared-current:after{position:absolute;content:'';height:2px;background:var(--gold);bottom:0;left:16px;right:16px}
:host .nav-home:not([aria-current=page]):after{display:none}
:host .shared-menu-badge{display:inline-block;margin-left:6px;font-size:9px;color:var(--gold-light)}
@media(max-width:850px){:host .shared-account-group{display:none}}
@media(max-width:640px){:host .nav-actions .button{min-height:35px;font-size:11px}}

View file

@ -0,0 +1,73 @@
import {readFileSync} from 'node:fs';
import {MAIN_MENU_GROUPS} from './main-menu.mjs';
const root='https://www.dunerealms.com';
export function homepageHeaderTemplate(html){
const start=html.indexOf('<div class="utility">'),end=html.indexOf('<main');
if(start<0||end<=start)throw Error('Original homepage header missing');
const template=html.slice(start,end).trim();
if(!template.includes('<header class="masthead">')||!template.includes('id="portal-navigation"'))throw Error('Original homepage header invalid');
return template.replace(/(href|src)="\/(?!\/)/g,'$1="'+root+'/');
}
export function mountSharedHomepageHeader(template,groups,root){
if(window.__duneHomepageHeaderMounted||window.top!==window.self)return;
const old=document.querySelector('header.dune-site-header');
const original=document.querySelector('header.masthead');
const utility=(original||old)?.previousElementSibling,bar=(original||old)?.nextElementSibling;
if(!old&&!(original&&utility?.classList.contains('utility')&&bar?.classList.contains('nav-bar')))return;
window.__duneHomepageHeaderMounted=true;
const home=!!document.querySelector('.arrival-grid')&&!!document.querySelector('#play-dialog');
const host=document.createElement('dune-shared-header');host.hidden=true;
const shadow=host.attachShadow({mode:'open'});
const from=location.hostname==='wiki.dunerealms.com'?'':root;
const load=(path)=>{const link=document.createElement('link');link.rel='stylesheet';link.href=from+path;shadow.append(link);return new Promise(resolve=>{link.onload=()=>resolve(true);link.onerror=()=>resolve(false);});};
const loaded=[load('/preview/portal.css'),load('/preview/sections.css'),load('/realm-design.css?v=shared-homepage-header-1')];
const holder=document.createElement('template');holder.innerHTML=template;shadow.append(holder.content);
const nav=shadow.querySelector('#portal-navigation'),toggle=shadow.querySelector('.menu-toggle'),actions=shadow.querySelector('.nav-actions');
// Reuse the original homepage structure, maintaining all PR602 destinations in the matching menu groups.
const addLink=(box,label,href)=>{const a=document.createElement('a');a.href=href;a.textContent=label;box.append(a);};
for(const group of nav.querySelectorAll('details')){
const label=group.querySelector('summary').childNodes[0].textContent.trim();
const box=group.querySelector('.dropdown');
for(const [text,href] of groups[label]||[])if(![...box.querySelectorAll('a')].some(a=>a.href===href))addLink(box,text,href);
}
// Keep the actual account control in its homepage position; its menu preserves the existing shared account routes.
const account=actions.querySelector('.account-link'),accountGroup=document.createElement('details');accountGroup.className='shared-account-group';
const summary=document.createElement('summary');summary.className=account.className;summary.append(...account.childNodes);
const accountBox=document.createElement('div');accountBox.className='dropdown';for(const [label,href] of groups['My Account']||[])addLink(accountBox,label,href);
accountGroup.append(summary,accountBox);account.replaceWith(accountGroup);
const staff=actions.querySelector('[data-staff-access]');
const oldStaff=old?.querySelector('[data-staff-access]')||bar?.querySelector('[data-staff-access]');
if(oldStaff){staff.hidden=oldStaff.hidden;const mirror=new MutationObserver(()=>{staff.hidden=oldStaff.hidden;});mirror.observe(oldStaff,{attributes:true,attributeFilter:['hidden']});setTimeout(()=>mirror.disconnect(),10000);}
const welcome=location.hostname==='cp.dunerealms.com'?'/api/welcome':'https://cp.dunerealms.com/api/welcome';
fetch(welcome,{credentials:'include',cache:'no-store',signal:AbortSignal.timeout(6000)}).then(r=>r.ok?r.json():null).then(context=>{if(context)staff.hidden=context.staffAccess!==true;}).catch(()=>{});
const play=actions.querySelector('[data-play]');play.addEventListener('click',()=>{close();const dialog=document.querySelector('#play-dialog');if(home&&dialog?.showModal)dialog.showModal();else location.href=root+'/install.html';});
const menus=[...shadow.querySelectorAll('details')];
function close(){for(const menu of menus)menu.open=false;nav.classList.remove('open');toggle.setAttribute('aria-expanded','false');}
toggle.addEventListener('click',()=>{const open=toggle.getAttribute('aria-expanded')!=='true';nav.classList.toggle('open',open);toggle.setAttribute('aria-expanded',String(open));});
for(const menu of menus)menu.addEventListener('toggle',()=>{if(menu.open)for(const other of menus)if(other!==menu)other.open=false;});
document.addEventListener('click',e=>{if(!e.composedPath().includes(host))close();});
document.addEventListener('keydown',e=>{if(e.key==='Escape'){const active=menus.find(m=>m.open);close();active?.querySelector('summary').focus();}});
for(const a of shadow.querySelectorAll('a'))a.addEventListener('click',close);
const here=new URL(location.href);
const active=home?'Home':here.hostname==='forums.dunerealms.com'||/\/(discord|staff|community-records|news)/.test(here.pathname)?'Community':here.hostname==='support.dunerealms.com'||here.hostname==='wiki.dunerealms.com'||/\/manual|\/install/.test(here.pathname)?'Discover':here.hostname==='shop.dunerealms.com'||/\/exchange|\/kits/.test(here.pathname)?'Trade':/\/realm-hub/.test(here.pathname)?'The realm':null;
const homeLink=nav.querySelector('.nav-home');if(!home)homeLink.removeAttribute('aria-current');
for(const item of nav.children){if(item.textContent.trim().startsWith(active||'\0')){const current=item.querySelector('summary')||item;current.setAttribute('aria-current','page');current.classList.add('shared-current');}}
// Managed badges remain in shared header links only; the same endpoint remains authoritative.
for(const badge of old?.querySelectorAll('.dune-new-overlay')||[]){const source=badge.closest('a');const target=[...shadow.querySelectorAll('.dropdown a')].find(a=>a.href===source?.href);if(target){const mark=document.createElement('span');mark.className='shared-menu-badge';mark.textContent=badge.textContent;target.append(mark);}}
const badges=location.hostname==='cp.dunerealms.com'?'/api/menu-badges':'https://cp.dunerealms.com/api/menu-badges';
fetch(badges,{cache:'no-store'}).then(r=>r.ok?r.json():null).then(data=>{for(const a of shadow.querySelectorAll('.dropdown a')){const item=data?.items?.find(x=>x.href===a.href);if(['NEW','UPDATE'].includes(item?.badge)){const badge=a.querySelector('.shared-menu-badge')||document.createElement('span');badge.className='shared-menu-badge';badge.textContent=item.badge;if(!badge.parentNode)a.append(badge);}}}).catch(()=>{});
(old||utility).before(host);
Promise.all(loaded).then(results=>{
if(results.some(x=>!x)){host.remove();window.__duneHomepageHeaderMounted=false;return;}
if(old){old.remove();if(utility?.classList.contains('utility'))utility.remove();if(bar?.classList.contains('nav-bar'))bar.remove();}
else{utility.remove();original.remove();bar.remove();}
host.hidden=false;
});
}
export function sharedHomepageHeaderFallback(html=readFileSync(new URL('../web/index.html',import.meta.url),'utf8')){
const template=homepageHeaderTemplate(html).replace('<header class="masthead">','<div class="masthead">').replace('</header>','</div>');
return '<header class="dune-site-header" data-shared-header-source="homepage">'+template+'</header>';
}
export function sharedHomepageHeaderScript(html=readFileSync(new URL('../web/index.html',import.meta.url),'utf8')){
return '\n;('+mountSharedHomepageHeader.toString()+')('+JSON.stringify(homepageHeaderTemplate(html))+','+JSON.stringify(MAIN_MENU_GROUPS)+','+JSON.stringify(root)+');\n';
}

View file

@ -0,0 +1,45 @@
/* MyBB's native content; keep navigation, permissions and forum-state classes intact. */
html body:is(.dune-forum,.dr-native-boards){background:#071b16!important;color:#f4e8ca!important;font:16px/1.65 'DM Sans',Arial,sans-serif!important}
html body:is(.dune-forum,.dr-native-boards) :is(#container,#content,.wrapper){box-sizing:border-box}
html body:is(.dune-forum,.dr-native-boards) #container{width:min(1280px,calc(100% - 48px))!important;max-width:1280px!important;margin-inline:auto!important;border:0!important;background:transparent!important}
html body:is(.dune-forum,.dr-native-boards) #container>.wrapper,
html body:is(.dune-forum,.dr-native-boards) #content>.wrapper{width:100%!important;max-width:none!important;margin:0!important}
html body:is(.dune-forum,.dr-native-boards) #content{padding:0!important;margin:0 auto!important;max-width:none!important;background:transparent!important}
html body:is(.dune-forum,.dr-native-boards) #content>.navigation{margin:4px 0 12px!important;min-height:0!important;color:#b5c4b8!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-category{margin:12px 0 20px!important;border:1px solid #8f773e!important;border-radius:6px!important;background:#102c24!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-heading{padding:13px 18px!important;background:linear-gradient(105deg,#234536,#15342a)!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-heading p{margin:0 0 3px!important;font:10px/1.4 'DM Sans',Arial,sans-serif!important;letter-spacing:.12em}
html body:is(.dune-forum,.dr-native-boards) .dune-board-heading h2{margin:0!important;font:600 22px/1.25 'Cinzel',Georgia,serif!important;color:#f0d89b!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panels{gap:12px!important;padding:12px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panel{border:1px solid #79643b!important;border-radius:5px!important;background:#102c24!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panel-title{padding:10px 14px!important;gap:10px!important;background:#1a3b2e!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panel-title img{width:38px!important;height:38px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panel-title h3{margin:0!important;font:600 18px/1.3 'Cinzel',Georgia,serif!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panel-title p{margin:3px 0 0!important;font:13px/1.4 'DM Sans',Arial,sans-serif!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums th{padding:9px 12px!important;background:#204233!important;color:#f0d89b!important;font-size:12px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums td{padding:9px 12px!important;border-color:#79643b!important;font-size:14px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums td:first-child{width:46px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums .smalltext{font-size:12px!important;line-height:1.45!important;color:#b5c4b8!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums :is(.trow1,.trow2){background:#102c24!important;color:#f4e8ca!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums tr:nth-child(even) td{background:#15362a!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums tr:hover td{background:#1a3b2e!important}
html body:is(.dune-forum,.dr-native-boards) :is(.thead,.tcat,.tfoot,.pagination,.popup_menu,.popup_item_container,.modcp_nav_item,.usercp_nav_item){background-color:#163329!important;border-color:#79643b!important;color:#f0d89b!important;text-shadow:none!important}
html body:is(.dune-forum,.dr-native-boards) :is(.thead,.tcat,.tfoot){background-image:none!important}
html body:is(.dune-forum,.dr-native-boards) :is(.trow1,.trow2,.trow_shaded,.post,.post_content,.post_body,.quote_body,.code_body,.editor,.sceditor-container,.sceditor-toolbar,.sceditor-group,.pm_alert,.forumdisplay_regular,.forumdisplay_sticky){background-color:#102c24!important;color:#f4e8ca!important;border-color:#79643b!important}
html body:is(.dune-forum,.dr-native-boards) :is(.post_author,.post_controls,.post_head,.quote_header,.code_header){background-color:#1a3b2e!important;color:#f4e8ca!important;border-color:#8f773e!important}
html body:is(.dune-forum,.dr-native-boards) :is(input.textbox,textarea,select,.sceditor-container textarea){background:#0a211b!important;color:#f4e8ca!important;border:1px solid #8f773e!important;border-radius:4px!important}
html body:is(.dune-forum,.dr-native-boards) :is(input.button,button.button,a.button){background:linear-gradient(135deg,#f8da8b,#dcb55a 55%,#b28633)!important;color:#242211!important;border:1px solid #c9a85a!important;border-radius:4px!important;font-family:'DM Sans',Arial,sans-serif!important;font-weight:700!important}
html body:is(.dune-forum,.dr-native-boards) :is(.pagination a,.pagination_current,.postbit_buttons a,.popup_item){border-color:#8f773e!important}
html body:is(.dune-forum,.dr-native-boards) :is(.forum_status,.subforumicon){background-size:contain!important;background-position:center!important;background-repeat:no-repeat!important;background-color:transparent!important}
html body:is(.dune-forum,.dr-native-boards) .forum_status{display:inline-block!important;width:30px!important;height:30px!important;vertical-align:middle!important}
html body:is(.dune-forum,.dr-native-boards) .subforumicon{width:16px!important;height:16px!important}
html body:is(.dune-forum,.dr-native-boards) :is(.forum_on,.subforum_minion){background-image:url('https://www.dunerealms.com/assets/forum-status-new.svg')!important}
html body:is(.dune-forum,.dr-native-boards) :is(.forum_off,.subforum_minioff){background-image:url('https://www.dunerealms.com/assets/forum-status-read.svg')!important}
html body:is(.dune-forum,.dr-native-boards) :is(.forum_offclose,.subforum_minioffclose){background-image:url('https://www.dunerealms.com/assets/forum-status-locked.svg')!important}
html body:is(.dune-forum,.dr-native-boards) :is(.forum_offlink,.subforum_miniofflink){background-image:url('https://www.dunerealms.com/assets/forum-status-link.svg')!important}
html body:is(.dune-forum,.dr-native-boards) #footer :is(.upper,.lower){background:#102c24!important;color:#b5c4b8!important;border-color:#8f773e!important}
@media(max-width:760px){
html body:is(.dune-forum,.dr-native-boards) #container{width:calc(100% - 28px)!important;min-width:0!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-panels{padding:8px!important;gap:8px!important}
html body:is(.dune-forum,.dr-native-boards) .dune-board-forums td{padding:7px 5px!important;font-size:12px!important}
}

View file

@ -0,0 +1,60 @@
/* Native osTicket presentation only. The existing ticket controls, forms,
thread markup, permissions and service navigation remain owned by osTicket. */
html body:is(.dune-support,.dr-native-support){
color-scheme:dark;background:#071b16!important;color:#f4e8ca!important;
font:16px/1.65 'DM Sans',Arial,sans-serif!important;
}
html body:is(.dune-support,.dr-native-support) :is(#container,#pjax-container,#content,.content,#ticket_container,#landing_page){
background-color:#0f2921!important;color:#f4e8ca!important;border-color:#79613b!important;
}
html body:is(.dune-support,.dr-native-support) :is(h1,h2,h3,h4,.form-header,.form_table th){
font-family:'Cinzel',Georgia,serif!important;color:#f4e8ca!important;text-shadow:none!important;
}
html body:is(.dune-support,.dr-native-support) :is(h1,h2){font-weight:600!important}
html body:is(.dune-support,.dr-native-support) :is(.dune-support-workspace-hero,.dune-support-card,.search.well,.ticket-info,.ticket_info,.infoTable,.thread-entry,.thread-entry-body,.thread-body,.tab_content,.panel,.card,.well,fieldset){
background-color:#102d24!important;border-color:#8f773e!important;border-radius:6px!important;color:#f4e8ca!important;
}
html body:is(.dune-support,.dr-native-support) :is(.dune-support-workspace-hero,.dune-support-card){border:1px solid #8f773e!important;box-shadow:0 8px 20px #0002!important}
html body:is(.dune-support,.dr-native-support) .dune-support-workspace-hero h1{font-size:clamp(26px,3vw,44px)!important}
html body:is(.dune-support,.dr-native-support) :is(#nav,#sub_nav,.sub_nav,.tabs,.nav-tabs,.dune-support-submenu,.sticky.bar,.queue-actions,.ticket-actions){
background:#102d24!important;border-color:#8f773e!important;color:#f4e8ca!important;box-shadow:none!important;
}
html body:is(.dune-support,.dr-native-support) :is(#nav,#sub_nav,.sub_nav,.tabs,.nav-tabs,.dune-support-submenu) a{color:#f0d89b!important;text-shadow:none!important}
html body:is(.dune-support,.dr-native-support) :is(#nav,#sub_nav,.sub_nav,.tabs,.nav-tabs,.dune-support-submenu) :is(a.active,[aria-current=page],.active>a,.selected>a){
background:#234537!important;border-color:#d3ae5c!important;color:#fff1c8!important;
}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue,table.form_table,table.two-column,table.custom-data,.infoTable){
background:#102c24!important;color:#f4e8ca!important;border-color:#8f773e!important;
}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue,table.form_table,table.two-column,table.custom-data,.infoTable) :is(th,thead td){
background:#204233!important;color:#f0d89b!important;border-color:#79643b!important;text-shadow:none!important;
}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue) tbody tr{background:#102c24!important;color:#f4e8ca!important}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue) tbody tr:nth-child(even){background:#15362a!important}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue) tbody tr:hover{background:#234537!important}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue,table.form_table,table.two-column,table.custom-data,.infoTable) td{
border-color:#79643b!important;color:inherit!important;background-color:transparent!important;
}
html body:is(.dune-support,.dr-native-support) :is(#ticketForm,#reply,#response,#ticketSearchForm,.form_table) :is(label,.required,.form-desc,.help-block,.instructions){color:#d5dfcf!important}
html body:is(.dune-support,.dr-native-support) :is(input:not([type=checkbox]):not([type=radio]):not([type=button]):not([type=submit]):not([type=reset]):not([type=hidden]),textarea,select,.select2-selection,.select2-choice,.select2-choices,.redactor-editor,.redactor-box,.redactor-statusbar){
background:#0a211b!important;color:#f4e8ca!important;border-color:#8f773e!important;border-radius:4px!important;box-shadow:none!important;
}
html body:is(.dune-support,.dr-native-support) :is(input,textarea)::placeholder{color:#b5c4b8!important}
html body:is(.dune-support,.dr-native-support) :is(.redactor-toolbar,.thread-entry .header,.thread-entry .header .title,.thread-entry .avatar,.form-header,.section-break){
background-color:#1a3b2e!important;color:#f4e8ca!important;border-color:#8f773e!important;
}
html body:is(.dune-support,.dr-native-support) :is(.select2-dropdown,.select2-results,.dropdown-menu,.typeahead,.ui-menu,.ui-dialog,.ui-dialog-content,.dialog,.modal,.modal-content,.popup){
background:#112b24!important;color:#f4e8ca!important;border-color:#8f773e!important;
}
html body:is(.dune-support,.dr-native-support) :is(.ui-dialog-titlebar,.modal-header,.dialog .header){background:#204233!important;color:#f0d89b!important;border-color:#8f773e!important}
html body:is(.dune-support,.dr-native-support) :is(.select2-results__option--highlighted,.ui-state-focus,.ui-menu-item:hover,.dropdown-menu a:hover){background:#234537!important;color:#fff1c8!important}
html body:is(.dune-support,.dr-native-support) :is(.button,.btn,input[type=submit],input[type=button],button.primary){
color:#242211!important;background:linear-gradient(135deg,#f8da8b,#dcb55a 55%,#b28633)!important;border:1px solid #c9a85a!important;border-radius:4px!important;font-family:'DM Sans',Arial,sans-serif!important;font-weight:700!important;text-shadow:none!important;
}
html body:is(.dune-support,.dr-native-support) :is(a,button,input,select,textarea):focus-visible{outline:2px solid #f5d48b!important;outline-offset:3px}
html body:is(.dune-support,.dr-native-support) :is(.faded,.muted,.help-block,.instructions,.form-desc){color:#b5c4b8!important}
html body:is(.dune-support,.dr-native-support) :is(.ticket-info,.ticket_info,.thread-entry,.form_table) a:not(.button):not(.btn){color:#f0d89b!important}
@media(max-width:700px){
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue){font-size:13px!important}
html body:is(.dune-support,.dr-native-support) :is(#ticketTable,table.list,table.listings,table.queue) :is(th,td){padding:9px!important}
}

View file

@ -1,4 +1,5 @@
import {applySharedFooter} from './site-chrome.mjs';
import {sharedHomepageHeaderFallback} from './homepage-header.mjs';
import{MAIN_MENU,MAIN_MENU_GROUPS}from'./main-menu.mjs';
export const PORTAL_LINKS=MAIN_MENU;
const menuLink=([name,url,icon,children])=>children?`<details class="dune-menu-group dune-menu-subgroup" data-dune-submenu="${name}"><summary><img src="https://www.dunerealms.com/assets/${icon}" alt="" width="42" height="42"><span>${name}</span></summary><div class="dune-menu-dropdown">${children.map(menuLink).join('')}</div></details>`:`<a href="${url}"><img src="https://www.dunerealms.com/assets/${icon}" alt="" width="42" height="42" decoding="async"><span>${name}</span></a>`;
@ -18,7 +19,7 @@ body>header>.menu-toggle{display:none!important;box-shadow:none;border:1px solid
`;
export function oldUpdatePortalNavigation(html){let updated=html.replace(/<nav aria-label="Main navigation">[\s\S]*?<\/nav>/,PORTAL_NAV);if(updated.includes(PORTAL_NAV)&&!updated.includes('href="https://www.dunerealms.com/portal-navigation.css?v=hosting-9-release-1002"'))updated=updated.replace('</head>','<link rel="stylesheet" href="https://www.dunerealms.com/portal-navigation.css?v=hosting-9-release-1002"></head>');return updated;}
export const SHARED_HEADER='<header class="dune-site-header" data-realm-design="every-page-1"><div class="dr-header-utility"><span>◆ MINECRAFT / JAVA + BEDROCK</span><span><a href="https://support.dunerealms.com/">Support</a><a href="https://cp.dunerealms.com/">My account</a></span></div><div class="dr-header-brand"><span class="dr-masthead-caption left">THE CARAVAN ENDURES</span><span class="dr-masthead-caption right">WRITE YOUR CHAPTER</span><a class="wordmark" href="https://www.dunerealms.com/" target="_top"><img class="masthead-logo" src="https://www.dunerealms.com/assets/dunerealms-season-logo-v2.webp" alt="DuneRealms — The Quest for Tavren II Aedrecht" width="450" height="164"></a></div><div class="dr-header-bar"><button class="menu-toggle" type="button" aria-label="Open navigation" aria-expanded="false">Menu ☰</button>'+PORTAL_NAV+'<a class="dr-header-account" href="https://www.dunerealms.com/install.html"><img src="https://www.dunerealms.com/assets/nav-home-v2.webp" alt="" width="26" height="28">Play now</a></div></header>';
export const SHARED_HEADER=sharedHomepageHeaderFallback();
export const SHARED_HEAD='<link rel="stylesheet" href="https://www.dunerealms.com/realm-comfort.css"><link rel="stylesheet" href="/portal-navigation.css"><script src="/portal-navigation.js" defer></script><link rel="stylesheet" data-realm-design href="https://www.dunerealms.com/realm-design.css?v=every-page-1"><script src="https://www.dunerealms.com/realm-design.js?v=every-page-1" defer></script>';
export const PORTAL_SCRIPT=`(()=>{let menuIndex=0;for(const header of document.querySelectorAll('.dune-site-header')){if(window.top!==window.self){header.hidden=true;continue;}const toggle=header.querySelector('.menu-toggle'),nav=header.querySelector('nav');if(!toggle||!nav)continue;if(!nav.id){do{nav.id='dune-main-navigation-'+(++menuIndex);}while(document.getElementById(nav.id)!==nav);}toggle.setAttribute('aria-controls',nav.id);const setOpen=open=>{nav.classList.toggle('open',open);toggle.setAttribute('aria-expanded',String(open));toggle.setAttribute('aria-label',open?'Close navigation':'Open navigation');};setOpen(nav.classList.contains('open'));toggle.addEventListener('click',event=>{event.stopImmediatePropagation();setOpen(!nav.classList.contains('open'));},true);header.addEventListener('keydown',event=>{if(event.key==='Escape'&&nav.classList.contains('open')){event.preventDefault();setOpen(false);toggle.focus();}});for(const a of nav.querySelectorAll('a')){const url=new URL(a.href);if(url.host===location.host&&url.pathname===location.pathname&&url.hash===location.hash)a.setAttribute('aria-current','page');}}})();`;
export function updatePortalNavigation(html){

View file

@ -9,12 +9,12 @@ export function applySharedFooter(html){
}
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){
export function applySharedHeader(html,header,label){
if(/<header\b[^>]*class="[^"]*dune-site-header/.test(html))return html.replace(/<header\b[^>]*class="[^"]*dune-site-header[^"]*"[^>]*>[\s\S]*?<\/header>/,header);
// Homepage content/dialogs stay intact; only its formerly separate masthead/navigation are replaced.
// Non-homepage legacy mastheads are compiled into the shared header as before.
if(html.includes('<header class="masthead">')){
const start=html.indexOf('<div class="utility">'),end=html.indexOf('<main');
if(start<0||end<start)throw Error('Homepage chrome boundary missing');
if(start<0||end<start)throw Error('Legacy chrome boundary missing');
return html.slice(0,start)+header.replace('class="dr-header-account"','class="dr-header-account" data-play')+'\n'+html.slice(end);
}
return html;
@ -26,6 +26,7 @@ export function assertSharedChrome(html,header,label='document'){
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;
}

View file

@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFile} from 'node:fs/promises';
import {sharedHomepageHeaderScript} from '../scripts/homepage-header.mjs';
import {LocalD1} from './d1-adapter.mjs';
import {createPanel} from '../control-panel/server.mjs';
import {NATIVE_SERVICES,nativeServiceAccess} from '../control-panel/public/cp-v2/cp-v2-native-services.mjs';
@ -10,7 +11,7 @@ test('actual CP router serves the dedicated clan page and assets without requiri
try{
for(const [file,mime]of [['clan-center.html','text/html'],['clan-center-entry.mjs','javascript'],['clan-center.css','text/css'],['v2/cp-v2-realm-design.mjs','javascript']]){
const response=await app(new Request('https://cp.dunerealms.com/'+file));assert.equal(response.status,200,file);assert.ok(response.headers.get('content-type').includes(mime));
if(file==='v2/cp-v2-realm-design.mjs')assert.equal(await response.text(),await readFile(new URL('../web/realm-design.js',import.meta.url),'utf8'));
if(file==='v2/cp-v2-realm-design.mjs')assert.equal(await response.text(),(await readFile(new URL('../web/realm-design.js',import.meta.url),'utf8'))+sharedHomepageHeaderScript());
if(file.endsWith('.html')){const html=await response.text();assert.match(html,/id="dashboard"/);assert.doesNotMatch(html,/v2\/v2\.js|src="\/panel\.js"|id="portals"/);}
}
}finally{db.close();}

View file

@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import {readFileSync,readdirSync} from 'node:fs';
import {applySharedHeader,applySharedFooter,SHARED_FOOTER,assertSharedChrome} from '../scripts/site-chrome.mjs';
import {SHARED_HEADER} from '../scripts/portal-navigation.mjs';
import {homepageHeaderTemplate,sharedHomepageHeaderScript,sharedHomepageHeaderFallback} from '../scripts/homepage-header.mjs';
test('shared chrome replaces legacy navigation without changing page forms or dialogs',()=>{
const content='<main id="content"><form id="payment"><input name="amount"></form></main><dialog id="play-dialog"></dialog>';
const old='<html><body><header class="dune-site-header"><nav>Old</nav></header>'+content+'<footer>Old footer</footer></body></html>';
@ -10,9 +11,18 @@ test('shared chrome replaces legacy navigation without changing page forms or di
assert(next.includes(content));assert(next.includes(SHARED_HEADER));assert(next.includes(SHARED_FOOTER));assert(!next.includes('Old footer'));
assert.equal(applySharedFooter(applySharedHeader(next,SHARED_HEADER)),next);
});
test('homepage and interior pages receive the same header while homepage play dialog remains connected',()=>{
const source=readFileSync(new URL('../web/index.html',import.meta.url),'utf8');const next=applySharedHeader(source,SHARED_HEADER);
assert.equal((next.match(/class="dune-site-header"/g)||[]).length,1);assert(!next.includes('class="masthead"'));assert(!next.includes('class="nav-bar"'));assert(next.includes('data-play'));assert(next.includes('id="play-dialog"'));assert(next.includes('id="world-dialog"'));
test('homepage retains its original header and dropdowns while sharing the footer',()=>{
const source=readFileSync(new URL('../web/index.html',import.meta.url),'utf8');
const next=applySharedFooter(applySharedHeader(source,SHARED_HEADER,'index.html'));
assert(next.includes(SHARED_HEADER));
assert.equal(SHARED_HEADER,sharedHomepageHeaderFallback(source));
assert(SHARED_HEADER.includes(homepageHeaderTemplate(source).replace('<header class="masthead">','<div class="masthead">').replace('</header>','</div>')));
assert(sharedHomepageHeaderScript(source).includes(JSON.stringify(homepageHeaderTemplate(source))));
assert(next.includes('id="portal-navigation"'));assert(next.includes('data-play'));assert(next.includes('id="play-dialog"'));assert(next.includes('id="world-dialog"'));
assert.equal(assertSharedChrome(next,SHARED_HEADER,'index.html'),next);
assert.throws(()=>assertSharedChrome(next.replace('<main','<section class="dr-page-banner"></section><main'),SHARED_HEADER,'index.html'));
assert.throws(()=>assertSharedChrome(next.replace('<main',SHARED_HEADER+'<main'),SHARED_HEADER,'index.html'));
assert(applySharedHeader(source,SHARED_HEADER,'preview/portal.html').includes('class="dune-site-header"'));
});
test('footer replacement retains memorial artwork and preserves separate legal content',()=>{
const memorial='<aside class="dune-memorial"><img src="seal.png"><blockquote>Existing text</blockquote></aside>',legal='<aside class="legal-notice">Legal text</aside>';

View file

@ -0,0 +1,46 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {sharedHomepageHeaderFallback,sharedHomepageHeaderScript,homepageHeaderTemplate} from '../scripts/homepage-header.mjs';
import {SHARED_HEADER} from '../scripts/portal-navigation.mjs';
import {MAIN_MENU_GROUPS} from '../scripts/main-menu.mjs';
const read=path=>readFileSync(new URL('../'+path,import.meta.url),'utf8');
test('Template Fix 6000 generates one shared header from the original homepage and retains PR602 menu destinations',()=>{
const original=read('web/index.html'),runtime=sharedHomepageHeaderScript(original);
assert.equal(SHARED_HEADER,sharedHomepageHeaderFallback(original));
assert(runtime.includes(JSON.stringify(homepageHeaderTemplate(original))));
assert(runtime.includes(JSON.stringify(MAIN_MENU_GROUPS)));
assert.doesNotThrow(()=>new Function(runtime));
assert.match(runtime,/window\.top!==window\.self/);
assert.match(runtime,/context\.staffAccess!==true/);
assert.match(runtime,/dialog\.showModal\(\)/);
});
test('native support keeps the authored workspace intro and native themes do not target unrelated sites',()=>{
assert.match(read('web/realm-design.js'),/\.arrival-grid,\.dune-support-workspace-hero/);
const support=read('scripts/osticket-presentation.css');
for(const selector of ['#ticketTable','#ticketForm','.thread-entry','.redactor-editor','.ui-dialog','.queue'])assert(support.includes(selector));
assert.match(support,/body:is\(\.dune-support,\.dr-native-support\)/);
assert.doesNotMatch(support,/display:\s*none/);
});
test('native forum status artwork maps every actual MyBB state and board shortcuts are only a no-row fallback',()=>{
const css=read('scripts/mybb-presentation.css'),sections=read('integrations/mybb/inc/plugins/dune_sections.php');
for(const [state,icon]of [['forum_on','new'],['forum_off','read'],['forum_offclose','locked'],['forum_offlink','link']]){
assert(css.includes('.'+state));
assert(css.includes('forum-status-'+icon+'.svg'));
assert.match(read('web/assets/forum-status-'+icon+'.svg'),/^<svg /);
}
assert(!sections.includes('Subcategories</span>'));
assert.match(sections,/if\(\$rows&&!empty\(\$rows\['forum_list'\]\)\)/);
assert.match(sections,/else if\(\$children\).*dune_sections_links\(\$children\)/);
assert.match(sections,/forum_permissions/);
assert.match(sections,/forum_password_validated/);
});
test('native publisher and website build publish the same header and both presentation styles',()=>{
const build=read('scripts/build.mjs'),pub=read('ops/publish-realm-design.py');
for(const name of ['homepage-header.css','osticket-presentation.css','mybb-presentation.css']){
assert(build.includes(name));assert(pub.includes(name));
}
assert(build.includes('sharedHomepageHeaderScript()'));
assert(pub.includes('data-shared-header-source="homepage"'));
assert(pub.includes('mybb/inc/plugins/dune_sections.php'));
});

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M32 3 56 16v24L32 61 8 40V16Z" fill="#264a3d" stroke="#d4b16b" stroke-width="3"/><path d="M32 9 50 20v17L32 53 14 37V20Z" fill="none" stroke="#d4b16b" stroke-width="1.5" opacity=".65"/><path d="M18 32h25m-8-8 9 8-9 8" fill="none" stroke="#f2d38a" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>

After

Width:  |  Height:  |  Size: 388 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M32 3 56 16v24L32 61 8 40V16Z" fill="#234336" stroke="#c7a75c" stroke-width="3"/><path d="M32 9 50 20v17L32 53 14 37V20Z" fill="none" stroke="#c7a75c" stroke-width="1.5" opacity=".65"/><rect x="21" y="30" width="22" height="16" rx="3" fill="#ad893d" stroke="#efd38b" stroke-width="2"/><path d="M26 30v-5a6 6 0 0 1 12 0v5" fill="none" stroke="#efd38b" stroke-width="3"/><circle cx="32" cy="37" r="2" fill="#17281e"/></svg>

After

Width:  |  Height:  |  Size: 491 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M32 3 56 16v24L32 61 8 40V16Z" fill="#ba8c36" stroke="#f7dc8e" stroke-width="3"/><path d="M32 9 50 20v17L32 53 14 37V20Z" fill="none" stroke="#f7dc8e" stroke-width="1.5" opacity=".65"/><path d="m32 17 3.5 10.5L46 31l-10.5 3.5L32 45l-3.5-10.5L18 31l10.5-3.5Z" fill="#fff1b0" stroke="#3c2b15" stroke-width="1.5"/></svg>

After

Width:  |  Height:  |  Size: 387 B

View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><path d="M32 3 56 16v24L32 61 8 40V16Z" fill="#193c30" stroke="#9d9a65" stroke-width="3"/><path d="M32 9 50 20v17L32 53 14 37V20Z" fill="none" stroke="#9d9a65" stroke-width="1.5" opacity=".65"/><path d="M20 26h24v13H20z" fill="#395c47" stroke="#acb68b" stroke-width="2"/><path d="M24 30h16M24 35h10" stroke="#c6c6a3" stroke-width="2"/></svg>

After

Width:  |  Height:  |  Size: 402 B

View file

@ -32,13 +32,14 @@
}
const memorial=header?.querySelector('.dune-memorial'),footer=document.querySelector('body>footer,.dune-shared-footer');if(memorial&&footer)footer.append(memorial);
// The host page owns one banner; embedded services keep their content width.
if(!embedded&&!workspace&&!document.querySelector('.dr-page-banner,.section-banner')&&header){
if(!embedded&&!workspace&&!document.querySelector('.arrival-grid,.dune-support-workspace-hero')&&!document.querySelector('.dr-page-banner,.section-banner')&&header){
const main=document.querySelector('main,#content,#main-content,.main-content,#container>#content');
const title=document.querySelector('main h1,.main-content h1,#content h1'),label=title?.textContent.trim()||document.title.replace(/\s*[|—·]\s*DuneRealms.*$/i,'').trim();
if(main&&(title||nativeHost)){const banner=document.createElement('section');banner.className='dr-page-banner';const icon=document.createElement('img');icon.src=root+'/assets/'+({boards:'nav-boards-v2.webp',support:'nav-support-v2.webp',shop:'nav-shop-v1.webp',wiki:'nav-manual-v2.webp',git:'nav-manual-v2.webp',mail:'nav-support-v2.webp'})[nativeHost||'wiki'];icon.alt='';icon.width=80;icon.height=92;const content=document.createElement('div');const crumbs=document.createElement('div');crumbs.className='dr-breadcrumb';const home=document.createElement('a');home.href=root+'/';home.textContent='DuneRealms';crumbs.append(home,document.createTextNode(' / '+label));const heading=document.createElement('h1');heading.textContent=label;content.append(crumbs,heading);banner.append(icon,content);main.before(banner);main.classList.add('dr-page-content');document.body.classList.add('dr-interior');}
}
if(nativeHost==='wiki'&&!embedded){const main=document.querySelector('.mw-body,#content,.main-content');if(main&&!document.querySelector('.dr-wiki-placeholder')){const notice=document.createElement('section');notice.className='dr-wiki-placeholder';const heading=document.createElement('h2');heading.textContent='The Dunopedia is being updated';const copy=document.createElement('p');copy.textContent='The existing wiki is an archive and may describe outdated features. Updated guides will be published here.';const link=document.createElement('a');link.href=root+'/manual.html';link.textContent='Open the player field manual →';notice.append(heading,copy,link);main.prepend(notice);}}
function polishContent(){
if(nativeHost==='boards'){const nav=document.querySelector('#content>.navigation');if(nav&&document.querySelector('.dune-board-category')&&nav.textContent.trim()==='DuneRealms Forums'&&nav.querySelectorAll('a').length<=1)nav.hidden=true;for(const status of document.querySelectorAll('.forum_status[title],.subforumicon[title]')){const label=status.title;if(status.getAttribute('aria-label')!==label)status.setAttribute('aria-label',label);if(!status.classList.contains('ajax_mark_read'))status.setAttribute('role','img');}}
const account=header?.querySelector('nav [data-dune-nav-group="My Account"]');if(account){account.classList.add('dr-account-menu');header.querySelector('.dr-header-bar>.dr-nav-account:not(.dr-staff-link)')?.remove();}
if(document.querySelector('.dr-page-banner'))for(const h of document.querySelectorAll('main h1'))if(!h.classList.contains('dr-content-title')){h.classList.add('dr-content-title');h.setAttribute('role','heading');h.setAttribute('aria-level','2');}
// Keep calendar, editor and data-grid table structures under their owners.