diff --git a/docs/README.md b/docs/README.md index 2b140a825..8333ee3d6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1542,6 +1542,24 @@ Category 列表: +### Solidot + + + +::: tip 提示 + +Solidot 提供的 feed: + +- https://www.solidot.org/index.rss + +::: + +| 全部 | 创业 | Linux | 科学 | 科技 | 移动 | 苹果 | 硬件 | 软件 | 安全 | 游戏 | 书籍 | ask | idle | 博客 | 云计算 | +| ---- | ------- | ----- | ------- | ---------- | ------ | ----- | -------- | -------- | -------- | ----- | ----- | --- | ---- | ---- | ------ | +| www | startup | linux | science | technology | mobile | apple | hardware | software | security | games | books | ask | idle | blog | cloud | + + + ## 预报预警 ### 停水通知 diff --git a/router.js b/router.js index 8d65061d4..077a56e79 100644 --- a/router.js +++ b/router.js @@ -690,6 +690,9 @@ router.get('/99percentinvisible/transcript', require('./routes/99percentinvisibl // 青空文庫 router.get('/aozora/newbook/:count?', require('./routes/aozora/newbook')); +// solidot +router.get('/solidot/:type?', require('./routes/solidot/main')); + // Hermes UK router.get('/parcel/hermesuk/:tracking', require('./routes/parcel/hermesuk')); diff --git a/routes/solidot/main.js b/routes/solidot/main.js new file mode 100644 index 000000000..4a7be0cef --- /dev/null +++ b/routes/solidot/main.js @@ -0,0 +1,87 @@ +// Warning: The author still knows nothing about javascript! + +// params: +// type: subject type + +const axios = require('../../utils/axios'); // get web content +const cheerio = require('cheerio'); // html parser + +const base_url = 'https://$type$.solidot.org'; +module.exports = async (ctx) => { + const type = ctx.params.type || 'www'; + + const list_url = base_url.replace('$type$', type); + const response = await axios({ + method: 'get', + url: list_url, + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0', + }); + const data = response.data; // content is html format + const $ = cheerio.load(data); + + // get content + const a = $('div.block_m'); + + const msg_list = []; + for (let i = 0; i < a.length; ++i) { + const title = $(a[i]) + .find('div.bg_htit > h2 > a') + .text(); + const link = + list_url + + $(a[i]) + .find('div.bg_htit > h2 > a') + .attr('href'); + const content = $(a[i]) + .find('div.p_mainnew') + .html() + .replace(/href="\//g, 'href="' + list_url); + const author = $(a[i]) + .find('div.talk_time > b') + .text() + .replace(/^来自/, ''); + const category = $(a[i]) + .find('div.icon_float > a') + .attr('title'); + const cat_img = $(a[i]) + .find('div.icon_float > a') + .html(); + const date_raw = $(a[i]).find('div.talk_time'); + $(date_raw) + .find('div.icon_float') + .remove(); + $(date_raw) + .find('span.user') + .remove(); + $(date_raw) + .find('b') + .remove(); + const date_str_zh = $(date_raw) + .text() + .replace(/^[^`]*发表于(.*分)[^`]*$/g, '$1'); // use [^`] to match \n + const date_str = date_str_zh + .replace(/[年月]/g, '-') + .replace(/时/g, ':') + .replace(/[日分]/g, ''); + let date = new Date(date_str); + date.setHours(date.getHours() - 8); + date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds())); + const item = { + title: title, + author: author, + pubDate: date.toUTCString(), + category: category, // not supported: 2018-10-29 + link: link, + description: content + '

' + cat_img, + }; + + msg_list.push(item); + } + + // feed the data + ctx.state.data = { + title: '奇客的资讯,重要的东西', + link: list_url, + item: msg_list, + }; +};