Skip to content

Commit

Permalink
chore(source-wikipedia): ugrade dependencies (#23810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slashgear authored May 6, 2020
1 parent f35545e commit 9275666
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
5 changes: 3 additions & 2 deletions packages/gatsby-source-wikipedia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
},
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.9.6",
"axios": "^0.19.2"
"bluebird": "^3.7.2",
"node-fetch": "^2.6.0",
"query-string": "^6.12.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down
57 changes: 28 additions & 29 deletions packages/gatsby-source-wikipedia/src/fetch.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const Promise = require(`bluebird`)
var querystring = require(`querystring`)
var axios = require(`axios`)
const queryString = require(`query-string`)
const fetch = require(`node-fetch`)

var apiBase = `https://en.wikipedia.org/w/api.php?`
var viewBase = `https://en.m.wikipedia.org/wiki/`
const apiBase = `https://en.wikipedia.org/w/api.php?`

const fetchNodesFromSearch = ({ query, limit = 15 }) =>
search({ query, limit }).then(results =>
Expand All @@ -22,19 +21,18 @@ const fetchNodesFromSearch = ({ query, limit = 15 }) =>
)

const getMetaData = name =>
axios(
apiBase +
querystring.stringify({
action: `query`,
titles: name,
format: `json`,
redirects: `resolve`,
prop: `extracts|revisions`,
explaintext: 1,
exsentences: 1,
})
fetch(
`${apiBase}${queryString.stringify({
action: `query`,
titles: name,
format: `json`,
redirects: `resolve`,
prop: `extracts|revisions`,
explaintext: 1,
exsentences: 1,
})}`
)
.then(r => r.data)
.then(response => response.json())
.then(data => {
var page = data.query.pages[Object.keys(data.query.pages)[0]]

Expand All @@ -57,17 +55,16 @@ const getMetaData = name =>
})

const search = ({ query, limit }) =>
axios(
apiBase +
querystring.stringify({
action: `opensearch`,
search: query,
format: `json`,
redirects: `resolve`,
limit,
})
fetch(
`${apiBase}${queryString.stringify({
action: `opensearch`,
search: query,
format: `json`,
redirects: `resolve`,
limit,
})}`
)
.then(r => r.data)
.then(response => response.json())
.then(([term, pageTitles, descriptions, urls]) =>
pageTitles.map((title, i) => {
return {
Expand All @@ -79,8 +76,10 @@ const search = ({ query, limit }) =>
)

const getArticle = name =>
axios(viewBase + name + `?action=render`).then(r =>
r.data.replace(/\/\/en\.wikipedia\.org\/wiki\//g, `/wiki/`)
)
fetch(`https://en.m.wikipedia.org/wiki/${name}?action=render`)
.then(res => res.text())
.then(pageContent =>
pageContent.replace(/\/\/en\.wikipedia\.org\/wiki\//g, `/wiki/`)
)

module.exports = { fetchNodesFromSearch, getMetaData, getArticle, search }

0 comments on commit 9275666

Please sign in to comment.