diff --git a/website/integrations/SHARED-HEADER-362.md b/website/integrations/SHARED-HEADER-362.md new file mode 100644 index 00000000..ad1b5ba3 --- /dev/null +++ b/website/integrations/SHARED-HEADER-362.md @@ -0,0 +1,7 @@ +# Shared canonical main menu —362 + +One11-link source: Home, Shop, Boards, Staff roster, Discord, Exchange, Kit Exchange, Support center, Account center, Clan center, Dunopedia. Build/publish helpers use this list. Runtime normalisation repairs legacy order/missing/duplicate links while preserving existing anchor/badge objects. Native PHP consumes a generated main-navigation fragment; inner application menus, logos and memorial blocks stay untouched. + +Already scoped-deployed4November;5November verification completed, no stale full rebuild or new production mutation. API/runtime suffix was byte-preserved by scoped publication. Backup/root/ticket362-before-20261104. Later Support368/364 and account changes retained. + +17 focused tests passed. Actual authenticated HTTP checks:9surfaces(home,bans,profile,shop,CP,Support,Forums,Clans,Wiki) allHTTP200/exact11orderedhrefs/11icons. Native Support scriptproxy returnscanonical marker andCache-Control:no-store. RealSupportbrowser1280px:11loadedicons,Shopsecond,nooverflow,hamburgerhidden;390px:opens/closes,Escape restoresfocus,nooverflow. Screenshotsoutput/ticket362-final-20261105/header-{desktop,mobile}.png. No payment/permission/game changes. Source-review merge and native completion evidence in task362. diff --git a/website/integrations/common/shared-header.php b/website/integrations/common/shared-header.php index 912a59ed..3bfd6592 100644 --- a/website/integrations/common/shared-header.php +++ b/website/integrations/common/shared-header.php @@ -13,7 +13,8 @@ function dune_shared_header($html) { $html=str_ireplace('',$head.'',$html); } if(!str_contains($html,'class="dune-memorial"')&&is_file($base.'shared-memorial.html'))$html=preg_replace_callback('/
/',fn($m)=>str_replace('
',file_get_contents($base.'shared-memorial.html').'',$m[0]),$html,1); - $html=preg_replace('~https://www\.dunerealms\.com/portal-navigation\.(js|css)(?:\?[^\"\s>]*)?~','/dune-navigation.$1?v=shared-20261102',$html); + if(is_file($base.'shared-main-menu.html'))$html=preg_replace('~]*aria-label=["\']Main navigation["\'])[^>]*>[\s\S]*?~',file_get_contents($base.'shared-main-menu.html'),$html); + $html=preg_replace('~https://www\.dunerealms\.com/portal-navigation\.(js|css)(?:\?[^\"\s>]*)?~','/dune-navigation.$1?v=canonical-362',$html); if(($_SERVER['HTTP_HOST']??'')==='support.dunerealms.com'&&!str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))$html=str_ireplace('','',$html); if(($_SERVER['HTTP_HOST']??'')==='support.dunerealms.com'){ $html=str_ireplace('','',$html); @@ -29,7 +30,7 @@ function dune_shared_header($html) { } // DuneRealms native MyBB surface polish if(($_SERVER['HTTP_HOST']??'')==='forums.dunerealms.com'){ - $html=str_replace('/dune-navigation.js?v=shared-20261102','/dune-navigation.js?v=shared-20261102',$html); + $html=str_replace('/dune-navigation.js?v=canonical-362','/dune-navigation.js?v=canonical-362',$html); $html=str_ireplace('','',$html); $html=preg_replace_callback('/]*)>/i',function($m){$attrs=$m[1];if(preg_match('/\bclass=["\']([^"\']*)["\']/i',$attrs))$attrs=preg_replace('/\bclass=(["\'])([^"\']*)\1/i','class="$2 dune-forum"',$attrs,1);else $attrs.=' class="dune-forum"';return '';},$html,1); } diff --git a/website/scripts/build-portal-navigation.mjs b/website/scripts/build-portal-navigation.mjs index 6eee84d2..6b0f1308 100644 --- a/website/scripts/build-portal-navigation.mjs +++ b/website/scripts/build-portal-navigation.mjs @@ -1,3 +1,4 @@ +import{CANONICAL_MENU_SCRIPT}from'./main-menu.mjs'; import{recordPageUpdates,menuBadgeScript}from'./menu-updates.mjs'; import {RELEASE_SCRIPT,RELEASE_CSS} from './release-branding.mjs'; import {BUTTON_CSS,BUTTON_SCRIPT} from './dune-buttons.mjs'; @@ -6,7 +7,7 @@ import {updatePortalNavigation,PORTAL_CSS,PORTAL_SCRIPT,CONTEXT_SCRIPT,CONTEXT_C const web=new URL('../web/',import.meta.url); writeFileSync(new URL('portal-navigation.css',web),PORTAL_CSS+CONTEXT_CSS+BUTTON_CSS+RELEASE_CSS); recordPageUpdates(); -writeFileSync(new URL('portal-navigation.js',web),PORTAL_SCRIPT+CONTEXT_SCRIPT+BUTTON_SCRIPT+RELEASE_SCRIPT+menuBadgeScript()); +writeFileSync(new URL('portal-navigation.js',web),PORTAL_SCRIPT+CONTEXT_SCRIPT+BUTTON_SCRIPT+RELEASE_SCRIPT+menuBadgeScript()+CANONICAL_MENU_SCRIPT); writeFileSync(new URL('dune-actions.css',web),BUTTON_CSS); writeFileSync(new URL('dune-actions.js',web),BUTTON_SCRIPT); for(const file of readdirSync(web).filter(f=>f.endsWith('.html'))){const url=new URL(file,web),before=readFileSync(url,'utf8'),after=updatePortalNavigation(before);if(after!==before)writeFileSync(url,after);} diff --git a/website/scripts/build.mjs b/website/scripts/build.mjs index f48bf7c2..64e977d6 100644 --- a/website/scripts/build.mjs +++ b/website/scripts/build.mjs @@ -1,8 +1,9 @@ +import{withCanonicalMenu}from'./main-menu.mjs'; import{recordPageUpdates,patchMenuBadges}from'./menu-updates.mjs'; // Package the authored web and worker sources without rewriting their content. import {readFileSync,writeFileSync,readdirSync,statSync,mkdirSync,existsSync,rmSync,cpSync} from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url'; const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'),web=path.join(root,'web'),dist=path.join(root,'dist'); -recordPageUpdates({root});patchMenuBadges(root); +recordPageUpdates({root});patchMenuBadges(root);writeFileSync(path.join(web,'portal-navigation.js'),withCanonicalMenu(readFileSync(path.join(web,'portal-navigation.js'),'utf8'))); const assets={};const types={'.html':'text/html; charset=utf-8','.css':'text/css; charset=utf-8','.js':'text/javascript; charset=utf-8','.json':'application/json; charset=utf-8','.webp':'image/webp','.png':'image/png','.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 type=types[path.extname(entry)];if(!type)throw Error('Unexpected asset: '+entry);assets['/'+path.relative(web,p).split(path.sep).join('/')]=[type,readFileSync(p).toString('base64')]}}}collect(web); let api=['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(/export /g,'')).join('\n');let runtime=readFileSync(path.join(root,'worker/runtime.mjs'),'utf8').replace(/^import .*;$/gm,''); diff --git a/website/scripts/deploy-canonical-menu.mjs b/website/scripts/deploy-canonical-menu.mjs new file mode 100644 index 00000000..0aec9e44 --- /dev/null +++ b/website/scripts/deploy-canonical-menu.mjs @@ -0,0 +1,14 @@ +// Scoped publication: retain every existing runtime/API byte outside the asset map. +import{readFileSync,writeFileSync,existsSync,mkdirSync}from'node:fs';import{createHash}from'node:crypto';import path from'node:path';import{fileURLToPath}from'node:url';import{withCanonicalMenu}from'./main-menu.mjs';import{PORTAL_NAV}from'./portal-navigation.mjs'; +const navPattern=/]*aria-label=["']Main navigation["'])[^>]*>[^]*?<\/nav>/g; +export function canonicalHeaderHtml(html){return html.replace(navPattern,PORTAL_NAV).replace(/(?:portal-navigation|dune-navigation)\.js\?v=[a-zA-Z0-9_.-]+/g,m=>m.split('?')[0]+'?v=canonical-362');} +export function deployCanonicalMenu({release,nativeRoot,backupDir,extraFiles=[]}){ + for(const p of[release,backupDir,...(nativeRoot?[nativeRoot]:[])])if(!path.isAbsolute(p))throw Error('Absolute paths required');mkdirSync(backupDir,{recursive:true,mode:0o700});const changed=[]; + const save=(file,content,key)=>{if(existsSync(file)){const old=readFileSync(file);if(old.equals(Buffer.from(content)))return;const backup=path.join(backupDir,key);mkdirSync(path.dirname(backup),{recursive:true});if(!existsSync(backup))writeFileSync(backup,old,{mode:0o600});}writeFileSync(file,content,{mode:0o644});changed.push(file);}; + const worker=path.join(release,'dist/server/index.js'),before=readFileSync(worker,'utf8'),prefix='const ASSET_DATA=',end=before.indexOf(';\n');if(!before.startsWith(prefix)||end<0)throw Error('Unknown asset bundle');const assets=JSON.parse(before.slice(prefix.length,end));if(!assets['/portal-navigation.js'])throw Error('No shared script');const script=withCanonicalMenu(Buffer.from(assets['/portal-navigation.js'][1],'base64').toString());assets['/portal-navigation.js'][1]=Buffer.from(script).toString('base64');let pages=0;for(const asset of Object.values(assets))if(asset[0].startsWith('text/html')){const old=Buffer.from(asset[1],'base64').toString(),next=canonicalHeaderHtml(old);if(next!==old){asset[1]=Buffer.from(next).toString('base64');pages++;}} + const after=prefix+JSON.stringify(assets)+before.slice(end);save(worker,after,'worker.js');save(path.join(release,'web/portal-navigation.js'),script,'web-script.js'); + for(const file of[path.join(release,'control-panel/public/index.html'),path.join(release,'node/public/forums.html'),...extraFiles])if(existsSync(file))save(file,canonicalHeaderHtml(readFileSync(file,'utf8')),'templates/'+createHash('sha256').update(file).digest('hex')+'.html'); + if(nativeRoot){save(path.join(nativeRoot,'shared-main-menu.html'),PORTAL_NAV,'shared-main-menu.html');for(const name of['shared-header.html','shared-header-head.html']){const file=path.join(nativeRoot,name);if(existsSync(file))save(file,canonicalHeaderHtml(readFileSync(file,'utf8')),name);}} + const apiUnchanged=createHash('sha256').update(before.slice(end)).digest('hex')===createHash('sha256').update(after.slice(after.indexOf(';\n'))).digest('hex');if(!apiUnchanged)throw Error('Runtime tail changed');return{changed,pages,apiUnchanged}; +} +if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){const[release,nativeRoot,backupDir]=process.argv.slice(2);console.log(JSON.stringify(deployCanonicalMenu({release,nativeRoot,backupDir,extraFiles:['/home/dunerealms/htdocs/clans.dunerealms.com/index.html']})));} diff --git a/website/scripts/deploy-portal-navigation.mjs b/website/scripts/deploy-portal-navigation.mjs index d77cf7a4..17db6f9e 100644 --- a/website/scripts/deploy-portal-navigation.mjs +++ b/website/scripts/deploy-portal-navigation.mjs @@ -1,3 +1,4 @@ +import{CANONICAL_MENU_SCRIPT}from'./main-menu.mjs'; import {RELEASE_SCRIPT,RELEASE_CSS} from './release-branding.mjs'; import {BUTTON_CSS,BUTTON_SCRIPT} from './dune-buttons.mjs'; // Apply only the menu to an already-built release, leaving all other assets and APIs intact. @@ -12,7 +13,7 @@ const assets=JSON.parse(text.slice(prefix.length,end));let changed=0; for(const entry of Object.values(assets)){if(!entry[0].startsWith('text/html'))continue;const html=Buffer.from(entry[1],'base64').toString(),updated=updatePortalNavigation(html);if(html!==updated){entry[1]=Buffer.from(updated).toString('base64');changed++;}} if(!Object.values(assets).some(a=>a[0].startsWith('text/html')&&Buffer.from(a[1],'base64').toString().includes('Main navigation')))throw Error('No menus found'); assets['/portal-navigation.css']=['text/css; charset=utf-8',Buffer.from(PORTAL_CSS+'header.dune-site-header[hidden]{display:none!important}'+(withContext?CONTEXT_CSS:'')+BUTTON_CSS+RELEASE_CSS).toString('base64')]; -assets['/portal-navigation.js']=['text/javascript; charset=utf-8',Buffer.from(PORTAL_SCRIPT+(withContext?CONTEXT_SCRIPT:'')+BUTTON_SCRIPT+RELEASE_SCRIPT).toString('base64')]; +assets['/portal-navigation.js']=['text/javascript; charset=utf-8',Buffer.from(PORTAL_SCRIPT+(withContext?CONTEXT_SCRIPT:'')+BUTTON_SCRIPT+RELEASE_SCRIPT+CANONICAL_MENU_SCRIPT).toString('base64')]; for(const [name,,icon]of (await import('./portal-navigation.mjs')).PORTAL_LINKS)for(const asset of [icon,icon.replace('-v2.webp','-full-v2.webp')]){const file=release+'/web/assets/'+asset;if(!existsSync(file))throw Error('Missing navigation artwork: '+name);assets['/assets/'+asset]=['image/webp',readFileSync(file).toString('base64')];} assets['/assets/vaerkring-network-title-v1.webp']=['image/webp',readFileSync(release+'/web/assets/vaerkring-network-title-v1.webp').toString('base64')]; for(const asset of ['dunerealms-season-logo-v2.png','dunerealms-season-logo-v2.webp','seals/master-imperial-300.png']){const path=release+'/web/assets/'+asset;if(existsSync(path))assets['/assets/'+asset]=[asset.endsWith('.webp')?'image/webp':'image/png',readFileSync(path).toString('base64')];} diff --git a/website/scripts/main-menu.mjs b/website/scripts/main-menu.mjs new file mode 100644 index 00000000..5b57d123 --- /dev/null +++ b/website/scripts/main-menu.mjs @@ -0,0 +1,9 @@ +export const MAIN_MENU=[['Home','https://www.dunerealms.com/','nav-home-v2.webp'],['Shop','https://www.dunerealms.com/shop.html','nav-shop-v1.webp'],['Boards','https://forums.dunerealms.com/','nav-boards-v2.webp'],['Staff roster','https://www.dunerealms.com/staff.html','nav-staff-v2.webp'],['Discord','https://www.dunerealms.com/discord.html','nav-discord-v2.webp'],['Exchange','https://www.dunerealms.com/exchange.html','nav-exchange-v2.webp'],['Kit Exchange','https://www.dunerealms.com/kits.html','items/office_water.png'],['Support center','https://support.dunerealms.com/','nav-support-v2.webp'],['Account center','https://cp.dunerealms.com/','nav-account-v2.webp'],['Clan center','https://clans.dunerealms.com/','nav-clan-v2.webp'],['Dunopedia','https://wiki.dunerealms.com/','nav-manual-v2.webp']]; +export function canonicalMenuHref(value){const u=new URL(value,'https://www.dunerealms.com');if(u.hostname==='dunerealms.com')u.hostname='www.dunerealms.com';if(u.hostname==='www.dunerealms.com'&&/^\/(manual|wiki)\.html$/.test(u.pathname))return'https://wiki.dunerealms.com/';if(u.hostname==='cp.dunerealms.com'&&u.pathname==='/'){if(u.hash==='#shop')return'https://www.dunerealms.com/shop.html';if(u.hash==='#exchange')return'https://www.dunerealms.com/exchange.html';}if(['forums','support','cp','clans','wiki'].some(h=>u.hostname===h+'.dunerealms.com'))return u.origin+'/';return u.origin+(u.pathname==='/index.html'?'/':u.pathname);} +export function normalizeMainMenus(doc,currentUrl,links=MAIN_MENU){let changes=0;const set=(node,key,value)=>{if(node.getAttribute(key)!==value){node.setAttribute(key,value);changes++;}}; + for(const nav of doc.querySelectorAll('header nav[aria-label="Main navigation"]')){const old=[...nav.querySelectorAll('a')],ordered=[];for(const[name,href,icon]of links){let a=old.find(x=>!ordered.includes(x)&&canonicalMenuHref(x.href)===href);if(!a){a=doc.createElement('a');changes++;}set(a,'href',href);let image=a.querySelector('img');if(!image){image=doc.createElement('img');a.insertBefore(image,a.firstChild);changes++;}set(image,'src','https://www.dunerealms.com/assets/'+icon);set(image,'alt','');set(image,'width','34');set(image,'height','34');let label=[...a.children].find(x=>x.tagName==='SPAN'&&!x.classList.contains('dune-new-overlay')&&!x.classList.contains('dune-sales-overlay'));if(!label){label=doc.createElement('span');a.append(label);changes++;}set(label,'data-dune-nav-label','1');if(label.textContent!==name){label.textContent=name;changes++;}for(const n of [...a.childNodes])if(n.nodeType===3){n.remove();changes++;}const active=canonicalMenuHref(currentUrl)===href;if(active)set(a,'aria-current','page');else if(a.hasAttribute('aria-current')){a.removeAttribute('aria-current');changes++;}ordered.push(a);} + for(const a of old)if(!ordered.includes(a)){a.remove();changes++;}let cursor=nav.firstElementChild;for(const a of ordered){if(a!==cursor){nav.insertBefore(a,cursor);changes++;}cursor=a.nextElementSibling;}} + return changes; +} +export const CANONICAL_MENU_SCRIPT='\n/* Dune canonical menu begin */\n(()=>{if(window.top!==window.self)return;const MAIN_MENU='+JSON.stringify(MAIN_MENU)+';const canonicalMenuHref='+canonicalMenuHref.toString()+';const normalizeMainMenus='+normalizeMainMenus.toString()+';const sync=()=>normalizeMainMenus(document,location.href,MAIN_MENU);sync();new MutationObserver(sync).observe(document.body,{childList:true,subtree:true});})();\n/* Dune canonical menu end */\n'; +export function withCanonicalMenu(script){return script.replace(/\n?\/\* Dune canonical menu begin \*\/[^]*?\/\* Dune canonical menu end \*\/\n?/g,'')+CANONICAL_MENU_SCRIPT;} diff --git a/website/scripts/portal-navigation.mjs b/website/scripts/portal-navigation.mjs index bd3b0dc1..5e85b341 100644 --- a/website/scripts/portal-navigation.mjs +++ b/website/scripts/portal-navigation.mjs @@ -1,4 +1,5 @@ -export const PORTAL_LINKS=[["Home","https://www.dunerealms.com/","nav-home-v2.webp"],["Shop","https://www.dunerealms.com/shop.html","nav-shop-v1.webp"],["Boards","https://forums.dunerealms.com/","nav-boards-v2.webp"],["Staff roster","https://www.dunerealms.com/staff.html","nav-staff-v2.webp"],["Discord","https://www.dunerealms.com/discord.html","nav-discord-v2.webp"],["Exchange","https://www.dunerealms.com/exchange.html","nav-exchange-v2.webp"],["Kit Exchange","https://www.dunerealms.com/kits.html","items/office_water.png"],["Support center","https://support.dunerealms.com/","nav-support-v2.webp"],["Account center","https://cp.dunerealms.com/","nav-account-v2.webp"],["Clan center","https://clans.dunerealms.com/","nav-clan-v2.webp"]]; +import{MAIN_MENU}from'./main-menu.mjs'; +export const PORTAL_LINKS=MAIN_MENU; export const PORTAL_NAV=''; export const PORTAL_CSS=` body>header{position:relative;z-index:100;height:auto;min-height:82px;padding:14px 3%;display:flex;align-items:center;justify-content:space-between;gap:24px;background:#10251f;border-bottom:1px solid #806e45;box-shadow:none;box-sizing:border-box} @@ -16,7 +17,7 @@ body>header>.menu-toggle{display:none!important;box-shadow:none;border:1px solid export function oldUpdatePortalNavigation(html){let updated=html.replace(/