mediawiki-projects-list 1.3.0 → 2.1.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 CHANGED
@@ -35,9 +35,28 @@ declare module 'mediawiki-projects-list' {
35
35
  note: string | null;
36
36
  };
37
37
 
38
+ /** A frontend proxy */
39
+ export type FrontendProxy = {
40
+ /** Hostname of the proxy */
41
+ name: string;
42
+ /** Regex to match the proxy url */
43
+ regex: string;
44
+ /** Name path of the proxy */
45
+ namePath: string;
46
+ /** Article path of the proxy */
47
+ articlePath: string;
48
+ /** Script path of the proxy */
49
+ scriptPath: string;
50
+ /** Note about the specific proxy */
51
+ note: string | null;
52
+ };
53
+
38
54
  /** List of MediaWiki projects */
39
55
  export const wikiProjects: WikiProject[];
40
56
 
57
+ /** List of frontend proxies */
58
+ export const frontendProxies: FrontendProxy[];
59
+
41
60
  export function inputToWikiProject(input: string): {
42
61
  fullArticlePath: string;
43
62
  fullScriptPath: string;
@@ -48,4 +67,13 @@ declare module 'mediawiki-projects-list' {
48
67
 
49
68
  export function idStringToUrl(idString: string, projectName: string): URL | null;
50
69
 
70
+ export function inputToWikiProject(input: string): {
71
+ fullNamePath: string;
72
+ fullArticlePath: string;
73
+ fullScriptPath: string;
74
+ frontendProxy: FrontendProxy;
75
+ } | null;
76
+
77
+ export function urlToFix(url: string): ((href: string, pagelink: string) => string) | null;
78
+
51
79
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const {properties: {wikiProjects: {items: {properties: wikiProjectSchema}}}} = require('./projects-schema.json');
1
+ const {properties: {wikiProjects: {items: {properties: wikiProjectSchema}}, frontendProxies: {items: {properties: frontendProxySchema}}}} = require('./projects-schema.json');
2
2
  const PROJECTS = require('./projects.json');
3
3
 
4
4
  /**
@@ -29,13 +29,16 @@ 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} note - Note about the specific proxy
32
33
  */
33
34
 
34
35
  /**
35
36
  * @type {{
36
37
  * inputToWikiProject: Map<string, ?{fullArticlePath: string, fullScriptPath: string, wikiProject: WikiProject}>,
37
38
  * urlToIdString: Map<string, ?string>,
38
- * idStringToUrl: Map<string, ?string>
39
+ * idStringToUrl: Map<string, ?string>,
40
+ * inputToFrontendProxy: Map<string, ?{fullNamePath: string, fullArticlePath: string, fullScriptPath: string, frontendProxy: FrontendProxy}>,
41
+ * urlToFix: Map<string, ?((href:String,pagelink:String)=>String)>
39
42
  * }}
40
43
  */
41
44
  const functionCache = {
@@ -67,7 +70,10 @@ const wikiProjects = PROJECTS.wikiProjects.map( wikiProject => {
67
70
  * List of frontend proxies
68
71
  * @type {FrontendProxy[]}
69
72
  */
70
- const frontendProxies = PROJECTS.frontendProxies;
73
+ const frontendProxies = PROJECTS.frontendProxies.map( frontendProxy => {
74
+ frontendProxy.note ??= frontendProxySchema.note.default;
75
+ return frontendProxy;
76
+ } );
71
77
 
72
78
  /**
73
79
  *
@@ -92,6 +98,10 @@ function inputToWikiProject(input) {
92
98
  fullScriptPath: 'https://' + regex[1] + scriptPath,
93
99
  wikiProject: wikiProject
94
100
  };
101
+ if ( result.fullArticlePath.includes('?') && !result.fullArticlePath.endsWith('=') ) {
102
+ result.fullArticlePath = result.fullArticlePath.replace( '?', '$1?' );
103
+ }
104
+ else result.fullArticlePath += '$1';
95
105
  }
96
106
  }
97
107
  functionCache.inputToWikiProject.set(input, result);
@@ -160,6 +170,10 @@ function inputToFrontendProxy(input) {
160
170
  fullScriptPath: frontendProxy.scriptPath.replace( /\$(\d)/g, (match, n) => regex[n] ),
161
171
  frontendProxy: frontendProxy
162
172
  };
173
+ if ( result.fullArticlePath.includes('?') && !result.fullArticlePath.endsWith('=') ) {
174
+ result.fullArticlePath = result.fullArticlePath.replace( '?', '$1?' );
175
+ }
176
+ else result.fullArticlePath += '$1';
163
177
  }
164
178
  }
165
179
  functionCache.inputToFrontendProxy.set(input, result);
@@ -176,9 +190,26 @@ function urlToFix(url) {
176
190
  if ( functionCache.urlToFix.has(hostname) ) return functionCache.urlToFix.get(hostname);
177
191
  let result = null;
178
192
  let frontendProxy = frontendProxies.find( frontendProxy => hostname.endsWith( frontendProxy.name ) );
179
- if ( frontendProxy?.namePath.split('/').length > 4 ) {
193
+ if ( frontendProxy ) {
180
194
  let splitLength = frontendProxy.namePath.split('/').length;
181
- result = (href, pagelink) => '/' + pagelink.split('/', splitLength).slice(3, -1).join('/') + href;
195
+ let querykeys = frontendProxy.namePath.split('?').slice(1).join('?').split('&').flatMap( query => query.split('=', 1) );
196
+ if ( splitLength > 4 && querykeys.length ) {
197
+ result = (href, pagelink) => {
198
+ let prepend = '/' + pagelink.split('/', splitLength).slice(3, -1).join('/');
199
+ let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
200
+ let append = ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
201
+ return prepend + href + append;
202
+ };
203
+ }
204
+ else if ( splitLength > 4 ) {
205
+ result = (href, pagelink) => '/' + pagelink.split('/', splitLength).slice(3, -1).join('/') + href;
206
+ }
207
+ else if ( querykeys.length ) {
208
+ result = (href, pagelink) => {
209
+ let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
210
+ return href + ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
211
+ }
212
+ }
182
213
  }
183
214
  functionCache.urlToFix.set(hostname, result);
184
215
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediawiki-projects-list",
3
- "version": "1.3.0",
3
+ "version": "2.1.0",
4
4
  "type": "commonjs",
5
5
  "description": "List of MediaWiki projects for use in discord-wiki-bot",
6
6
  "main": "index.js",
@@ -34,7 +34,12 @@
34
34
  },
35
35
  "scriptPath": {
36
36
  "type": "string",
37
- "description": "Script path of the project"
37
+ "description": "Script path of the proxy"
38
+ },
39
+ "note": {
40
+ "type": "string",
41
+ "description": "Note about the specific proxy",
42
+ "default": null
38
43
  }
39
44
  },
40
45
  "required": [
package/projects.json CHANGED
@@ -1,26 +1,36 @@
1
1
  {
2
2
  "$schema": "./projects-schema.json",
3
3
  "frontendProxies": [
4
+ {
5
+ "name": "wikiless.org",
6
+ "regex": "wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50})(?:&|$)",
7
+ "namePath": "https://wikiless.org/?lang=$1",
8
+ "articlePath": "https://wikiless.org/wiki/?lang=$1",
9
+ "scriptPath": "https://$1.wikipedia.org/w/"
10
+ },
4
11
  {
5
12
  "name": ".breezewiki.com",
6
13
  "regex": "([a-z\\d-]{1,50})\\.breezewiki\\.com(?:/wiki/|/?$)",
7
14
  "namePath": "https://breezewiki.com/$1/",
8
15
  "articlePath": "https://breezewiki.com/$1/wiki/",
9
- "scriptPath": "https://$1.fandom.com/"
16
+ "scriptPath": "https://$1.fandom.com/",
17
+ "note": "Missing language support."
10
18
  },
11
19
  {
12
20
  "name": "breezewiki.com",
13
21
  "regex": "breezewiki\\.com/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
14
22
  "namePath": "https://breezewiki.com/$1/",
15
23
  "articlePath": "https://breezewiki.com/$1/wiki/",
16
- "scriptPath": "https://$1.fandom.com/"
24
+ "scriptPath": "https://$1.fandom.com/",
25
+ "note": "Missing language support."
17
26
  },
18
27
  {
19
28
  "name": "breezewiki.pussthecat.org",
20
29
  "regex": "breezewiki\\.pussthecat\\.org/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
21
30
  "namePath": "https://breezewiki.pussthecat.org/$1/",
22
31
  "articlePath": "https://breezewiki.pussthecat.org/$1/wiki/",
23
- "scriptPath": "https://$1.fandom.com/"
32
+ "scriptPath": "https://$1.fandom.com/",
33
+ "note": "Missing language support."
24
34
  }
25
35
  ],
26
36
  "wikiProjects": [