dijs / wiki

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

Get Wikipedia Source url? #117

Closed Zel9278 closed 5 years ago

Zel9278 commented 5 years ago

I use this module using Wikipedia's api. However, I noticed that I could not display Wikipedia links.

dijs commented 5 years ago

Could you please provide a code example showing the issue?

Zel9278 commented 5 years ago

Could you please provide a code example showing the issue?

    const page = await wiki.page('Wikipedia');
    const summary = await page.summary();
    const images = await page.mainImage();
    const noi = `${images ? `${images}` : "画像が見つかりませんでした。"}`;
    const noi2 = `${images ? `${images}` : "https://sitechecker.pro/wp-content/uploads/2017/12/404.png"}`;
         message.channel.send({
            embed: {
                color: 2500351,
                title: `Wikipediaの検索結果(Wikipedia)`,
                description: summary,
                timestamp: new Date(),
                footer: {
                    icon_url: message.author.avatarURL,
                    text: `実行者: ${message.author.tag}`,
                },
                thumbnail: {
                    url: noi2
                },
                fields: [
                    {
                        name: "links",
                        value: '無いよ',
                    },
                ],
            },
        }).catch(error => message.reply(`${error}のためメッセージを表示できませんでした`));

(Sorry Japanese)

dijs commented 5 years ago

Could you please give a much more specific issue.

What exactly is not returning what you expect?

I did notice that the Wikipedia page gives undefined for a mainImage, is this what you are speaking of?

Zel9278 commented 5 years ago

No, I just want to show the Wikipedia article link, but I do not know what to do https://ja.wikipedia.org/wiki/Wikipedia

I want to display this.

kurai021 commented 5 years ago

I have this simple example


var wikijs = require("wikijs").default;

wikijs({
        apiUrl: 'https://es.wikipedia.org/w/api.php',
        origin: null
    })
    .page("djinn")
    .then(async data => {
        console.log(data.raw.canonicalurl) //the URL for the Wikipedia article is here
        return data.summary();
    })
    .then (async res => {
        let firstChars = res.split('\n')[0] + "...";
        console.log(firstChars)
    })```
dijs commented 5 years ago

Thanks! I will add a method for getting that value easily.

dijs commented 5 years ago

Will be published in v5.3.0

Zel9278 commented 5 years ago

Will be published in v5.3.0

Thanks!