Add id-edb after release if we can't do anything else

This commit is contained in:
ewin 2025-07-28 18:51:06 -04:00
parent c86fb77f9e
commit 8e4239893c
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

View file

@ -12,11 +12,18 @@ const existingEmptyEDBIDParameter = /^(\s*\|\s*id-edb\s*=)\s*$/m;
/** /**
* Matches an `id-gt` infobox parameter above which we can insert an `id-edb` * Matches an `id-gt` infobox parameter above which we can insert an `id-edb`
* parameter above. Whitespace in capture groups so the inserted parameter can * parameter. Whitespace in capture groups so the inserted parameter can use the
* use the exact same formatting. * exact same formatting.
*/ */
const existingGTIDParameter = /^(\s*)\|(\s*)id-gt(\s*)=(\s*).*$/m; const existingGTIDParameter = /^(\s*)\|(\s*)id-gt(\s*)=(\s*).*$/m;
/**
* Matches a `release` infobox parameter below which we can insert an `id-edb`
* parameter. Whitespace in capture groups so the inserted parameter can use the
* exact same formatting.
*/
const existingReleaseParameter = /^(\s*)\|(\s*)release(\s*)=(\s*).*$/m;
/** /**
* Inserts the `id-edb` item infobox parameter into the given page contents. * Inserts the `id-edb` item infobox parameter into the given page contents.
* @param {string} pageContent * @param {string} pageContent
@ -36,7 +43,14 @@ function insertInfoboxEDBID (pageContent, edbID) {
console.log('Page has `id-gt` parameter, inserting `id-edb` above that'); console.log('Page has `id-gt` parameter, inserting `id-edb` above that');
return pageContent.replace(existingGTIDParameter, `$1|$2id-edb$3=$4${edbID}\n$&`); return pageContent.replace(existingGTIDParameter, `$1|$2id-edb$3=$4${edbID}\n$&`);
} }
console.log('bad', pageContent); if (pageContent.match(existingReleaseParameter)) {
console.log('Page has no ID parameters, inserting `id-edb` below `release`');
return pageContent.replace(existingReleaseParameter, `$&\n$1|$2id-edb$3=$4${edbID}`)
}
console.group('Bad page content:');
console.log(pageContent);
console.groupEnd();
throw new Error('Dunno how to insert the parameter into this page'); throw new Error('Dunno how to insert the parameter into this page');
} }