Skip to content

Commit

Permalink
Merge pull request #494 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain committed Jul 27, 2022
2 parents c5e86ca + 1cddb43 commit b406391
Show file tree
Hide file tree
Showing 35 changed files with 463 additions and 236 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.

49 changes: 42 additions & 7 deletions builds/wtf_wikipedia.cjs
@@ -1,4 +1,4 @@
/*! wtf_wikipedia 10.0.1 MIT */
/*! wtf_wikipedia 10.0.2 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 @@ -890,6 +890,16 @@

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

// templates that signal page is not a disambiguation
const notDisambig = {
about: true,
for: true,
'for multi': true,
'other people': true,
'other uses of': true,
'distinguish': true
};

const inTitle = new RegExp('. \\((' + disambig_titles.join('|') + ')\\)$', 'i');
const i18n_templates = disambig_templates.reduce((h, str) => {
h[str] = true;
Expand Down Expand Up @@ -931,6 +941,11 @@
if (title && inTitle.test(title) === true) {
return true
}
// does it have a non-disambig template?
let notDisamb = templates.find((obj) => notDisambig.hasOwnProperty(obj.template));
if (notDisamb) {
return false
}
//try 'may refer to' on first line for en-wiki?
if (byText(doc.sentence(0)) === true || byText(doc.sentence(1)) === true) {
return true
Expand Down Expand Up @@ -3770,7 +3785,7 @@
const list_reg = /^[#*:;|]+/;
const bullet_reg = /^\*+[^:,|]{4}/;
const number_reg = /^ ?#[^:,|]{4}/;
const has_word = /[a-z_0-9\]}]/i;
const has_word = /[\p{Letter}_0-9\]}]/iu;

// does it start with a bullet point or something?
const isList = function (line) {
Expand Down Expand Up @@ -4252,7 +4267,6 @@
'tl2',
'tlu',
'demo',
'hatnote',
'xpd',
'para',
'elc',
Expand Down Expand Up @@ -4354,7 +4368,6 @@
'big',
'cquote',
'pull quote',
'small',
'smaller',
'midsize',
'larger',
Expand Down Expand Up @@ -4387,6 +4400,11 @@
'mvar',
'pre2',
'code',
'char',
'angle bracket',
'angbr',
'symb',
'key press', //needs work - https://en.m.wikipedia.org/wiki/Template:Key_press
];
zeros.forEach((k) => {
templates$9[k] = 0;
Expand Down Expand Up @@ -4880,6 +4898,14 @@
}
return num + '%'
},
// this one is re-used by i18n
small: (tmpl) => {
let obj = parser(tmpl);
if (obj.list && obj.list[0]) {
return obj.list[0]
}
return ''
},

// {{Percent-done|done=N|total=N|digits=N}}
'percent-done': (tmpl) => {
Expand Down Expand Up @@ -5828,6 +5854,7 @@
'taxon info': ['taxon', 'item'], //https://en.wikipedia.org/wiki/Template:Taxon_info
'portuguese name': ['first', 'second', 'suffix'], // https://en.wikipedia.org/wiki/Template:Portuguese_name
geo: ['lat', 'lon', 'zoom'], //https://en.wikivoyage.org/wiki/Template:Geo
hatnote: ['text']
};

templates$4 = Object.assign(
Expand Down Expand Up @@ -5891,6 +5918,14 @@
return '\n\n' + (obj.formula || '') + '\n\n'
},

//svg labels - https://en.m.wikipedia.org/wiki/Template:Legend
legend: (tmpl, list) => {
let order = ['color', 'label'];
let obj = parser(tmpl, order);
list.push(obj);
return obj.label || ' '
},

isbn: (tmpl, list) => {
let order = ['id', 'id2', 'id3'];
let obj = parser(tmpl, order);
Expand Down Expand Up @@ -9378,7 +9413,7 @@
})
};

var version = '10.0.1';
var version = '10.0.2';

/**
* use the native client-side fetch function
Expand All @@ -9393,8 +9428,8 @@
return res.json()
}).catch((e) => {
console.error('\n\n=-=- http response error =-=-=-');
console.log(url);
console.log(e);
console.error(url);
console.error(e);
return {}
})
};
Expand Down
49 changes: 42 additions & 7 deletions builds/wtf_wikipedia.mjs
@@ -1,4 +1,4 @@
/*! wtf_wikipedia 10.0.1 MIT */
/*! wtf_wikipedia 10.0.2 MIT */
import unfetch from 'isomorphic-unfetch';

