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 #1020 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
9 changed files
with
311 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'altervista.org': { | ||
_name: 'Altervista', | ||
hyp3rlinx: [ | ||
{ | ||
title: 'hyp3rlinx blog', | ||
docs: 'https://docs.rsshub.app/', | ||
source: ['/'], | ||
target: '/rsshub/transform/html/http%3A%2F%2Fhyp3rlinx.altervista.org%2F/item=table[border=%221%22]%20tr%20td%20a', | ||
}, | ||
], | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module.exports = { | ||
'/routes/:lang?': ['DIYgod'], | ||
'/rsshub/sponsors': ['DIYgod'], | ||
'/transform/html/:url/:routeParams': ['ttttmr'], | ||
'/transform/json/:url/:routeParams': ['ttttmr'], | ||
}; |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module.exports = (router) => { | ||
router.get('/rss', require('./routes')); // 弃用 | ||
|
||
router.get('/routes/:lang?', require('./routes')); | ||
router.get('/sponsors', require('./sponsors')); | ||
router.get('/transform/html/:url/:routeParams', require('./transform/html')); | ||
router.get('/transform/json/:url/:routeParams', require('./transform/json')); | ||
}; |
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,75 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const config = require('@/config').value; | ||
|
||
module.exports = async (ctx) => { | ||
if (!config.feature.allow_user_supply_unsafe_domain) { | ||
ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); | ||
} | ||
const { url } = ctx.params; | ||
const response = await got({ | ||
method: 'get', | ||
url, | ||
}); | ||
|
||
const routeParams = new URLSearchParams(ctx.params.routeParams); | ||
const $ = cheerio.load(response.data); | ||
const rssTitle = routeParams.get('title') ? routeParams.get('title') : $('title').text(); | ||
const item = routeParams.get('item') ? routeParams.get('item') : 'html'; | ||
const items = $(item) | ||
.toArray() | ||
.map((item) => { | ||
try { | ||
item = $(item); | ||
|
||
let title; | ||
const titleEle = routeParams.get('itemTitle') ? item.find(routeParams.get('itemTitle')) : item; | ||
if (routeParams.get('itemTitleAttr')) { | ||
title = titleEle.attr(routeParams.get('itemTitleAttr')); | ||
} else { | ||
title = titleEle.text(); | ||
} | ||
|
||
let link; | ||
const linkEle = routeParams.get('itemLink') ? item.find(routeParams.get('itemLink')) : item; | ||
if (routeParams.get('itemLinkAttr')) { | ||
link = linkEle.attr(routeParams.get('itemLinkAttr')); | ||
} else { | ||
if (linkEle.is('a')) { | ||
link = linkEle.attr('href'); | ||
} else { | ||
link = linkEle.find('a').attr('href'); | ||
} | ||
} | ||
// 补全绝对链接 | ||
link = link.trim(); | ||
if (link && !link.startsWith('http')) { | ||
link = `${new URL(url).origin}${link}`; | ||
} | ||
|
||
let desc; | ||
const descEle = routeParams.get('itemDesc') ? item.find(routeParams.get('itemDesc')) : item; | ||
if (routeParams.get('itemDescAttr')) { | ||
desc = descEle.attr(routeParams.get('itemDescAttr')); | ||
} else { | ||
desc = descEle.html(); | ||
} | ||
|
||
return { | ||
title, | ||
link, | ||
description: desc, | ||
}; | ||
} catch (e) { | ||
return null; | ||
} | ||
}) | ||
.filter(Boolean); | ||
|
||
ctx.state.data = { | ||
title: rssTitle, | ||
link: url, | ||
description: `Proxy ${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,57 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const config = require('@/config').value; | ||
|
||
function jsonGet(obj, attr) { | ||
if (typeof attr !== 'string') { | ||
return obj; | ||
} | ||
// a.b.c | ||
// a.b[0].c => a.b.0.c | ||
attr.split('.').forEach((key) => { | ||
obj = obj[key]; | ||
}); | ||
return obj; | ||
} | ||
|
||
module.exports = async (ctx) => { | ||
if (!config.feature.allow_user_supply_unsafe_domain) { | ||
ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`); | ||
} | ||
const { url } = ctx.params; | ||
const response = await got({ | ||
method: 'get', | ||
url, | ||
}); | ||
|
||
const routeParams = new URLSearchParams(ctx.params.routeParams); | ||
let rssTitle = routeParams.get('title'); | ||
if (!rssTitle) { | ||
const resp = await got({ | ||
method: 'get', | ||
url: new URL(url).origin, | ||
}); | ||
const $ = cheerio.load(resp.data); | ||
rssTitle = $('title').text(); | ||
} | ||
|
||
const items = jsonGet(response.data, routeParams.get('item')).map((item) => { | ||
let link = jsonGet(item, routeParams.get('itemLink')).trim(); | ||
// 补全绝对链接 | ||
if (link && !link.startsWith('http')) { | ||
link = `${new URL(url).origin}${link}`; | ||
} | ||
return { | ||
title: jsonGet(item, routeParams.get('itemTitle')), | ||
link, | ||
description: routeParams.get('itemDesc') ? jsonGet(item, routeParams.get('itemDesc')) : '', | ||
}; | ||
}); | ||
|
||
ctx.state.data = { | ||
title: rssTitle, | ||
link: url, | ||
description: `Proxy ${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,13 @@ | ||
module.exports = { | ||
'sec.today': { | ||
_name: '每日安全', | ||
'.': [ | ||
{ | ||
title: '动态', | ||
docs: 'https://docs.rsshub.app/', | ||
source: ['/pulses', '/'], | ||
target: '/rsshub/transform/html/https%3A%2F%2Fsec.today%2Fpulses%2F/item=div[class="card-body"]', | ||
}, | ||
], | ||
}, | ||
}; |
6d7ab03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rsshub-master – ./
rsshub-master-auto-bot-ty.vercel.app
rsshub-master-git-master-auto-bot-ty.vercel.app
rsshub-master.vercel.app