Skip to content

Commit

Permalink
Merge pull request #389 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Sep 10, 2020
2 parents ac8795a + 8405a95 commit f3da84d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 42 deletions.
File renamed without changes.
15 changes: 11 additions & 4 deletions builds/wtf_wikipedia-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* wtf_wikipedia 8.5.0 MIT */
/* wtf_wikipedia 8.5.1 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -3623,7 +3623,6 @@

var parse$3 = parser;

//also called 'citations'
var Reference = function Reference(data) {
Object.defineProperty(this, 'data', {
enumerable: false,
Expand Down Expand Up @@ -3662,7 +3661,15 @@
return ''; //nah, skip these.
},
json: function json() {
return this.data;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var json = this.data || {}; //encode them, for mongodb

if (options.encode === true) {
json = Object.assign({}, json);
json = encode.encodeObj(json);
}

return json;
}
};
Object.keys(methods$5).forEach(function (k) {
Expand Down Expand Up @@ -8964,7 +8971,7 @@

var category = fetchCategory;

var _version = '8.5.0';
var _version = '8.5.1';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
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.

15 changes: 11 additions & 4 deletions builds/wtf_wikipedia.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* wtf_wikipedia 8.5.0 MIT */
/* wtf_wikipedia 8.5.1 MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('https')) :
typeof define === 'function' && define.amd ? define(['https'], factory) :
Expand Down Expand Up @@ -3627,7 +3627,6 @@

var parse$3 = parser;

//also called 'citations'
var Reference = function Reference(data) {
Object.defineProperty(this, 'data', {
enumerable: false,
Expand Down Expand Up @@ -3666,7 +3665,15 @@
return ''; //nah, skip these.
},
json: function json() {
return this.data;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var json = this.data || {}; //encode them, for mongodb

if (options.encode === true) {
json = Object.assign({}, json);
json = encode.encodeObj(json);
}

return json;
}
};
Object.keys(methods$5).forEach(function (k) {
Expand Down Expand Up @@ -8984,7 +8991,7 @@

var category = fetchCategory;

var _version = '8.5.0';
var _version = '8.5.1';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
Expand Down
15 changes: 11 additions & 4 deletions builds/wtf_wikipedia.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* wtf_wikipedia 8.5.0 MIT */
/* wtf_wikipedia 8.5.1 MIT */
import https from 'https';

var parseUrl = function parseUrl(url) {
Expand Down Expand Up @@ -3619,7 +3619,6 @@ var parser = function parser(tmpl, order, fmt) {

var parse$3 = parser;

//also called 'citations'
var Reference = function Reference(data) {
Object.defineProperty(this, 'data', {
enumerable: false,
Expand Down Expand Up @@ -3658,7 +3657,15 @@ var methods$5 = {
return ''; //nah, skip these.
},
json: function json() {
return this.data;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var json = this.data || {}; //encode them, for mongodb

if (options.encode === true) {
json = Object.assign({}, json);
json = encode.encodeObj(json);
}

return json;
}
};
Object.keys(methods$5).forEach(function (k) {
Expand Down Expand Up @@ -8976,7 +8983,7 @@ var fetchCategory = function fetchCategory(category, lang, options) {

var category = fetchCategory;

var _version = '8.5.0';
var _version = '8.5.1';

var wtf = function wtf(wiki, options) {
return _01Document(wiki, options);
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#### [unreleased]

#### 8.5.1

- fix reference json encoding for mongodb

#### 8.5.0

- fix for cross-domain 3rd-party wikis
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "wtf_wikipedia",
"description": "parse wikiscript into json",
"version": "8.5.0",
"version": "8.5.1",
"author": "Spencer Kelly <[email protected]> (http://spencermounta.in)",
"repository": {
"type": "git",
"url": "git://github.com/spencermountain/wtf_wikipedia.git"
},
"man": [
"./src/man/wtf_wikipedia.1"
"./builds/man/wtf_wikipedia.1"
],
"main": "builds/wtf_wikipedia.js",
"module": "builds/wtf_wikipedia.mjs",
Expand Down
21 changes: 6 additions & 15 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ wtf.extend(require('./plugins/wikitext/src'))
// console.log(doc.images().map((j) => j.url()))
// })

let str = `{{Gallery
|title=Cultural depictions of George Washington
|width=160 | height=170
|align=center
|footer=Example 1
|File:VeryCool.JPG
|alt1=Statue facing a city building with Greek columns and huge U.S. flag
}}`

let doc = wtf(str, { domain: 'cool.com' })
console.log(doc.template())
let str = `
<ref name="Bond">{{cite magazine |last=Bond |first=Brian |date=October 1963 |title=Amritsar 1919 |magazine=History Today |volume=13 |uitgawe=10 |bls.=666–676}}</ref>
`
let doc = wtf(str)
let json = doc.json({ encode: true }).sections[0].references
console.log(json)
// console.log(doc.infobox().image().url())
// console.log(doc.images().map((img) => img.url()))

wtf.fetch('https://doom.fandom.com/wiki/Samuel_Hayden').then((doc) => {
console.log(doc.images().map((img) => img.url()))
})
2 changes: 1 addition & 1 deletion src/_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '8.5.0'
module.exports = '8.5.1'
28 changes: 18 additions & 10 deletions src/reference/Reference.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const encode = require('../_lib/encode')

//also called 'citations'
const Reference = function(data) {
const Reference = function (data) {
Object.defineProperty(this, 'data', {
enumerable: false,
value: data
value: data,
})
}

const methods = {
title: function() {
title: function () {
let data = this.data
return data.title || data.encyclopedia || data.author || ''
},
links: function(n) {
links: function (n) {
let arr = []
if (typeof n === 'number') {
return arr[n]
Expand All @@ -22,20 +24,26 @@ const methods = {
} else if (typeof n === 'string') {
//grab a link like .links('Fortnight')
n = n.charAt(0).toUpperCase() + n.substring(1) //titlecase it
let link = arr.find(o => o.page() === n)
let link = arr.find((o) => o.page() === n)
return link === undefined ? [] : [link]
}
return arr || []
},
text: function() {
text: function () {
return '' //nah, skip these.
},

json: function() {
return this.data
}
json: function (options = {}) {
let json = this.data || {}
//encode them, for mongodb
if (options.encode === true) {
json = Object.assign({}, json)
json = encode.encodeObj(json)
}
return json
},
}
Object.keys(methods).forEach(k => {
Object.keys(methods).forEach((k) => {
Reference.prototype[k] = methods[k]
})
module.exports = Reference

0 comments on commit f3da84d

Please sign in to comment.