mediawiki-projects-list 2.1.0 → 2.2.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 +2 -0
- package/index.js +30 -2
- package/package.json +1 -1
- package/projects-schema.json +5 -0
- package/projects.json +9 -1
package/index.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ declare module 'mediawiki-projects-list' {
|
|
|
47
47
|
articlePath: string;
|
|
48
48
|
/** Script path of the proxy */
|
|
49
49
|
scriptPath: string;
|
|
50
|
+
/** Regex to remove from the relative url */
|
|
51
|
+
relativeFix: string;
|
|
50
52
|
/** Note about the specific proxy */
|
|
51
53
|
note: string | null;
|
|
52
54
|
};
|
package/index.js
CHANGED
|
@@ -29,6 +29,7 @@ const PROJECTS = require('./projects.json');
|
|
|
29
29
|
* @property {string} namePath - Name path of the proxy
|
|
30
30
|
* @property {string} articlePath - Article path of the proxy
|
|
31
31
|
* @property {string} scriptPath - Script path of the proxy
|
|
32
|
+
* @property {?string} relativeFix - Regex to remove from the relative url
|
|
32
33
|
* @property {?string} note - Note about the specific proxy
|
|
33
34
|
*/
|
|
34
35
|
|
|
@@ -71,6 +72,7 @@ const wikiProjects = PROJECTS.wikiProjects.map( wikiProject => {
|
|
|
71
72
|
* @type {FrontendProxy[]}
|
|
72
73
|
*/
|
|
73
74
|
const frontendProxies = PROJECTS.frontendProxies.map( frontendProxy => {
|
|
75
|
+
frontendProxy.relativeFix ??= frontendProxySchema.relativeFix.default;
|
|
74
76
|
frontendProxy.note ??= frontendProxySchema.note.default;
|
|
75
77
|
return frontendProxy;
|
|
76
78
|
} );
|
|
@@ -192,8 +194,19 @@ function urlToFix(url) {
|
|
|
192
194
|
let frontendProxy = frontendProxies.find( frontendProxy => hostname.endsWith( frontendProxy.name ) );
|
|
193
195
|
if ( frontendProxy ) {
|
|
194
196
|
let splitLength = frontendProxy.namePath.split('/').length;
|
|
195
|
-
let querykeys = frontendProxy.namePath.split('?').slice(1).join('?').split('&').flatMap( query =>
|
|
196
|
-
|
|
197
|
+
let querykeys = frontendProxy.namePath.split('?').slice(1).join('?').split('&').flatMap( query => {
|
|
198
|
+
if ( !query ) return [];
|
|
199
|
+
return query.split('=', 1);
|
|
200
|
+
} );
|
|
201
|
+
if ( splitLength > 4 && querykeys.length && frontendProxy.relativeFix ) {
|
|
202
|
+
result = (href, pagelink) => {
|
|
203
|
+
let prepend = '/' + pagelink.split('/', splitLength).slice(3, -1).join('/');
|
|
204
|
+
let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
|
|
205
|
+
let append = ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
|
|
206
|
+
return prepend + href.replace( new RegExp( frontendProxy.relativeFix ), '' ) + append;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
else if ( splitLength > 4 && querykeys.length ) {
|
|
197
210
|
result = (href, pagelink) => {
|
|
198
211
|
let prepend = '/' + pagelink.split('/', splitLength).slice(3, -1).join('/');
|
|
199
212
|
let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
|
|
@@ -201,15 +214,30 @@ function urlToFix(url) {
|
|
|
201
214
|
return prepend + href + append;
|
|
202
215
|
};
|
|
203
216
|
}
|
|
217
|
+
else if ( splitLength > 4 && frontendProxy.relativeFix ) {
|
|
218
|
+
result = (href, pagelink) => {
|
|
219
|
+
let prepend = '/' + pagelink.split('/', splitLength).slice(3, -1).join('/');
|
|
220
|
+
return prepend + href.replace( new RegExp( frontendProxy.relativeFix ), '' );
|
|
221
|
+
}
|
|
222
|
+
}
|
|
204
223
|
else if ( splitLength > 4 ) {
|
|
205
224
|
result = (href, pagelink) => '/' + pagelink.split('/', splitLength).slice(3, -1).join('/') + href;
|
|
206
225
|
}
|
|
226
|
+
else if ( querykeys.length && frontendProxy.relativeFix ) {
|
|
227
|
+
result = (href, pagelink) => {
|
|
228
|
+
let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
|
|
229
|
+
return href.replace( new RegExp( frontendProxy.relativeFix ), '' ) + ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
207
232
|
else if ( querykeys.length ) {
|
|
208
233
|
result = (href, pagelink) => {
|
|
209
234
|
let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
|
|
210
235
|
return href + ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
|
|
211
236
|
}
|
|
212
237
|
}
|
|
238
|
+
else if ( frontendProxy.relativeFix ) {
|
|
239
|
+
result = (href, pagelink) => href.replace( new RegExp( frontendProxy.relativeFix ), '' );
|
|
240
|
+
}
|
|
213
241
|
}
|
|
214
242
|
functionCache.urlToFix.set(hostname, result);
|
|
215
243
|
return result;
|
package/package.json
CHANGED
package/projects-schema.json
CHANGED
|
@@ -36,6 +36,11 @@
|
|
|
36
36
|
"type": "string",
|
|
37
37
|
"description": "Script path of the proxy"
|
|
38
38
|
},
|
|
39
|
+
"relativeFix": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "Regex to remove from the relative url",
|
|
42
|
+
"default": null
|
|
43
|
+
},
|
|
39
44
|
"note": {
|
|
40
45
|
"type": "string",
|
|
41
46
|
"description": "Note about the specific proxy",
|
package/projects.json
CHANGED
|
@@ -3,11 +3,19 @@
|
|
|
3
3
|
"frontendProxies": [
|
|
4
4
|
{
|
|
5
5
|
"name": "wikiless.org",
|
|
6
|
-
"regex": "wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50})(
|
|
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
9
|
"scriptPath": "https://$1.wikipedia.org/w/"
|
|
10
10
|
},
|
|
11
|
+
{
|
|
12
|
+
"name": "wikiwand.com",
|
|
13
|
+
"regex": "(?:www\\.)?wikiwand\\.com/([a-z\\d-]{1,50})/?",
|
|
14
|
+
"namePath": "https://www.wikiwand.com/$1/",
|
|
15
|
+
"articlePath": "https://www.wikiwand.com/$1/",
|
|
16
|
+
"scriptPath": "https://$1.wikipedia.org/w/",
|
|
17
|
+
"relativeFix": "^/wiki(?=/)"
|
|
18
|
+
},
|
|
11
19
|
{
|
|
12
20
|
"name": ".breezewiki.com",
|
|
13
21
|
"regex": "([a-z\\d-]{1,50})\\.breezewiki\\.com(?:/wiki/|/?$)",
|