add script for fixing flavor text formatting from robogurgum
see
This commit is contained in:
parent
a8ad47f830
commit
80bf319378
1 changed files with 53 additions and 0 deletions
53
bin/one-time/flavor-text-color-fix
Executable file
53
bin/one-time/flavor-text-color-fix
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env -S node --env-file-if-exists=.env
|
||||
// Fixes flavor text formatting on files robogurgum created for patches 7.3/7.31
|
||||
// see https://discord.com/channels/312060255469305856/1412850908668100810
|
||||
|
||||
import {getMediawikiClient} from '../../lib/config.js';
|
||||
import {diff} from '../../lib/util/diff.js';
|
||||
|
||||
const mw = await getMediawikiClient();
|
||||
|
||||
function fixPageContent (pageContent) {
|
||||
const flavorTextRegexp = /\| flavor-text = ([\s\S]*?)\n\|/;
|
||||
|
||||
let match = pageContent.match(flavorTextRegexp);
|
||||
if (!match) return pageContent;
|
||||
let flavorText = match[1];
|
||||
if (!flavorText.trim()) return pageContent;
|
||||
|
||||
let newFlavorText = flavorText
|
||||
// linebreaks with
|
||||
// - no <br> or <br /> etc before or after
|
||||
// - no {{action fact}} after (that renders a line break at the start)
|
||||
.replace(/(?<!<br\s*\/?>)\n(?!<br\s*\/?>)(?!{{action fact|\s*$)/gi, '<br>\n')
|
||||
// spans that set color via inline style instead of using {{colorize}}
|
||||
.replace(/<span style="color: #00cc22;">([^<]+)<\/span>/g, '`$1`')
|
||||
.replace(/<span style="color: #ffff66;">([^<]+)<\/span>/g, '``$1``')
|
||||
.replace(/<span style="color: #ff7b1a;">([^<]+)<\/span>/g, '```$1```')
|
||||
// convert lunar/phaenna credit bonuses to use {{action fact}}, but only
|
||||
// when we can be sure it won't add extra line breaks
|
||||
.replace(
|
||||
/<br\s*\/?>(\n?)`([\w\d _-]+)(?<=Credit Bonus)(?::`|`:) +([^\n<]+)/g,
|
||||
'$1{{action fact|$2|$3}}',
|
||||
)
|
||||
// flavor-text is automatically colorized, remove redundant invocations
|
||||
.replace(/{{colorize\|([^|{}]+)}}/g, '$1');
|
||||
|
||||
return pageContent.replace(flavorTextRegexp, `| flavor-text = ${newFlavorText}\n|`);
|
||||
}
|
||||
|
||||
const pages = await mw.listUserContribs('RoboGurgum', {namespaces: [0], show: 'new', limit: 1000});
|
||||
for (const page of pages) {
|
||||
const {title} = page;
|
||||
const pageContent = await mw.readPage(title);
|
||||
let fixedContent = fixPageContent(pageContent);
|
||||
if (fixedContent === pageContent) {
|
||||
console.log('#', title, ' No change\n');
|
||||
continue;
|
||||
}
|
||||
console.write('\n');
|
||||
diff(pageContent, fixedContent, page);
|
||||
console.log();
|
||||
|
||||
await mw.editPage(title, fixedContent, 'fix flavor text formatting', true);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue