dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

mainImage does not work for fr.wikipedia.org #156

Closed horohoro closed 2 years ago

horohoro commented 3 years ago

For pages of fr.wikipedia.org it seems that Page.mainImage() does not return right image. Maybe it fails to find the infobox.

For example, applying it on https://fr.wikipedia.org/wiki/Sigmund_Freud returned me https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/1933-may-10-berlin-book-burning.JPG/1280px-1933-may-10-berlin-book-burning.JPG

If I tried it on https://en.wikipedia.org/wiki/Sigmund_Freud it properly returned me https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Sigmund_Freud%2C_by_Max_Halberstadt_%28cropped%29.jpg/800px-Sigmund_Freud%2C_by_Max_Halberstadt_%28cropped%29.jpg

Note: to be clear when I say I tried on a page it means that I had set properly the apiUrl option to hit the right endpoint of the wiki api.

I am not sure if the issue reproduces for other languages.

horohoro commented 3 years ago

Here is an example:

const wiki = require('wikijs').default;
const WIKI_API = {
   en: 'https://en.wikipedia.org/w/api.php',
   fr: 'https://fr.wikipedia.org/w/api.php'
}
function test(apiUrl, name) {
    wiki({apiUrl: apiUrl}).page(name).then(page => {
        console.log(page.canonicalurl);
        return page.mainImage()
    }).then(mainImage => console.log(mainImage))
}
test(WIKI_API.fr, "Sigmund Freud")

Output:

https://fr.wikipedia.org/wiki/Sigmund_Freud
https://upload.wikimedia.org/wikipedia/commons/2/2b/1933-may-10-berlin-book-burning.JPG
dijs commented 2 years ago

v6.3.1 fixes this issue

Thanks for pointing it out!