mediawiki-projects-list 1.3.0 → 2.0.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.js CHANGED
@@ -35,7 +35,9 @@ const PROJECTS = require('./projects.json');
35
35
  * @type {{
36
36
  * inputToWikiProject: Map<string, ?{fullArticlePath: string, fullScriptPath: string, wikiProject: WikiProject}>,
37
37
  * urlToIdString: Map<string, ?string>,
38
- * idStringToUrl: Map<string, ?string>
38
+ * idStringToUrl: Map<string, ?string>,
39
+ * inputToFrontendProxy: Map<string, ?{fullNamePath: string, fullArticlePath: string, fullScriptPath: string, frontendProxy: FrontendProxy}>,
40
+ * urlToFix: Map<string, ?((href:String,pagelink:String)=>String)>
39
41
  * }}
40
42
  */
41
43
  const functionCache = {
@@ -92,6 +94,10 @@ function inputToWikiProject(input) {
92
94
  fullScriptPath: 'https://' + regex[1] + scriptPath,
93
95
  wikiProject: wikiProject
94
96
  };
97
+ if ( result.fullArticlePath.includes('?') && !result.fullArticlePath.endsWith('=') ) {
98
+ result.fullArticlePath = result.fullArticlePath.replace( '?', '$1?' );
99
+ }
100
+ else result.fullArticlePath += '$1';
95
101
  }
96
102
  }
97
103
  functionCache.inputToWikiProject.set(input, result);
@@ -160,6 +166,10 @@ function inputToFrontendProxy(input) {
160
166
  fullScriptPath: frontendProxy.scriptPath.replace( /\$(\d)/g, (match, n) => regex[n] ),
161
167
  frontendProxy: frontendProxy
162
168
  };
169
+ if ( result.fullArticlePath.includes('?') && !result.fullArticlePath.endsWith('=') ) {
170
+ result.fullArticlePath = result.fullArticlePath.replace( '?', '$1?' );
171
+ }
172
+ else result.fullArticlePath += '$1';
163
173
  }
164
174
  }
165
175
  functionCache.inputToFrontendProxy.set(input, result);
@@ -176,9 +186,26 @@ function urlToFix(url) {
176
186
  if ( functionCache.urlToFix.has(hostname) ) return functionCache.urlToFix.get(hostname);
177
187
  let result = null;
178
188
  let frontendProxy = frontendProxies.find( frontendProxy => hostname.endsWith( frontendProxy.name ) );
179
- if ( frontendProxy?.namePath.split('/').length > 4 ) {
189
+ if ( frontendProxy ) {
180
190
  let splitLength = frontendProxy.namePath.split('/').length;
181
- result = (href, pagelink) => '/' + pagelink.split('/', splitLength).slice(3, -1).join('/') + href;
191
+ let querykeys = frontendProxy.namePath.split('?').slice(1).join('?').split('&').flatMap( query => query.split('=', 1) );
192
+ if ( splitLength > 4 && querykeys.length ) {
193
+ result = (href, pagelink) => {
194
+ let prepend = '/' + pagelink.split('/', splitLength).slice(3, -1).join('/');
195
+ let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
196
+ let append = ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
197
+ return prepend + href + append;
198
+ };
199
+ }
200
+ else if ( splitLength > 4 ) {
201
+ result = (href, pagelink) => '/' + pagelink.split('/', splitLength).slice(3, -1).join('/') + href;
202
+ }
203
+ else if ( querykeys.length ) {
204
+ result = (href, pagelink) => {
205
+ let querystring = pagelink.split('?').slice(1).join('?').split('&').filter( query => querykeys.includes( query.split('=', 1)[0] ) );
206
+ return href + ( href.includes('?') ? '&' : '?' ) + querystring.join('&');
207
+ }
208
+ }
182
209
  }
183
210
  functionCache.urlToFix.set(hostname, result);
184
211
  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.0.0",
4
4
  "type": "commonjs",
5
5
  "description": "List of MediaWiki projects for use in discord-wiki-bot",
6
6
  "main": "index.js",
package/projects.json CHANGED
@@ -1,6 +1,13 @@
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/|/?$)",