/**
Expand Down Expand Up @@ -882,6 +882,16 @@ const templates$a = [

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

// templates that signal page is not a disambiguation
const notDisambig = {
about: true,
for: true,
'for multi': true,
'other people': true,
'other uses of': true,
'distinguish': true
};

const inTitle = new RegExp('. \\((' + disambig_titles.join('|') + ')\\)$', 'i');
const i18n_templates = disambig_templates.reduce((h, str) => {
h[str] = true;
Expand Down Expand Up @@ -923,6 +933,11 @@ const isDisambig = function (doc) {
if (title && inTitle.test(title) === true) {
return true
}
// does it have a non-disambig template?
let notDisamb = templates.find((obj) => notDisambig.hasOwnProperty(obj.template));
if (notDisamb) {
return false
}
//try 'may refer to' on first line for en-wiki?
if (byText(doc.sentence(0)) === true || byText(doc.sentence(1)) === true) {
return true
Expand Down Expand Up @@ -3762,7 +3777,7 @@ Object.keys(methods$3).forEach((k) => {
const list_reg = /^[#*:;|]+/;
const bullet_reg = /^\*+[^:,|]{4}/;
const number_reg = /^ ?#[^:,|]{4}/;
const has_word = /[a-z_0-9\]}]/i;
const has_word = /[\p{Letter}_0-9\]}]/iu;

// does it start with a bullet point or something?
const isList = function (line) {
Expand Down Expand Up @@ -4244,7 +4259,6 @@ let multi = {
'tl2',
'tlu',
'demo',
'hatnote',
'xpd',
'para',
'elc',
Expand Down Expand Up @@ -4346,7 +4360,6 @@ let zeros = [
'big',
'cquote',
'pull quote',
'small',
'smaller',
'midsize',
'larger',
Expand Down Expand Up @@ -4379,6 +4392,11 @@ let zeros = [
'mvar',
'pre2',
'code',
'char',
'angle bracket',
'angbr',
'symb',
'key press', //needs work - https://en.m.wikipedia.org/wiki/Template:Key_press
];
zeros.forEach((k) => {
templates$9[k] = 0;
Expand Down Expand Up @@ -4872,6 +4890,14 @@ var functions = {
}
return num + '%'
},
// this one is re-used by i18n
small: (tmpl) => {
let obj = parser(tmpl);
if (obj.list && obj.list[0]) {
return obj.list[0]
}
return ''
},

// {{Percent-done|done=N|total=N|digits=N}}
'percent-done': (tmpl) => {
Expand Down Expand Up @@ -5820,6 +5846,7 @@ let templates$4 = {
'taxon info': ['taxon', 'item'], //https://en.wikipedia.org/wiki/Template:Taxon_info
'portuguese name': ['first', 'second', 'suffix'], // https://en.wikipedia.org/wiki/Template:Portuguese_name
geo: ['lat', 'lon', 'zoom'], //https://en.wikivoyage.org/wiki/Template:Geo
hatnote: ['text']
};

templates$4 = Object.assign(
Expand Down Expand Up @@ -5883,6 +5910,14 @@ let templates$3 = {
return '\n\n' + (obj.formula || '') + '\n\n'
},

//svg labels - https://en.m.wikipedia.org/wiki/Template:Legend
legend: (tmpl, list) => {
let order = ['color', 'label'];
let obj = parser(tmpl, order);
list.push(obj);
return obj.label || ' '
},

isbn: (tmpl, list) => {
let order = ['id', 'id2', 'id3'];
let obj = parser(tmpl, order);
Expand Down Expand Up @@ -9370,7 +9405,7 @@ const fetch = function (title, options, callback) {
})
};

var version = '10.0.1';
var version = '10.0.2';

/**
* use the native client-side fetch function
Expand All @@ -9385,8 +9420,8 @@ const request = function (url, opts) {
return res.json()
}).catch((e) => {
console.error('\n\n=-=- http response error =-=-=-');
console.log(url);
console.log(e);
console.error(url);
console.error(e);
return {}
})
};
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
@@ -1,6 +1,13 @@
<!--
#### [unreleased ]
-->
#### 10.0.2 [Jul 2022]
- **[fix]** - multiple inline templates in a heading #489
- **[fix]** - non-i18n list templates #475
- **[fix]** - don't print hatnotes in .text()
- **[update]** - api, i18n, sports plugins

#### 10.0.1 [May 2022]
- **[fix]** - runtime error #484
- **[new]** - wtf-plugin-sports for tricky nhl and mlb templates
Expand Down

0 comments on commit b406391

Please sign in to comment.