From 1371dca3d8b8246191fcbfe379cc0c51dd86facf Mon Sep 17 00:00:00 2001 From: Chlod Alejandro Date: Sat, 8 Jun 2024 17:01:45 +0800 Subject: [PATCH] MOS:PHIL compliance --- src/PagasaParserWikipediaFormatter.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/PagasaParserWikipediaFormatter.ts b/src/PagasaParserWikipediaFormatter.ts index 5b2c210..a062bea 100644 --- a/src/PagasaParserWikipediaFormatter.ts +++ b/src/PagasaParserWikipediaFormatter.ts @@ -178,7 +178,26 @@ export default class PagasaParserWikipediaFormatter extends PagasaParserFormatte if (redirects[a1] == a2) return `[[${a2}]]`; - return `[[${redirects[a1]}|${a2 ?? a1}]]`; + let name = a2 ?? a1; + + // MOS:PHIL; https://w.wiki/AKWS + // If the title includes "city", use the page name as the title, + // removing disambiguators. This will automatically convert: + // * "Baguio City" to "Baguio" + // * "Science City of Muñoz" to "Muñoz" + // * "Isabela, Basilan" to "Isabela" + // This should exclude titles like: + // * Quezon City + // * Angeles City + // This should never change the redirect target. + if ( /\bcity\b/gi.test(name) ) { + name = redirects[a1].replace( + /^.*City of|(,.+)|(\s\([^)]+\)+)/g, + "" + ); + } + + return `[[${redirects[a1]}|${name}]]`; }); return wikitext;