From 751c4bf980f3c41c54ba469fc5a4a90941e2f063 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 4 Oct 2018 22:01:21 +0000 Subject: [PATCH] Fix meme descriptions and thumbnails --- commands/search/know-your-meme.js | 16 ++++++++++++++-- package.json | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/commands/search/know-your-meme.js b/commands/search/know-your-meme.js index abc995ed..1c288c06 100644 --- a/commands/search/know-your-meme.js +++ b/commands/search/know-your-meme.js @@ -54,11 +54,23 @@ module.exports = class KnowYourMemeCommand extends Command { async fetchMeme(location) { const { text } = await request.get(`https://knowyourmeme.com${location}`); const $ = cheerio.load(text); + const thumbnail = $('a[class="photo left wide"]').first().attr('href') + || $('a[class="photo left "]').first().attr('href') + || null; return { name: $('h1').first().text().trim(), url: `https://knowyourmeme.com${location}`, - description: $('.bodycopy').children().eq(1).text(), - thumbnail: $('a[class="photo left wide"]').first().attr('href') || null + description: this.getMemeDescription($), + thumbnail }; } + + getMemeDescription($) { + const children = $('.bodycopy').first().children(); + for (let i = 0; i < children.length; i++) { + const child = children.eq(i); + if (child.text() === 'About') return children.eq(i + 1).text(); + } + return null; + } }; diff --git a/package.json b/package.json index afae55b9..94a51489 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "92.2.0", + "version": "92.2.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {