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,4 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
// 发起 HTTP GET 请求
|
||||
module.exports = async (ctx) => {
|
||||
@@ -7,9 +8,9 @@ module.exports = async (ctx) => {
|
||||
const keyword = String(ctx.params.keyword);
|
||||
|
||||
//添加参数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' ) {
|
||||
url = `https://faexport.spangle.org.uk/search.json?q=${keyword}`;
|
||||
url = `https://faexport.spangle.org.uk/search.rss?q=${keyword}`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
@@ -20,7 +21,13 @@ module.exports = async (ctx) => {
|
||||
},
|
||||
});
|
||||
|
||||
// 使用 cheerio 加载返回的 HTML
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data, {
|
||||
xmlMode: true
|
||||
});
|
||||
|
||||
const list = $('item');
|
||||
|
||||
ctx.state.data = {
|
||||
// 源标题
|
||||
@@ -31,16 +38,18 @@ module.exports = async (ctx) => {
|
||||
description: `Fur Affinity ${keyword}'s Search List`,
|
||||
|
||||
//遍历此前获取的数据
|
||||
item: data.map((item) => ({
|
||||
// 标题
|
||||
title: item.title,
|
||||
// 正文
|
||||
description: `<img src="${item.thumbnail}">`,
|
||||
// 链接
|
||||
link: item.link,
|
||||
// 作者
|
||||
author: item.name,
|
||||
// 由于源API未提供日期,故无pubDate
|
||||
})),
|
||||
item:
|
||||
list &&
|
||||
list.map((index, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find("title").text(),
|
||||
description: item.find("description").text(),
|
||||
link: item.find("link").text(),
|
||||
pubDate: new Date(item.find("pubDate").text()).toUTCString(),
|
||||
//由于源API未提供作者信息,故无author
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user