Enhancement: 下厨房增加新的分类 (#1132)

This commit is contained in:
凉凉
2018-11-13 10:53:54 +08:00
committed by DIYgod
parent aba5fbe103
commit 96eac564cb
2 changed files with 49 additions and 15 deletions
+3 -3
View File
@@ -2298,9 +2298,9 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
<route name="作品动态" author="xyqfer" example="/xiachufang/popular/hot" path="/xiachufang/popular/:timeframe?" :paramsDesc="['默认最新上传']">
| 正在流行 | 24 小时最佳 |
| -------- | ----------- |
| hot | pop |
| 正在流行 | 24 小时最佳 | 本周最受欢迎 | 新秀菜谱 | 月度最佳 |
| -------- | ----------- | ------------ | -------- | ---------- |
| hot | pop | week | rising | monthhonor |
</route>
+46 -12
View File
@@ -1,33 +1,44 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const generateItems = ($) =>
$('.ias-container .pure-u')
const generateItems = ($, timeframe) => {
let selector;
if (['week', 'rising', 'monthhonor'].includes(timeframe)) {
selector = '.normal-recipe-list li';
} else {
selector = '.ias-container .pure-u';
}
return $(selector)
.map(function() {
const $item = $(this);
const $link = $item.find('.name a');
const title = $link.text();
const link = `https://www.xiachufang.com${$link.attr('href')}`;
const desc = $item
.find('.desc')
.text()
.replace(/\n/g, '<br>');
const img = $item
.find('.cover img')
.attr('data-src')
.replace(/\?.+/g, '');
let desc = $item.find('.ing').text();
if (!desc || desc === '') {
desc = $item
.find('.desc')
.text()
.replace(/\n/g, '<br>');
}
return {
title,
link,
description: `
<img referrerpolicy="no-referrer" src="${img}" /><br>
<strong>${title}</strong><br>
${desc}
`,
<img referrerpolicy="no-referrer" src="${img}" /><br>
<strong>${title}</strong><br>
${desc}
`,
};
})
.get();
};
const fetchPage = (url) =>
axios({
@@ -60,15 +71,38 @@ module.exports = {
'': '最新上传',
hot: '正在流行',
pop: '24小时最佳',
week: '本周最受欢迎',
rising: '新秀菜谱',
monthhonor: '月度最佳',
};
const url = `https://www.xiachufang.com/activity/site/?order=${timeframe}`;
let url;
switch (timeframe) {
case 'hot':
case 'pop':
url = `https://www.xiachufang.com/activity/site/?order=${timeframe}`;
break;
case 'rising':
case 'monthhonor':
url = `https://www.xiachufang.com/explore/${timeframe}/`;
break;
case 'week':
url = 'https://www.xiachufang.com/explore/';
break;
default:
url = 'https://www.xiachufang.com/activity/site/?order=';
}
const response = await fetchPage(url);
const $ = cheerio.load(response.data);
return {
title: `下厨房-${mapper[timeframe]}`,
link: url,
item: generateItems($),
item: generateItems($, timeframe),
};
},
};