Skip to content

Commit

Permalink
feat(route): add Hugo 更新日志 (DIYgod#7260)
Browse files Browse the repository at this point in the history
  • Loading branch information
maokwen authored May 12, 2021
1 parent e991617 commit f2c506d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/en/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ Language

<RouteEn author="imlonghao" path="/greasyfork/:language/:domain?" example="/greasyfork/en/google.com" :paramsDesc="['language, located on the top right corner of Greasy Fork\'s search page, set to `all` for including all languages', 'the script\'s target domain']" />

## Hugo

### Release News

<Route author="maokwen" example="/hugo/releases" path="/hugo/releases"/>

## IPSW.me

### Apple Firmware Update-IPSWs/OTAs version
Expand Down
6 changes: 6 additions & 0 deletions docs/program-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ pageClass: routes

<Route author="imlonghao" example="/greasyfork/zh-CN/bilibili.com" path="/greasyfork/:language/:domain?" :paramsDesc="['语言, 可在网站右上角找到, `all` 为所有语言', '按脚本生效域名过滤, 可选']"/>

## Hugo

### 更新日志

<Route author="maokwen" example="/hugo/releases" path="/hugo/releases"/>

## IPSW.me

### 苹果固件更新 - IPSWs/OTAs 版本
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4067,4 +4067,7 @@ router.get('/jisilu/topic/:user', require('./routes/jisilu/topic'));
// Constitutional Court of Baden-Württemberg (Germany)
router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press'));

// Hugo 更新日志
router.get('/hugo/releases', require('./routes/hugo/releases'));

module.exports = router;
53 changes: 53 additions & 0 deletions lib/routes/hugo/releases.js
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,
};
};

0 comments on commit f2c506d

Please sign in to comment.