Skip to content

Commit

Permalink
Merge pull request #556 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain committed Sep 27, 2023
2 parents d9ba589 + 7311361 commit c2ea471
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 25 deletions.
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.

11 changes: 9 additions & 2 deletions builds/wtf_wikipedia.cjs
Expand Up @@ -179,12 +179,18 @@
* @returns {*} result
*/
const getResult = function (data, options = {}) {
// handle nothing found or no data passed
if(!data?.query?.pages || !data?.query || !data){
return null
}

//get all the pagesIds from the result
let pages = Object.keys(data.query.pages);

// map over the pageIds to parse out all the information
return pages.map((id) => {
// get the page by pageID

let page = data.query.pages[id] || {};

// if the page is missing or not found than return null
Expand Down Expand Up @@ -1982,13 +1988,14 @@
'source',
'syntaxhighlight',
'timeline',
'maplink',
];
const openTag = `< ?(${ignore$1.join('|')}) ?[^>]{0,200}?>`;
const closeTag = `< ?/ ?(${ignore$1.join('|')}) ?>`;
const anyChar = '\\s\\S'; //including newline
const noThanks = new RegExp(`${openTag}[${anyChar}]+?${closeTag}`, 'gi');

const kill_xml = function (wiki) {
const kill_xml = function(wiki) {
//(<ref> tags are parsed in Section class) - luckily, refs can't be recursive.
//types of html/xml that we want to trash completely.
wiki = wiki.replace(noThanks, ' ');
Expand Down Expand Up @@ -10513,7 +10520,7 @@
})
};

var version = '10.1.6';
var version = '10.1.7';

/**
* use the native client-side fetch function
Expand Down
11 changes: 9 additions & 2 deletions builds/wtf_wikipedia.mjs
Expand Up @@ -175,12 +175,18 @@ const makeUrl = function (options, parameters = defaults$c) {
* @returns {*} result
*/
const getResult = function (data, options = {}) {
// handle nothing found or no data passed
if(!data?.query?.pages || !data?.query || !data){
return null
}

//get all the pagesIds from the result
let pages = Object.keys(data.query.pages);

// map over the pageIds to parse out all the information
return pages.map((id) => {
// get the page by pageID

let page = data.query.pages[id] || {};

// if the page is missing or not found than return null
Expand Down Expand Up @@ -1978,13 +1984,14 @@ const ignore$1 = [
'source',
'syntaxhighlight',
'timeline',
'maplink',
];
const openTag = `< ?(${ignore$1.join('|')}) ?[^>]{0,200}?>`;
const closeTag = `< ?/ ?(${ignore$1.join('|')}) ?>`;
const anyChar = '\\s\\S'; //including newline
const noThanks = new RegExp(`${openTag}[${anyChar}]+?${closeTag}`, 'gi');

const kill_xml = function (wiki) {
const kill_xml = function(wiki) {
//(<ref> tags are parsed in Section class) - luckily, refs can't be recursive.
//types of html/xml that we want to trash completely.
wiki = wiki.replace(noThanks, ' ');
Expand Down Expand Up @@ -10509,7 +10516,7 @@ const fetch = function (title, options, callback) {
})
};

var version = '10.1.6';
var version = '10.1.7';

/**
* use the native client-side fetch function
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Expand Up @@ -4,6 +4,9 @@
-->

#### 10.1.7 [Sep 2023]
- **[fix]** - don't crash on huge geojson blob #555

#### 10.1.6 [Sep 2023]

- **[change]** - handle fetch data errors
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "wtf_wikipedia",
"description": "parse wikiscript into json",
"version": "10.1.6",
"version": "10.1.7",
"main": "src/index.js",
"module": "builds/wtf_wikipedia.mjs",
"unpkg": "builds/wtf_wikipedia-client.min.js",
Expand Down
49 changes: 32 additions & 17 deletions scratch.js
@@ -1,23 +1,38 @@
import wtf from './src/index.js'
import plg from './plugins/i18n/src/index.js'
wtf.plugin(plg)
console.log('start')

let str = `#AANSTUUR[[Xai-Xai]]
`
// let str = ` {{font|text=也可以只選用其中一項選項。|size=25px}} `
let doc = wtf(str)
console.log(doc.text())
// doc.templates().map((s) => s.json())
// console.log(doc.templates()[4].json())
let str = `hello
{{usableitinerary}}
{{PartOfItinerary|North America itineraries}}
<maplink text="" zoom="5" group="route1" class="no-icon">
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[
-117.02964,
32.54259
],
[
-117.03059,
32.54305
]
// let doc = await wtf.fetch("Space_disco", "it")
// console.log(doc.text())
// trunc
// wtf.fetch("2007 FIFA Women's World Cup Group A", "en")
]
}
}
]
}
// fails on percentage template
// wtf.fetch("Sacramento Mountain Lions", "es")
</maplink>
`
// let doc = wtf(str)
const doc = await wtf.fetch('https://en.wikivoyage.org/wiki/Interstate_5');

// fails on min template
// wtf.fetch("Phase finale du Championnat du monde masculin de handball 2019", "fr")
console.log(doc.text());
1 change: 1 addition & 0 deletions src/01-document/preProcess/kill_xml.js
Expand Up @@ -17,6 +17,7 @@ const ignore = [
'source',
'syntaxhighlight',
'timeline',
'maplink',
]
const openTag = `< ?(${ignore.join('|')}) ?[^>]{0,200}?>`
const closeTag = `< ?/ ?(${ignore.join('|')}) ?>`
Expand Down
6 changes: 6 additions & 0 deletions src/_fetch/getResult.js
Expand Up @@ -9,12 +9,18 @@
* @returns {*} result
*/
const getResult = function (data, options = {}) {
// handle nothing found or no data passed
if(!data?.query?.pages || !data?.query || !data){
return null
}

//get all the pagesIds from the result
let pages = Object.keys(data.query.pages)

// map over the pageIds to parse out all the information
return pages.map((id) => {
// get the page by pageID

let page = data.query.pages[id] || {}

// if the page is missing or not found than return null
Expand Down
2 changes: 1 addition & 1 deletion src/_version.js
@@ -1 +1 @@
export default '10.1.6'
export default '10.1.7'

0 comments on commit c2ea471

Please sign in to comment.