mediawiki-projects-list 2.2.0 → 2.3.1
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 +22 -10
- package/package.json +1 -1
- package/projects-schema.json +39 -0
- package/projects.json +29 -25
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;
|
|
@@ -118,12 +127,14 @@ function inputToWikiProject(input) {
|
|
|
118
127
|
function urlToIdString(url) {
|
|
119
128
|
if ( functionCache.urlToIdString.has(url.href) ) return functionCache.urlToIdString.get(url.href);
|
|
120
129
|
let result = null;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
/** @type {WikiProject|FrontendProxy|undefined} */
|
|
131
|
+
let project = wikiProjects.find( wikiProject => wikiProject.idString && url.hostname.endsWith( wikiProject.name ) );
|
|
132
|
+
if ( !project ) project = frontendProxies.find( frontendProxy => frontendProxy.idString && url.hostname.endsWith( frontendProxy.name ) );
|
|
133
|
+
if ( project ) {
|
|
134
|
+
let regex = url.href.match( new RegExp( project.regex ) )?.slice(2);
|
|
124
135
|
if ( regex?.length ) {
|
|
125
|
-
if (
|
|
126
|
-
result = regex.join(
|
|
136
|
+
if ( project.idString.direction === 'desc' ) regex.reverse();
|
|
137
|
+
result = regex.join(project.idString.separator);
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
140
|
functionCache.urlToIdString.set(url.href, result);
|
|
@@ -143,11 +154,12 @@ function idStringToUrl(idString, projectName) {
|
|
|
143
154
|
return ( result ? new URL(result) : result );
|
|
144
155
|
}
|
|
145
156
|
let result = null;
|
|
146
|
-
let
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
157
|
+
let project = wikiProjects.find( wikiProject => wikiProject.idString && wikiProject.name === projectName )?.idString;
|
|
158
|
+
if ( !project ) project = frontendProxies.find( frontendProxy => frontendProxy.idString && frontendProxy.name === projectName )?.idString;
|
|
159
|
+
if ( project ) {
|
|
160
|
+
let regex = idString.match( new RegExp( '^' + project.regex + '$' ) )?.[1].split(project.separator);
|
|
161
|
+
if ( regex && regex.length <= project.scriptPaths.length ) {
|
|
162
|
+
result = project.scriptPaths[regex.length - 1].replace( /\$(\d)/g, (match, n) => regex[n - 1] );
|
|
151
163
|
}
|
|
152
164
|
}
|
|
153
165
|
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
|
@@ -3,41 +3,45 @@
|
|
|
3
3
|
"frontendProxies": [
|
|
4
4
|
{
|
|
5
5
|
"name": "wikiless.org",
|
|
6
|
-
"regex": "wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50})(?:&|/?$)",
|
|
7
|
-
"namePath": "https://wikiless.org/?lang=$
|
|
8
|
-
"articlePath": "https://wikiless.org/wiki/?lang=$
|
|
9
|
-
"scriptPath": "https://$
|
|
6
|
+
"regex": "(wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50}))(?:&|/?$)",
|
|
7
|
+
"namePath": "https://wikiless.org/?lang=$2",
|
|
8
|
+
"articlePath": "https://wikiless.org/wiki/?lang=$2",
|
|
9
|
+
"scriptPath": "https://$2.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",
|
|
13
|
-
"regex": "(?:www\\.)?wikiwand\\.com/([a-z\\d-]{1,50})/?",
|
|
14
|
-
"namePath": "https://www.wikiwand.com/$
|
|
15
|
-
"articlePath": "https://www.wikiwand.com/$
|
|
16
|
-
"scriptPath": "https://$
|
|
17
|
-
"relativeFix": "^/wiki(?=/)"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"scriptPath": "https://$1.fandom.com/",
|
|
25
|
-
"note": "Missing language support."
|
|
19
|
+
"regex": "((?:www\\.)?wikiwand\\.com/([a-z\\d-]{1,50}))/?",
|
|
20
|
+
"namePath": "https://www.wikiwand.com/$2/",
|
|
21
|
+
"articlePath": "https://www.wikiwand.com/$2/",
|
|
22
|
+
"scriptPath": "https://$2.wikipedia.org/w/",
|
|
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",
|
|
29
|
-
"regex": "breezewiki\\.com/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
|
|
30
|
-
"namePath": "https://breezewiki.com/$
|
|
31
|
-
"articlePath": "https://breezewiki.com/$
|
|
32
|
-
"scriptPath": "https://$
|
|
33
|
+
"regex": "(breezewiki\\.com/([a-z\\d-]{1,50}))(?:/wiki/|/?$)",
|
|
34
|
+
"namePath": "https://breezewiki.com/$2/",
|
|
35
|
+
"articlePath": "https://breezewiki.com/$2/wiki/",
|
|
36
|
+
"scriptPath": "https://$2.fandom.com/",
|
|
33
37
|
"note": "Missing language support."
|
|
34
38
|
},
|
|
35
39
|
{
|
|
36
40
|
"name": "breezewiki.pussthecat.org",
|
|
37
|
-
"regex": "breezewiki\\.pussthecat\\.org/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
|
|
38
|
-
"namePath": "https://breezewiki.pussthecat.org/$
|
|
39
|
-
"articlePath": "https://breezewiki.pussthecat.org/$
|
|
40
|
-
"scriptPath": "https://$
|
|
41
|
+
"regex": "(breezewiki\\.pussthecat\\.org/([a-z\\d-]{1,50}))(?:/wiki/|/?$)",
|
|
42
|
+
"namePath": "https://breezewiki.pussthecat.org/$2/",
|
|
43
|
+
"articlePath": "https://breezewiki.pussthecat.org/$2/wiki/",
|
|
44
|
+
"scriptPath": "https://$2.fandom.com/",
|
|
41
45
|
"note": "Missing language support."
|
|
42
46
|
}
|
|
43
47
|
],
|