mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 21:18:57 +08:00
Update search.js
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
const got = require('@/utils/got');
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
// 发起 HTTP GET 请求
|
// 发起 HTTP GET 请求
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
// 传入参数
|
//传入参数
|
||||||
const nsfw = String(ctx.params.nsfw);
|
const nsfw = String(ctx.params.nsfw);
|
||||||
const keyword = String(ctx.params.keyword);
|
const keyword = String(ctx.params.keyword);
|
||||||
|
|
||||||
// 添加参数keyword以及判断传入的参数nsfw
|
//添加参数keyword以及判断传入的参数nsfw
|
||||||
let url = `https://faexport.spangle.org.uk/search.json?q=${keyword}?sfw=1`;
|
let url = `https://faexport.spangle.org.uk/search.rss?q=${keyword}?sfw=1`;
|
||||||
if (nsfw === '1' || keyword === '1') {
|
if (nsfw === '1' || keyword === '1' ) {
|
||||||
url = `https://faexport.spangle.org.uk/search.json?q=${keyword}`;
|
url = `https://faexport.spangle.org.uk/search.rss?q=${keyword}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await got({
|
const response = await got({
|
||||||
@@ -20,7 +21,13 @@ module.exports = async (ctx) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 使用 cheerio 加载返回的 HTML
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
const $ = cheerio.load(data, {
|
||||||
|
xmlMode: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const list = $('item');
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = {
|
||||||
// 源标题
|
// 源标题
|
||||||
@@ -30,17 +37,19 @@ module.exports = async (ctx) => {
|
|||||||
// 源说明
|
// 源说明
|
||||||
description: `Fur Affinity ${keyword}'s Search List`,
|
description: `Fur Affinity ${keyword}'s Search List`,
|
||||||
|
|
||||||
// 遍历此前获取的数据
|
//遍历此前获取的数据
|
||||||
item: data.map((item) => ({
|
item:
|
||||||
// 标题
|
list &&
|
||||||
title: item.title,
|
list.map((index, item) => {
|
||||||
// 正文
|
item = $(item);
|
||||||
description: `<img src="${item.thumbnail}">`,
|
return {
|
||||||
// 链接
|
title: item.find("title").text(),
|
||||||
link: item.link,
|
description: item.find("description").text(),
|
||||||
// 作者
|
link: item.find("link").text(),
|
||||||
author: item.name,
|
pubDate: new Date(item.find("pubDate").text()).toUTCString(),
|
||||||
// 由于源API未提供日期,故无pubDate
|
//由于源API未提供作者信息,故无author
|
||||||
})),
|
};
|
||||||
};
|
})
|
||||||
|
.get(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user