forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
44 changed files
with
478 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const renderDescription = (description, images) => art(path.join(__dirname, './templates/description.art'), { description, images }); | ||
const config = require('@/config').value; | ||
|
||
module.exports = async (ctx) => { | ||
const { keyword } = ctx.params; | ||
const url = `https://www.baidu.com/s?wd=${encodeURIComponent(keyword)}`; | ||
const key = `baidu-search:${url}`; | ||
|
||
const items = await ctx.cache.tryGet( | ||
key, | ||
async () => { | ||
const response = (await got(url)).data; | ||
const visitedLinks = new Set(); | ||
const $ = cheerio.load(response); | ||
const contentLeft = $('#content_left'); | ||
const containers = contentLeft.find('.c-container'); | ||
return containers | ||
.map((i, el) => { | ||
const element = $(el); | ||
const link = element.find('h3 a').first().attr('href'); | ||
if (link && !visitedLinks.has(link)) { | ||
visitedLinks.add(link); | ||
const imgs = element | ||
.find('img') | ||
.map((_j, _el) => $(_el).attr('src')) | ||
.toArray(); | ||
const description = element.find('.c-gap-top-small [class^="content-right_"]').first().text() || element.find('.c-row').first().text() || element.find('.cos-row').first().text(); | ||
return { | ||
title: element.find('h3').first().text(), | ||
description: renderDescription(description, imgs), | ||
link: element.find('h3 a').first().attr('href'), | ||
author: element.find('.c-row .c-color-gray').first().text() || '', | ||
}; | ||
} | ||
return null; | ||
}) | ||
.toArray() | ||
.filter((e) => e?.link); | ||
}, | ||
config.cache.routeExpire, | ||
false | ||
); | ||
|
||
ctx.state.data = { | ||
title: `${keyword} - 百度搜索`, | ||
description: `${keyword} - 百度搜索`, | ||
link: url, | ||
item: items, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{@ description }} | ||
{{if images}} | ||
{{each images}} | ||
<img src="{{ $value }}"> | ||
{{/each}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'/': ['FHYunCai'], | ||
'/search/:keyword': ['CaoMeiYouRen'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
'bing.com': { | ||
_name: 'Bing', | ||
cn: [ | ||
{ | ||
title: '每日壁纸', | ||
docs: 'https://docs.rsshub.app/routes/picture#bing', | ||
source: '/', | ||
target: '/bing', | ||
}, | ||
{ | ||
title: '搜索', | ||
docs: 'https://docs.rsshub.app/routes/other#bing', | ||
source: '/', | ||
target: (params, url) => { | ||
const q = new URL(url).searchParams.get('q'); | ||
return `/bing/search/${q}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function (router) { | ||
router.get('/', require('./daily-wallpaper')); | ||
router.get('/search/:keyword', require('./search')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const parser = require('@/utils/rss-parser'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const dayjs = require('dayjs'); | ||
const localizedFormat = require('dayjs/plugin/localizedFormat'); | ||
require('dayjs/locale/zh-cn'); | ||
dayjs.extend(localizedFormat); | ||
|
||
module.exports = async (ctx) => { | ||
const q = ctx.params.keyword; | ||
const searchParams = new URLSearchParams({ | ||
format: 'rss', | ||
q, | ||
}); | ||
const url = new URL('https://cn.bing.com/search'); | ||
url.search = searchParams.toString(); | ||
const data = await parser.parseURL(url.toString()); | ||
ctx.state.data = { | ||
title: data.title, | ||
link: data.link, | ||
description: data.description + ' - ' + data.copyright, | ||
image: data.image.url, | ||
item: data.items.map((e) => ({ | ||
...e, | ||
description: e.content, | ||
pubDate: parseDate(e.pubDate, 'dddd, DD MMM YYYY HH:mm:ss [GMT]', 'zh-cn'), | ||
})), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { art } = require('@/utils/render'); | ||
const path = require('path'); | ||
const config = require('@/config').value; | ||
|
||
const renderDescription = (description, images) => art(path.join(__dirname, './templates/description.art'), { description, images }); | ||
|
||
module.exports = async (ctx) => { | ||
const { keyword, language } = ctx.params; | ||
const searchParams = new URLSearchParams({ | ||
q: keyword, | ||
}); | ||
const tempUrl = new URL('https://www.google.com/search'); | ||
tempUrl.search = searchParams.toString(); | ||
const url = tempUrl.toString(); | ||
const key = `google-search:${language}:${url}`; | ||
const items = await ctx.cache.tryGet( | ||
key, | ||
async () => { | ||
const response = ( | ||
await got(url, { | ||
headers: { | ||
'Accept-Language': language, | ||
}, | ||
}) | ||
).data; | ||
const $ = cheerio.load(response); | ||
const content = $('#rso'); | ||
return content | ||
.find('> div') | ||
.map((i, el) => { | ||
const element = $(el); | ||
const link = element.find('div > div > div > div > div > span > a').first().attr('href'); | ||
const title = element.find('div > div > div> div > div > span > a > h3').first().text(); | ||
const imgs = element | ||
.find('img') | ||
.map((_j, _el) => $(_el).attr('src')) | ||
.toArray(); | ||
const description = element.find('div[style="-webkit-line-clamp:2"]').first().text() || element.find('div[role="heading"]').first().text(); | ||
const author = element.find('div > div > div > div > div > span > a > div > div > span').first().text() || ''; | ||
return { | ||
link, | ||
title, | ||
description: renderDescription(description, imgs), | ||
author, | ||
}; | ||
}) | ||
.toArray() | ||
.filter((e) => e?.link); | ||
}, | ||
config.cache.routeExpire, | ||
false | ||
); | ||
|
||
ctx.state.data = { | ||
title: `${keyword} - Google Search`, | ||
description: `${keyword} - Google Search`, | ||
link: url, | ||
item: items, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{@ description }} | ||
{{if images}} | ||
{{each images}} | ||
<img src="{{ $value }}"> | ||
{{/each}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.