mediawiki-projects-list 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +11 -0
- package/index.js +15 -5
- package/package.json +1 -1
- package/projects-schema.json +39 -0
- package/projects.json +14 -10
package/index.d.ts
CHANGED
|
@@ -49,6 +49,17 @@ declare module 'mediawiki-projects-list' {
|
|
|
49
49
|
scriptPath: string;
|
|
50
50
|
/** Regex to remove from the relative url */
|
|
51
51
|
relativeFix: string;
|
|
52
|
+
/** Only exists when the hostname contains multiple wikis: How to handle the id string */
|
|
53
|
+
idString?: {
|
|
54
|
+
/** Separator to join or split the id string on */
|
|
55
|
+
separator: string;
|
|
56
|
+
/** Order in which the project regex additional group matches should be chained to gain the id string */
|
|
57
|
+
direction: "asc" | "desc";
|
|
58
|
+
/** Regex to match the id string */
|
|
59
|
+
regex: string;
|
|
60
|
+
/** How to turn the group matches of the id string regex into an URL to the script path, index based on group matches */
|
|
61
|
+
scriptPaths: string[];
|
|
62
|
+
};
|
|
52
63
|
/** Note about the specific proxy */
|
|
53
64
|
note: string | null;
|
|
54
65
|
};
|
package/index.js
CHANGED
|
@@ -30,6 +30,11 @@ const PROJECTS = require('./projects.json');
|
|
|
30
30
|
* @property {string} articlePath - Article path of the proxy
|
|
31
31
|
* @property {string} scriptPath - Script path of the proxy
|
|
32
32
|
* @property {?string} relativeFix - Regex to remove from the relative url
|
|
33
|
+
* @property {object} [idString] - Only exists when the hostname contains multiple wikis: How to handle the id string
|
|
34
|
+
* @property {string} idString.separator - Separator to join or split the id string on
|
|
35
|
+
* @property {"asc"|"desc"} idString.direction - Order in which the project regex additional group matches should be chained to gain the id string
|
|
36
|
+
* @property {string} idString.regex - Regex to match the id string
|
|
37
|
+
* @property {string[]} idString.scriptPaths - How to turn the group matches of the id string regex into an URL to the script path, index based on group matches
|
|
33
38
|
* @property {?string} note - Note about the specific proxy
|
|
34
39
|
*/
|
|
35
40
|
|
|
@@ -72,6 +77,10 @@ const wikiProjects = PROJECTS.wikiProjects.map( wikiProject => {
|
|
|
72
77
|
* @type {FrontendProxy[]}
|
|
73
78
|
*/
|
|
74
79
|
const frontendProxies = PROJECTS.frontendProxies.map( frontendProxy => {
|
|
80
|
+
if ( frontendProxy.idString ) {
|
|
81
|
+
frontendProxy.idString.separator ??= frontendProxySchema.idString.properties.separator.default;
|
|
82
|
+
frontendProxy.idString.direction ??= frontendProxySchema.idString.properties.direction.default;
|
|
83
|
+
}
|
|
75
84
|
frontendProxy.relativeFix ??= frontendProxySchema.relativeFix.default;
|
|
76
85
|
frontendProxy.note ??= frontendProxySchema.note.default;
|
|
77
86
|
return frontendProxy;
|
|
@@ -143,11 +152,12 @@ function idStringToUrl(idString, projectName) {
|
|
|
143
152
|
return ( result ? new URL(result) : result );
|
|
144
153
|
}
|
|
145
154
|
let result = null;
|
|
146
|
-
let
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
let idString = wikiProjects.find( wikiProject => wikiProject.idString && wikiProject.name === projectName )?.idString;
|
|
156
|
+
if ( !idString ) idString = frontendProxies.find( frontendProxy => frontendProxy.idString && frontendProxy.name === projectName )?.idString;
|
|
157
|
+
if ( idString ) {
|
|
158
|
+
let regex = idString.match( new RegExp( '^' + idString.regex + '$' ) )?.[1].split(idString.separator);
|
|
159
|
+
if ( regex && regex.length <= idString.scriptPaths.length ) {
|
|
160
|
+
result = idString.scriptPaths[regex.length - 1].replace( /\$(\d)/g, (match, n) => regex[n - 1] );
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
functionCache.idStringToUrl.set(cacheKey, result);
|
package/package.json
CHANGED
package/projects-schema.json
CHANGED
|
@@ -41,6 +41,45 @@
|
|
|
41
41
|
"description": "Regex to remove from the relative url",
|
|
42
42
|
"default": null
|
|
43
43
|
},
|
|
44
|
+
"idString": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"description": "Only exists when the hostname contains multiple wikis: How to handle the id string",
|
|
47
|
+
"properties": {
|
|
48
|
+
"separator": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"description": "Separator to join or split the id string on",
|
|
51
|
+
"default": "."
|
|
52
|
+
},
|
|
53
|
+
"direction": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "Order in which the project regex additional group matches should be chained to gain the id string",
|
|
56
|
+
"enum": [
|
|
57
|
+
"asc",
|
|
58
|
+
"desc"
|
|
59
|
+
],
|
|
60
|
+
"default": "desc"
|
|
61
|
+
},
|
|
62
|
+
"regex": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "Regex to match the id string"
|
|
65
|
+
},
|
|
66
|
+
"scriptPaths": {
|
|
67
|
+
"type": "array",
|
|
68
|
+
"description": "How to turn the group matches of the id string regex into an URL to the script path, index based on group matches",
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"description": "Replacement for the id string regex match."
|
|
72
|
+
},
|
|
73
|
+
"contains": true,
|
|
74
|
+
"additionalItems": false
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"required": [
|
|
78
|
+
"regex",
|
|
79
|
+
"scriptPaths"
|
|
80
|
+
],
|
|
81
|
+
"additionalProperties": false
|
|
82
|
+
},
|
|
44
83
|
"note": {
|
|
45
84
|
"type": "string",
|
|
46
85
|
"description": "Note about the specific proxy",
|
package/projects.json
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
"regex": "wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50})(?:&|/?$)",
|
|
7
7
|
"namePath": "https://wikiless.org/?lang=$1",
|
|
8
8
|
"articlePath": "https://wikiless.org/wiki/?lang=$1",
|
|
9
|
-
"scriptPath": "https://$1.wikipedia.org/w/"
|
|
9
|
+
"scriptPath": "https://$1.wikipedia.org/w/",
|
|
10
|
+
"idString": {
|
|
11
|
+
"regex": "([a-z\\d-]{1,50})",
|
|
12
|
+
"scriptPaths": [
|
|
13
|
+
"https://wikiless.org/?lang=$1"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
10
16
|
},
|
|
11
17
|
{
|
|
12
18
|
"name": "wikiwand.com",
|
|
@@ -14,15 +20,13 @@
|
|
|
14
20
|
"namePath": "https://www.wikiwand.com/$1/",
|
|
15
21
|
"articlePath": "https://www.wikiwand.com/$1/",
|
|
16
22
|
"scriptPath": "https://$1.wikipedia.org/w/",
|
|
17
|
-
"relativeFix": "^/wiki(?=/)"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"scriptPath": "https://$1.fandom.com/",
|
|
25
|
-
"note": "Missing language support."
|
|
23
|
+
"relativeFix": "^/wiki(?=/)",
|
|
24
|
+
"idString": {
|
|
25
|
+
"regex": "([a-z\\d-]{1,50})",
|
|
26
|
+
"scriptPaths": [
|
|
27
|
+
"https://www.wikiwand.com/$1/"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
26
30
|
},
|
|
27
31
|
{
|
|
28
32
|
"name": "breezewiki.com",
|