Merge pull request 'Fix wiki and support design asset loading without changing security policy' (#573) from dev/MC:design/native-style-loading-20261125 into main
Some checks failed
DuneRealms Web CI / web (push) Failing after 54s
Some checks failed
DuneRealms Web CI / web (push) Failing after 54s
This commit is contained in:
commit
cfb9bc3319
5 changed files with 9 additions and 4 deletions
|
|
@ -14,7 +14,11 @@ def append(old,content):
|
|||
assert old.count(start)==old.count(end)==1
|
||||
old=old[:old.index(start)]+old[old.index(end)+len(end):]
|
||||
return old.rstrip()+'\n'+start+'\n'+content+'\n'+end+'\n'
|
||||
changes={'shared-header.html':chrome['header'],'shared-header-head.html':chrome['head']}
|
||||
native_head=chrome['head'].replace('href="/portal-navigation.css"','href="https://www.dunerealms.com/portal-navigation.css"').replace('src="/portal-navigation.js"','src="https://www.dunerealms.com/portal-navigation.js"')
|
||||
# Native services execute the compiled same-origin navigation script, which
|
||||
# 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')
|
||||
for app in ['mybb','osticket']:
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const esc=s=>s.replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'&q
|
|||
const designHead='<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 function applyRealmPageDesign(html,file){
|
||||
if(!/<link\b[^>]*data-realm-design/.test(html))html=html.replace('</head>',designHead+'</head>');
|
||||
if(file==='manual.html')html=html.replaceAll('https://www.dunerealms.com/realm-design','/realm-design');
|
||||
const page=REALM_PAGE_DESIGNS[file];if(!page)return html;
|
||||
if(html.includes('data-realm-layout="2"'))return html;
|
||||
html=html.replace(/<section class="dr-page-banner"[^>]*>[\s\S]*?<\/section>/g,'').replace(/\sdata-realm-page="[^"]*"/g,'');
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ test('every public document opts into the common design and every legacy page ow
|
|||
});
|
||||
test('page migration preserves functional element identities and keeps the banner outside a nested manual grid',()=>{
|
||||
const source='<!doctype html><html lang="en"><head><title>Manual</title><script src="manual.js" defer></script></head><body><header><a>Old navigation</a></header><div class="manual-layout"><aside id="chapter-nav"></aside><main id="chapter-content" tabindex="-1"><form id="chapter-search"><input name="q"></form></main></div></body></html>',next=applyRealmPageDesign(source,'manual.html');
|
||||
assert(next.indexOf('class="dr-page-banner"')<next.indexOf('class="manual-layout"'));assert.match(next,/<main id="chapter-content" tabindex="-1" class="dr-page-content">/);assert.match(next,/<form id="chapter-search"><input name="q"><\/form>/);assert.match(next,/<script src="manual.js" defer>/);assert.equal(applyRealmPageDesign(next,'manual.html'),next);assert.equal((next.match(/class="dune-site-header"/g)||[]).length,1);
|
||||
assert(next.indexOf('class="dr-page-banner"')<next.indexOf('class="manual-layout"'));assert.match(next,/<main id="chapter-content" tabindex="-1" class="dr-page-content">/);assert.match(next,/<form id="chapter-search"><input name="q"><\/form>/);assert.match(next,/<script src="manual.js" defer>/);assert.match(next,/href="\/realm-design\.css/);assert.match(next,/src="\/realm-design\.js/);assert.equal(applyRealmPageDesign(next,'manual.html'),next);assert.equal((next.match(/class="dune-site-header"/g)||[]).length,1);
|
||||
});
|
||||
test('all standalone CP documents load the same design without changing their feature scripts',()=>{
|
||||
for(const name of ['user-service.html','clan-center.html','servers.html','cp-v2/index.html','cp-v2/cp-v2-mentat-embed.html','cp-v2/reserve-ledger.html','dmpaint/index.html']){const html=readFileSync(new URL('../control-panel/public/'+name,import.meta.url),'utf8');assert.match(html,/realm-design\.css/,name);assert.match(html,/realm-design\.js/,name);}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,7 @@
|
|||
(()=>{
|
||||
'use strict';if(window.__duneRealmDesign)return;window.__duneRealmDesign=true;
|
||||
const root='https://www.dunerealms.com';
|
||||
if(!document.querySelector('link[data-realm-design],link[href*="/realm-design.css"]')){const css=document.createElement('link');css.rel='stylesheet';css.href=root+'/realm-design.css?v=every-page-1';css.dataset.realmDesign='';document.head.append(css);}
|
||||
if(!document.querySelector('link[data-realm-design],link[href*="/realm-design.css"]')){const css=document.createElement('link');css.rel='stylesheet';css.href=(location.hostname==='wiki.dunerealms.com'?'':root)+'/realm-design.css?v=every-page-1';css.dataset.realmDesign='';document.head.append(css);}
|
||||
const embedded=window.top!==window.self;if(embedded)document.documentElement.classList.add('dune-embedded');
|
||||
document.body.classList.add('dr-design');const workspace=!!document.querySelector('#portals')&&!!document.querySelector('#content');if(workspace)document.body.classList.add('dr-workspace');
|
||||
const nativeHost=({'forums.dunerealms.com':'boards','support.dunerealms.com':'support','shop.dunerealms.com':'shop','wiki.dunerealms.com':'wiki','mail.dunerealms.com':'mail'})[location.hostname]||(location.pathname.startsWith('/git/')?'git':null);if(nativeHost){document.body.classList.add('dr-native','dr-native-'+nativeHost);document.body.dataset.realmPage=nativeHost;}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff