forked from chengxuanying/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.
feat(route): add Hugo 更新日志 (DIYgod#7260)
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 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,53 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
async function load(link) { | ||
const response = await got.get(link); | ||
const $ = cheerio.load(response.data); | ||
const datestr = $('aside > time').attr('datetime'); | ||
const description = $('article > div.flex-l').html(); | ||
return { description, datestr }; | ||
} | ||
|
||
const ProcessFeed = async (title, url, caches) => { | ||
const single = { | ||
title: title, | ||
link: url, | ||
guid: url, | ||
}; | ||
const other = await caches.tryGet(url, async () => await load(url)); | ||
return Promise.resolve(Object.assign({}, single, other)); | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const host = 'https://gohugo.io/categories/releases'; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: host, | ||
headers: { | ||
Referer: host, | ||
}, | ||
}); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
const items = await Promise.all( | ||
$('section > div > div > h1') | ||
.get() | ||
.map(async (item) => { | ||
const node = $('a', item); | ||
const title = node.text(); | ||
const url = new URL(node.attr('href'), 'https://gohugo.io/').href; | ||
const result = await ProcessFeed(title, url, ctx.cache); | ||
return Promise.resolve(result); | ||
}) | ||
); | ||
|
||
ctx.state.data = { | ||
title: 'Hugo Release', | ||
link: host, | ||
description: 'Hugo Release', | ||
item: items, | ||
}; | ||
}; |