Correctly preprocess namespaces

Fixes an error in some complicated networks.
This commit is contained in:
Florine W. Dekker 2021-05-14 20:52:56 +02:00
parent 53f9dc7303
commit 4d1db86843
Signed by: FWDekker
GPG Key ID: 78B3EAF58145AF25
2 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "interlanguage-checker", "name": "interlanguage-checker",
"version": "1.13.3", "version": "1.13.4",
"description": "Check the consistency of MediaWiki interlanguage links in a simple overview.", "description": "Check the consistency of MediaWiki interlanguage links in a simple overview.",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"browser": "dist/bundle.js", "browser": "dist/bundle.js",

View File

@ -324,7 +324,7 @@ export class MediaWiki {
/** /**
* The namespaces on this wiki. * The namespaces on this wiki.
*/ */
namespaces!: Map<number, { id: string, canonical: string, "*": string }>; namespaces!: Map<number, { canonical: string, "*": string }>;
/** /**
@ -355,7 +355,13 @@ export class MediaWiki {
this.general = query.general; this.general = query.general;
this.interwikiMap = this.interwikiMap =
new Map(query.interwikimap.map((it: { prefix: string, url: string }) => [it.prefix, it.url])); new Map(query.interwikimap.map((it: { prefix: string, url: string }) => [it.prefix, it.url]));
this.namespaces = query.namespaces; this.namespaces =
new Map(
Object.keys(query.namespaces).map(id => {
const props = query.namespaces[id];
return [+id, {canonical: props.canonical, "*": props["*"]}];
})
);
return this; return this;
} }
@ -437,9 +443,7 @@ export class MediaWiki {
if (titleParts.length < 2) return new InterlangLink(normalLang, link.title); if (titleParts.length < 2) return new InterlangLink(normalLang, link.title);
titleParts[0] = [...this.namespaces.values()].reduce( titleParts[0] = [...this.namespaces.values()].reduce(
(titlePart: string, namespace: { id: string, canonical: string, "*": string }) => { (titlePart, namespace) => titlePart === namespace["canonical"] ? namespace["*"] : titlePart,
return titlePart === namespace["canonical"] ? namespace["*"] : titlePart;
},
titleParts[0] titleParts[0]
); );
const normalTitle = titleParts.join(":"); const normalTitle = titleParts.join(":");