Unify staff and public government directories with Order artwork and shared banners

This commit is contained in:
unimatrixgit 2026-11-15 11:02:39 +01:00
commit 8f3c7e06c5
3 changed files with 139 additions and 15 deletions

View file

@ -1,4 +1,4 @@
export const MAIN_MENU=[['Home','https://www.dunerealms.com/','nav-home-v2.webp'],['Shop','https://www.dunerealms.com/shop.html','nav-exchange-full-v2.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 const MAIN_MENU=[['Home','https://www.dunerealms.com/','nav-home-v2.webp'],['Shop','https://www.dunerealms.com/shop.html','nav-exchange-full-v2.webp'],['Boards','https://forums.dunerealms.com/','nav-boards-v2.webp'],['Staff roster','https://www.dunerealms.com/staff.html','nav-staff-v2.webp'],['Realm & Politics','https://www.dunerealms.com/government.html','seals/office-landsraad.png'],['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);}

View file

@ -26,7 +26,7 @@ export function updatePortalNavigation(html){
return updated.replace('</head>',SHARED_HEAD+'</head>');
}
export function pageContextFor(value,links=PORTAL_LINKS){
const url=new URL(value),host=url.hostname;if(url.pathname==='/kits.html')return {label:'Kit Exchange',icon:'items/office_water.png'};if(url.pathname==='/shop.html')return {label:'Shop',icon:'nav-exchange-full-v2.webp'}; if(host==='wiki.dunerealms.com')return {label:'Manual/wiki',icon:'nav-manual-full-v2.webp'};
const url=new URL(value),host=url.hostname;if(url.pathname==='/government.html')return {label:'Realm & Politics',icon:'seals/office-landsraad.png'};if(url.pathname==='/kits.html')return {label:'Kit Exchange',icon:'items/office_water.png'};if(url.pathname==='/shop.html')return {label:'Shop',icon:'nav-exchange-full-v2.webp'}; if(host==='wiki.dunerealms.com')return {label:'Manual/wiki',icon:'nav-manual-full-v2.webp'};
if(url.pathname.startsWith('/git/'))return {label:'DuneGit',icon:'nav-manual-full-v2.webp'};
if(url.pathname.startsWith('/news/'))return {label:'News dispatch',icon:'nav-discord-full-v2.webp'};
if(url.pathname==='/news-archive.html')return {label:url.searchParams.has('post')?'News dispatch':'News archive',icon:'nav-discord-full-v2.webp'};

View file

@ -0,0 +1,49 @@
"""Publish canonical release chrome through existing stable nginx aliases."""
from pathlib import Path
import argparse
import json
import os
import subprocess
ASSETS = ('portal-navigation.js','portal-navigation.css','release.json',
'menu-new-items.json','rates-and-charges.html','bank-rates.css')
DESTINATION = Path('/var/lib/dunerealms-public-rates')
def replace(path, data):
temporary = path.with_name(path.name+'.publication-new')
temporary.write_bytes(data)
temporary.chmod(0o644)
os.chown(temporary,0,0)
os.replace(temporary,path)
def main():
parser=argparse.ArgumentParser()
parser.add_argument('--apply',action='store_true')
args=parser.parse_args()
release=Path('/home/dunerealms/apps/dunerealms/current').resolve(strict=True)
source=release/'dist/shared-chrome'
data={name:(source/name).read_bytes() for name in ASSETS}
metadata=json.loads(data['release.json'])
if not args.apply:
print(json.dumps({'plan':True,'version':metadata['version'],'assets':len(data)}));return
if os.geteuid()!=0:raise RuntimeError('Deployment operator required')
previous={name:(DESTINATION/name).read_bytes() for name in ASSETS}
try:
for name,content in data.items():replace(DESTINATION/name,content)
# Check the actual nginx response, including its symlink policy. A file
# readability check alone missed the previous 403 regression.
for host in ('www','cp','forums','support','clans','wiki'):
domain=host+'.dunerealms.com'
prefix='dune-navigation' if host in ('forums','support') else 'portal-navigation'
for filename,expected in ((prefix+'.css',data['portal-navigation.css']),
(prefix+'.js',data['portal-navigation.js']),
('release.json',data['release.json'])):
actual=subprocess.check_output(['curl','--noproxy','*','-fsS','--max-time','12',
'--resolve',domain+':443:127.0.0.1','https://'+domain+'/'+filename],stderr=subprocess.PIPE)
if actual!=expected:raise RuntimeError('Shared publication mismatch: '+host+'/'+filename)
except Exception:
for name,content in previous.items():replace(DESTINATION/name,content)
raise
print(json.dumps({'applied':True,'version':metadata['version'],'hosts':6,'assets':len(data)}))
if __name__=='__main__':main()