README
npm install wtf-plugin-image
Some additional methods for using and rendering images in wtf_wikipedia
const wtf = require('wtf_wikipedia')
wtf.extend(require('wtf-plugin-markdown'))
wtf.fetch('casa', { lang:'it', wiki: `wiktionary` }).then(async function(doc) {
let image = doc.images(0)
// make a {method: 'HEAD'} request to test the image is there
let bool = await image.exists()
//instead of using the redirect api, generate a direct img url
let url = image.commonsURL()
//https://upload.wikimedia.org/wikipedia/commons/4/4e/RybnoeDistrict_06-13_Konstantinovo_village_05.jpg
let img = doc.mainImage()
//
})
plugin also has a method for choosing a good, or representative image for this page, if it exists:
// choose a good image for this article
let doc = await wtf.fetch('Toronto')
let img = doc.mainImage()
console.log(img.src())
// https://wikipedia.org/wiki/Special:Redirect/file/Toronto_Flag.svg
API
- image.exists() - double-check that the image is on the server
- image.commonsURL() - instead of the wikimedia redirect server, generate a url for the commons server.
- image.mainImage() - get only an image that should represent this topic, as a thumbnail.
MIT