mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 05:36:08 +08:00
feat: add rss of scala blog (#3768)
This commit is contained in:
29
lib/routes/scala-blog/scala-blog.js
Normal file
29
lib/routes/scala-blog/scala-blog.js
Normal file
@@ -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();
|
||||
};
|
||||
Reference in New Issue
Block a user