Skip to content

Commit

Permalink
Merge pull request #486 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain committed May 30, 2022
2 parents e54bf0d + 358579b commit 670a3bc
Show file tree
Hide file tree
Showing 77 changed files with 9,509 additions and 9,151 deletions.
4 changes: 2 additions & 2 deletions builds/wtf_wikipedia-client.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions builds/wtf_wikipedia-client.mjs

Large diffs are not rendered by default.

66 changes: 39 additions & 27 deletions builds/wtf_wikipedia.cjs
@@ -1,4 +1,4 @@
/*! wtf_wikipedia 10.0.0 MIT */
/*! wtf_wikipedia 10.0.1 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('isomorphic-unfetch')) :
typeof define === 'function' && define.amd ? define(['isomorphic-unfetch'], factory) :
Expand Down Expand Up @@ -888,6 +888,8 @@
return h
}, {});

const mayAlsoReg = /. may (also )?refer to\b/i;

const inTitle = new RegExp('. \\((' + disambig_titles.join('|') + ')\\)$', 'i');
const i18n_templates = disambig_templates.reduce((h, str) => {
h[str] = true;
Expand All @@ -901,7 +903,7 @@
}
let txt = s.text();
if (txt !== null && txt[0]) {
if (/. may (also)? refer to\b/i.test(txt) === true) {
if (mayAlsoReg.test(txt) === true) {
return true
}
}
Expand Down Expand Up @@ -6219,10 +6221,17 @@
},
// https://en.wikipedia.org/wiki/Template:Blockquote
blockquote: (tmpl, list) => {
let obj = parser(tmpl);
let props = ['text', 'author', 'title', 'source', 'character'];
let obj = parser(tmpl, props);
list.push(obj);
let txt = obj.text;
// used first un-named param
if (!txt) {
obj.list = obj.list || [];
txt = obj.list[0] || '';
}
// replace double quotes with singles and put the text inside double quotes
let result = (obj.text || obj.list[0]).replace(/"/g, '\'');
let result = txt.replace(/"/g, '\'');
result = '"' + result + '"';
return result
}
Expand Down Expand Up @@ -7909,32 +7918,30 @@
* @param {object} catcher
*/
const parseMlb = function (catcher) {
catcher.text = catcher.text.replace(
/\{\{mlb game log (section|month)[\s\S]+?\{\{mlb game log (section|month) end\}\}/gi,
(tmpl) => {
let headings = whichHeadings(tmpl);
catcher.text = catcher.text.replace(/\{\{mlb game log /gi, '{{game log ');
catcher.text = catcher.text.replace(/\{\{game log (section|month)[\s\S]+?\{\{game log (section|month) end\}\}/gi, (tmpl) => {
let headings = whichHeadings(tmpl);

tmpl = tmpl.replace(/^\{\{.*?\}\}/, '');
tmpl = tmpl.replace(/\{\{mlb game log (section|month) end\}\}/i, '');

let headers = '! ' + headings.join(' !! ');
let table = '{|\n' + headers + '\n' + tmpl + '\n|}';
let rows = parseTable(table);
rows = rows.map((row) => {
Object.keys(row).forEach((k) => {
row[k] = row[k].text();
});
return row
});
tmpl = tmpl.replace(/^\{\{.*?\}\}/, '');
tmpl = tmpl.replace(/\{\{game log (section|month) end\}\}/i, '');

catcher.templates.push({
template: 'mlb game log section',
data: rows,
let headers = '! ' + headings.join(' !! ');
let table = '{|\n' + headers + '\n' + tmpl + '\n|}';
let rows = parseTable(table);
rows = rows.map((row) => {
Object.keys(row).forEach((k) => {
row[k] = row[k].text();
});
return row
});
catcher.templates.push({
template: 'mlb game log section',
data: rows,
});

//return empty string to remove the template from the wiki text
return ''
}
//return empty string to remove the template from the wiki text
return ''
}
);
};

Expand Down Expand Up @@ -9371,7 +9378,7 @@
})
};

var version = '10.0.0';
var version = '10.0.1';

/**
* use the native client-side fetch function
Expand All @@ -9384,6 +9391,11 @@
const request = function (url, opts) {
return unfetch__default["default"](url, opts).then(function (res) {
return res.json()
}).catch((e) => {
console.error('\n\n=-=- http response error =-=-=-');
console.log(url);
console.log(e);
return {}
})
};

Expand Down
66 changes: 39 additions & 27 deletions builds/wtf_wikipedia.mjs
@@ -1,4 +1,4 @@
/*! wtf_wikipedia 10.0.0 MIT */
/*! wtf_wikipedia 10.0.1 MIT */
import unfetch from 'isomorphic-unfetch';

/**
Expand Down Expand Up @@ -880,6 +880,8 @@ const templates$a = [
return h
}, {});

const mayAlsoReg = /. may (also )?refer to\b/i;

const inTitle = new RegExp('. \\((' + disambig_titles.join('|') + ')\\)$', 'i');
const i18n_templates = disambig_templates.reduce((h, str) => {
h[str] = true;
Expand All @@ -893,7 +895,7 @@ const byText = function (s) {
}
let txt = s.text();
if (txt !== null && txt[0]) {
if (/. may (also)? refer to\b/i.test(txt) === true) {
if (mayAlsoReg.test(txt) === true) {
return true
}
}
Expand Down Expand Up @@ -6211,10 +6213,17 @@ let templates$3 = {
},
// https://en.wikipedia.org/wiki/Template:Blockquote
blockquote: (tmpl, list) => {
let obj = parser(tmpl);
let props = ['text', 'author', 'title', 'source', 'character'];
let obj = parser(tmpl, props);
list.push(obj);
let txt = obj.text;
// used first un-named param
if (!txt) {
obj.list = obj.list || [];
txt = obj.list[0] || '';
}
// replace double quotes with singles and put the text inside double quotes
let result = (obj.text || obj.list[0]).replace(/"/g, '\'');
let result = txt.replace(/"/g, '\'');
result = '"' + result + '"';
return result
}
Expand Down Expand Up @@ -7901,32 +7910,30 @@ const whichHeadings = function (tmpl) {
* @param {object} catcher
*/
const parseMlb = function (catcher) {
catcher.text = catcher.text.replace(
/\{\{mlb game log (section|month)[\s\S]+?\{\{mlb game log (section|month) end\}\}/gi,
(tmpl) => {
let headings = whichHeadings(tmpl);
catcher.text = catcher.text.replace(/\{\{mlb game log /gi, '{{game log ');
catcher.text = catcher.text.replace(/\{\{game log (section|month)[\s\S]+?\{\{game log (section|month) end\}\}/gi, (tmpl) => {
let headings = whichHeadings(tmpl);

tmpl = tmpl.replace(/^\{\{.*?\}\}/, '');
tmpl = tmpl.replace(/\{\{mlb game log (section|month) end\}\}/i, '');

let headers = '! ' + headings.join(' !! ');
let table = '{|\n' + headers + '\n' + tmpl + '\n|}';
let rows = parseTable(table);
rows = rows.map((row) => {
Object.keys(row).forEach((k) => {
row[k] = row[k].text();
});
return row
});
tmpl = tmpl.replace(/^\{\{.*?\}\}/, '');
tmpl = tmpl.replace(/\{\{game log (section|month) end\}\}/i, '');

catcher.templates.push({
template: 'mlb game log section',
data: rows,
let headers = '! ' + headings.join(' !! ');
let table = '{|\n' + headers + '\n' + tmpl + '\n|}';
let rows = parseTable(table);
rows = rows.map((row) => {
Object.keys(row).forEach((k) => {
row[k] = row[k].text();
});
return row
});
catcher.templates.push({
template: 'mlb game log section',
data: rows,
});

//return empty string to remove the template from the wiki text
return ''
}
//return empty string to remove the template from the wiki text
return ''
}
);
};

Expand Down Expand Up @@ -9363,7 +9370,7 @@ const fetch = function (title, options, callback) {
})
};

var version = '10.0.0';
var version = '10.0.1';

/**
* use the native client-side fetch function
Expand All @@ -9376,6 +9383,11 @@ var version = '10.0.0';
const request = function (url, opts) {
return unfetch(url, opts).then(function (res) {
return res.json()
}).catch((e) => {
console.error('\n\n=-=- http response error =-=-=-');
console.log(url);
console.log(e);
return {}
})
};

Expand Down
8 changes: 7 additions & 1 deletion changelog.md
@@ -1,11 +1,17 @@
<!--
#### [unreleased ]
-->
#### 10.0.1 [May 2022]
- **[fix]** - runtime error #484
- **[new]** - wtf-plugin-sports for tricky nhl and mlb templates
- **[change]** - .random() in api-plugin parses document
- **[change]** - update dependencies

#### 10.0.0 [April 2022]
- **[breaking]** - drop IE11 support - target evergreen browsers
- **[change]** - convert to esmodules internally
- **[change]** - add blockquote template
update deps
- **[change]** - update dependencies

#### 9.1.0 [March 2022]
- **[change]** - support inline templates inside section titles
Expand Down

0 comments on commit 670a3bc

Please sign in to comment.