Skip to content

Commit

Permalink
Merge pull request #586 from spencermountain/dev
Browse files Browse the repository at this point in the history
10.4.0
  • Loading branch information
spencermountain authored Feb 2, 2025
2 parents 0e1146d + 015abc2 commit 1c2ac63
Show file tree
Hide file tree
Showing 56 changed files with 2,052 additions and 1,672 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

87 changes: 0 additions & 87 deletions .eslintrc

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ Some wikis, (like wikia) have intentionally disabled this.
wikitext is (amazingly) used across all languages, wikis, and even in right-to-left languages.
This parser actually does an okay job at it too.

Wikipedia I18n langauge information for _Redirects, Infoboxes, Categories, and Images_ are included in the library, with pretty-decent coverage.
Wikipedia I18n language information for _Redirects, Infoboxes, Categories, and Images_ are included in the library, with pretty-decent coverage.

To improve coverage of i18n templates, use [wtf-plugin-i18n](./plugins/i18n)

Expand All @@ -730,12 +730,12 @@ Please make a PR if you see something missing for your language.

## Builds:

this library ships seperate client-side and server-side builds, to preserve filesize.
this library ships separate client-side and server-side builds, to preserve filesize.

- _[./wtf_wikipedia-client.mjs](./builds/wtf_wikipedia-client.mjs)_ - as es-module (or Deno)
- _[./wtf_wikipedia-client.min.js](./builds/wtf_wikipedia-client.min.js)_ - for production

- _[./wtf_wikipedia.cjs](./builds/wtf_wikipedia.js)_ - node commonjs build
- _[./wtf_wikipedia.cjs](./builds/wtf_wikipedia.cjs)_ - node commonjs build
- _[./wtf_wikipedia.mjs](./builds/wtf_wikipedia.mjs)_ - node/deno/typescript esm build

the browser version uses `fetch()` and the server version uses `require('https')`.
Expand Down
2 changes: 1 addition & 1 deletion builds/wtf_wikipedia-client.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion builds/wtf_wikipedia-client.mjs

Large diffs are not rendered by default.

77 changes: 68 additions & 9 deletions builds/wtf_wikipedia.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @returns {{domain: string, title: string}} The domain and title of a url
*/
const parseUrl = function (url) {
let parsed = new URL(url); // eslint-disable-line
let parsed = new URL(url); //eslint-disable-line
let title = parsed.pathname.replace(/^\/(wiki\/)?/, '');
title = decodeURIComponent(title);
return {
Expand Down Expand Up @@ -1208,20 +1208,17 @@
let name = t.template || '';
// try i18n templates like 'stubo'
if (allStubs.has(name)) {
// console.log(name)
return true
}
// english forms
if (name === 'stub' || name.endsWith('-stub')) {
// console.log(name)
return true
}
// look for i18n in last-word, like {{foo-stubo}}
let words = name.split(/[- ]/);
if (words.length > 1) {
let word = words[words.length - 1];
if (allStubs.has(word)) {
// console.log(name)
return true
}
}
Expand Down Expand Up @@ -2157,7 +2154,6 @@
}
//kill off just these just-anchor links [[#history]]
// if (link.match(/^#/i)) {
// console.log(s)
// return s
// }
//remove anchors from end [[toronto#history]]
Expand Down Expand Up @@ -8399,6 +8395,33 @@
return str
};

const toTextBritish = function (date) {
//eg '1995'
let str = String(date.year || '');
if (date.month !== undefined && months$1.hasOwnProperty(date.month) === true) {
if (date.date === undefined) {
//January 1995
str = `${months$1[date.month]} ${date.year}`;
} else {
//5 January 1995
str = `${date.date} ${months$1[date.month]} ${date.year}`;
//add times, if available
if (date.hour !== undefined && date.minute !== undefined) {
let time = `${pad(date.hour)}:${pad(date.minute)}`;
if (date.second !== undefined) {
time = time + ':' + pad(date.second);
}
str = time + ', ' + str;
//add timezone, if there, at the end in brackets
}
if (date.tz) {
str += ` (${date.tz})`;
}
}
}
return str
};

// console.log(toText(ymd([2018, 3, 28])));

//wrap it up as a template
Expand Down Expand Up @@ -8785,6 +8808,36 @@
// 'birth date and age2': date,
// 'age in years, months, weeks and days': true,
// 'age as of date': true,
// https://en.wikipedia.org/wiki/Template:As_of
'as of': (tmpl) => {
let obj = parser(tmpl, ['year', 'month', 'day']);
if (obj.alt) {
return obj.alt
}
let out = 'As of ';
if (obj.since) {
out = 'Since ';
}
if (obj.lc) {
out = out.toLowerCase();
}
if (obj.bare) {
out = '';
}
if (obj.pre) {
out += obj.pre + ' ';
}
let format = toTextBritish;
if (obj.df == "US") {
format = toText;
}
let dateObj = ymd([obj.year, obj.month, obj.day]);
out += format(dateObj);
if (obj.post) {
out += obj.post;
}
return out
}
};

/**
Expand Down Expand Up @@ -9246,6 +9299,8 @@
sports,
);

/* eslint-disable no-console */

let templates = Object.assign({}, textTmpl, dataTmpl, bothTmpl);

Object.keys(aliases).forEach((k) => {
Expand All @@ -9255,8 +9310,6 @@
templates[k] = templates[aliases[k]];
});

// console.log(Object.keys(templates).length)

const nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

//this gets all the {{template}} objects and decides how to parse them
Expand Down Expand Up @@ -10518,7 +10571,7 @@
};
});

const heading_reg = /^(={1,6})(.{1,200}?)={1,6}$/;
const heading_reg = /^(={1,6})(.{1,200}?)={1,6}$/; //eslint-disable-line
const hasTemplate = /\{\{.+?\}\}/;

const doInlineTemplates = function (wiki, doc) {
Expand Down Expand Up @@ -10666,6 +10719,8 @@
return [categories, newWiki]
};

/* eslint-disable no-console */

const defaults$1 = {
tables: true,
lists: true,
Expand Down Expand Up @@ -11251,6 +11306,7 @@
* @returns {null| Document | Document[]} null if there are no results or Document if there is one responses and Document array if there are multiple responses
*/
const parseDoc = function (res, title) {
res = res || [];
// filter out undefined
res = res.filter((o) => o);

Expand Down Expand Up @@ -11303,6 +11359,7 @@
}
};

/* eslint-disable no-console */
const isUrl = /^https?:\/\//;

/**
Expand Down Expand Up @@ -11384,7 +11441,9 @@
})
};

var version = '10.3.2';
var version = '10.4.0';

/* eslint-disable no-console */

/**
* use the native client-side fetch function
Expand Down
Loading

0 comments on commit 1c2ac63

Please sign in to comment.