diff --git a/src/index.mjs b/src/index.mjs index c848962..a0cb065 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -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` - * parameter above. Whitespace in capture groups so the inserted parameter can - * use the exact same formatting. + * parameter. Whitespace in capture groups so the inserted parameter can use the + * exact same formatting. */ 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. * @param {string} pageContent @@ -36,7 +43,14 @@ function insertInfoboxEDBID (pageContent, edbID) { console.log('Page has `id-gt` parameter, inserting `id-edb` above that'); 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'); }