Files
RSSHub/lib/routes/wikihow/category.js
T
sanmmmm 901bcbd3f9 feat: 新增 wikihow/正版中国 (#2679)
* feat: 新增 wikihow/正版中国/小众软件

* 移除 小众软件
2019-07-24 14:23:36 +08:00

35 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { category, type = 'all' } = ctx.params;
const link = encodeURI(`https://zh.wikihow.com/Category:${category}`);
const res = await got(link);
const $ = cheerio.load(res.data);
const itemsSelector = type === 'all' ? '#cat_featured .thumbnail' : '#cat_all .thumbnail';
const item = $(itemsSelector)
.map((_, ele) => {
const $item = cheerio.load(ele);
const title = '如何' + $item('.text span').text();
const link = $item('a').attr('href');
const thumbnail = $item('img').attr('data-src');
return {
title,
description: `
${title}<br/>
<img src="${thumbnail}"/>
`,
link,
};
})
.get();
ctx.state.data = {
title: `wikiHow - ${category}`,
description: `wikiHow - ${category}`,
link,
item,
};
};