diff --git a/docs/en/programming.md b/docs/en/programming.md index 813688b58..2c4a9c817 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -191,6 +191,14 @@ Website: https://news.ycombinator.com/ +## Scala + +### Scala Blog + + +part parmater can be found in the url of blog + + ## Visual Studio Code Marketplace ### Visual Studio Code Plugins Marketplace diff --git a/docs/programming.md b/docs/programming.md index 70b901673..f3b38f639 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -264,6 +264,14 @@ GitHub 官方也提供了一些 RSS: +## Scala + +### Scala Blog + + +默认为All part参数可在url中获得 + + ## segmentfault ### 频道 diff --git a/lib/router.js b/lib/router.js index 5ae1dee13..30f176886 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2144,6 +2144,9 @@ router.get('/discuz/:link(.*)', require('./routes/discuz/discuz')); router.get('/chinadialogue/topics/:topic', require('./routes/chinadialogue/topics')); router.get('/chinadialogue/:column', require('./routes/chinadialogue/column')); +// Scala Blog +router.get('/scala/blog/:part?', require('./routes/scala-blog/scala-blog')); + // Minecraft Java版游戏更新 router.get('/minecraft/version', require('./routes/minecraft/version')); diff --git a/lib/routes/scala-blog/scala-blog.js b/lib/routes/scala-blog/scala-blog.js new file mode 100644 index 000000000..005369ddf --- /dev/null +++ b/lib/routes/scala-blog/scala-blog.js @@ -0,0 +1,29 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx, next) => { + const part = ctx.params.part || ''; + const link = `https://scala-lang.org/blog/${part}`; + const host = 'https://scala-lang.org'; + + const resp = await got(link); + const $ = cheerio.load(resp.body); + const items = $('.blog-item') + .get() + .map((item) => { + const $ = cheerio.load(item); + const aTag = $('a').first(); + return { + title: aTag.text(), + link: host + aTag.attr('href'), + pubDate: new Date($('.blog-date').text()), + }; + }); + + ctx.state.data = { + title: `Scala Blog ${part === '' ? 'all' : part} Section `, + link, + item: items, + }; + await next(); +};