diff --git a/docs/en/program-update.md b/docs/en/program-update.md index a977c596813da6..6bb7b21f99248a 100644 --- a/docs/en/program-update.md +++ b/docs/en/program-update.md @@ -168,6 +168,12 @@ Language +## Hugo + +### Release News + + + ## IPSW.me ### Apple Firmware Update-IPSWs/OTAs version diff --git a/docs/program-update.md b/docs/program-update.md index 91114ab09aadbe..79064578ad31a0 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -212,6 +212,12 @@ pageClass: routes +## Hugo + +### 更新日志 + + + ## IPSW.me ### 苹果固件更新 - IPSWs/OTAs 版本 diff --git a/lib/router.js b/lib/router.js index f98d88997cdcb6..8f9039f4bbd71d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/hugo/releases.js b/lib/routes/hugo/releases.js new file mode 100644 index 00000000000000..6d85dfd607a4d1 --- /dev/null +++ b/lib/routes/hugo/releases.js @@ -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, + }; +};