web/website/control-panel/public/x-news-draft.mjs
Dev 6deb4a2e7d DuneRealms V2 clean baseline
Owner-authorised history reset; current source tree preserved exactly.
2026-11-13 00:05:14 +01:00

4 lines
1.1 KiB
JavaScript

// Draft formatting only. Publishing requires an authorised X account/integration.
const tags={news:['DuneRealms','Minecraft'],world:['DuneRealms','Minecraft','Worldbuilding'],maintenance:['DuneRealms','ServerMaintenance'],changelogs:['DuneRealms','Minecraft','DevLog'],events:['DuneRealms','Minecraft','CommunityEvent'],community:['DuneRealms','MinecraftCommunity'],unis_blog:['DuneRealms','DevLog']};
const weight=text=>Array.from(text).reduce((n,c)=>n+(c.codePointAt(0)>0x10ff?2:1),0);
export function xNewsDraft(post){if(!/^[0-9a-f-]{36}$/i.test(post.id))throw Error('Invalid article ID');const hashtags=['#dune','#minecraft',...(tags[post.category]||tags.news).filter(t=>!['Minecraft'].includes(t)).map(t=>'#'+t)].join(' '),url='https://www.dunerealms.com/news-archive.html?post='+post.id;const suffix='\n\n'+url+'\n'+hashtags;let title=String(post.title||'DuneRealms news').replace(/https?:\/\/\S+/g,'').replace(/[\r\n]+/g,' ').trim();const max=280-(weight(suffix)-url.length+23);if(weight(title)>max){let out='';for(const c of title){if(weight(out+c)>max-3)break;out+=c;}title=out.trimEnd()+'...';}return title+suffix;}