`; + // date + const date = $('div.story-calendar').text(); + // desc + const desc = `${$(author_block)}${$('div.story-content').html()}`; + + return { + title: h1, + description: desc, + pubDate: new Date(`${date}T09:00:00+0800`).toUTCString(), + link: line, + }; + }) + ); + // 執行一個切片 (20 個文章 URL) 的任務並將結果資料推至 rss 値 + return await Promise.all(now); +} + +module.exports = async (ctx) => { + const range = ctx.params.range || 'latest'; + const category = ctx.params.category || 'all'; + + // for range validation + const num = /^[1-9][0-9]{3}$/; + const current_year = new Date().getFullYear(); + // placeholders + let title = '傳媒透視'; + let rss = [ + { + description: '${s_author}
Invalid :range input.
所輸入:range參數有誤。
所输入:range参数有误。
${item.content}
${media}`, + pubDate: new Date(item.create_time * 1000).toUTCString(), + link: `https://tieba.baidu.com/p/${item.post_id}?pid=${item.thread_id}&cid=#${item.thread_id}`, + }; + }), }; }; diff --git a/lib/routes/tingdiantz/95598.js b/lib/routes/tingdiantz/95598.js new file mode 100644 index 000000000..9cc3161ba --- /dev/null +++ b/lib/routes/tingdiantz/95598.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const HOME_PAGE = 'http://www.sttcq.com'; + +module.exports = async (ctx) => { + const province = ctx.params.province; + const city = ctx.params.city; + const district = ctx.params.district; + + let url; + if (district) { + url = `${HOME_PAGE}/td/${province}/${city}/${district}`; + } else { + url = `${HOME_PAGE}/td/${province}/${city}`; + } + + const response = await got.get(url); + + const data = response.data; + const $ = cheerio.load(data); + const list = $('.news-blocks ul li'); + + ctx.state.data = { + title: $('.main-nav2.clearfix').text(), + link: url, + item: list + .map((index, item) => { + const $item = $(item); + const $aTag = $item.find('a'); + const link = $aTag.attr('href'); + const title = $aTag.text(); + + let pubDate = $item.find('span').text(); + pubDate = new Date(pubDate).toUTCString(); + + return { + title, + description: '停电通知', + link: `${HOME_PAGE}${link}`, + pubDate, + }; + }) + .get(), + }; +}; diff --git a/lib/routes/universities/ahut/cstzgg.js b/lib/routes/universities/ahut/cstzgg.js index 79f1d2dff..c3177bb20 100644 --- a/lib/routes/universities/ahut/cstzgg.js +++ b/lib/routes/universities/ahut/cstzgg.js @@ -1,58 +1,39 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const url = require('url'); module.exports = async (ctx) => { - const url = `http://jsjxy.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1887`; - const response = await got({ - method: 'get', - url: url, - }); + const response = await got.get('http://jsjxy.ahut.edu.cn/index/tzgg.htm'); const $ = cheerio.load(response.data); - $('.clickstyle1022').remove(); - $('td[width = "1%"]').remove(); - $('tr[height = "1"]').remove(); - $('td[colspan="3"]').remove(); - $('.leaderfont47822').remove(); - // ## 获取列表 - const list = $('.winstyle47822 > tbody > tr').get(); - // ## 定义输出的item + + // 获取列表 + const list = $('a.c259382') + .map((index, ele) => ({ + title: $(ele).attr('title'), + link: url.resolve('http://jsjxy.ahut.edu.cn/', $(ele).attr('href')), + })) + .get(); + + // 定义输出的item const out = await Promise.all( - // ### 遍历列表,筛选出自己想要的内容 + // 遍历列表,筛选出自己想要的内容 list.map(async (item) => { - const itemSingle = cheerio.load(item); - const title = itemSingle.text().replace(/^[\s]+|[\s]+$/g, ''); - const re = /]*href=['"]([^"]*)['"][^>]*>/g; - let singleUrl = ''; - if (re.exec(itemSingle.html()) !== null) { - singleUrl = RegExp.$1; - } - if (singleUrl.search('http') === -1) { - singleUrl = 'http://jsjxy.ahut.edu.cn' + singleUrl; - } - const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息 - // ### 判断缓存是否存在,如果存在即跳过此次获取的信息 + const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息 + // 判断缓存是否存在,如果存在即跳过此次获取的信息 if (cache) { return Promise.resolve(JSON.parse(cache)); } // 获取详情页面的介绍 - const detail_response = await got({ - method: 'get', - url: singleUrl, - }); + const detail_response = await got.get(item.link); const $ = cheerio.load(detail_response.data); - const detail_content = $('.contentstyle47853 > div').html(); - // ### 设置 RSS feed item - const single = { - title: title.replace(/(^\s*)|(\s*$)/g, ''), - link: singleUrl, - // author: author, - description: detail_content, - // pubDate: updateDate, - }; - // // ### 设置缓存 - ctx.cache.set(singleUrl, JSON.stringify(single)); - return Promise.resolve(single); - // } + + // 设置 RSS feed item + item.description = $('.contentstyle47853 > div').html(); + item.pubDate = new Date($('.timestyle47853').text().trim()); + + // 设置缓存 + ctx.cache.set(item.link, JSON.stringify(item)); + return Promise.resolve(item); }) ); ctx.state.data = { diff --git a/lib/routes/universities/ahut/jwc.js b/lib/routes/universities/ahut/jwc.js index 77e55deb6..957ff3f93 100644 --- a/lib/routes/universities/ahut/jwc.js +++ b/lib/routes/universities/ahut/jwc.js @@ -1,56 +1,37 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const url = require('url'); module.exports = async (ctx) => { - const url = `http://jwc.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1082`; - const response = await got({ - method: 'get', - url: url, - }); + const response = await got.get('http://jwc.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1082'); const $ = cheerio.load(response.data); - $('tr[height="1"]').remove(); - $('td[width="1%"]').remove(); - $('td[colspan="3"]').remove(); - // ## 获取列表 - const list = $('.winstyle44456 > tbody > tr >td').get(); - // ## 定义输出的item + + // 获取列表 + const list = $('.winstyle44566 tr') + .map((index, ele) => ({ + title: $('a', ele).attr('title'), + link: url.resolve('http://jwc.ahut.edu.cn/', $('a', ele).attr('href')), + })) + .get(); + + // 定义输出的item const out = await Promise.all( - // ### 遍历列表,筛选出自己想要的内容 + // 遍历列表,筛选出自己想要的内容 list.map(async (item) => { - const itemSingle = cheerio.load(item); - const title = itemSingle.text(); - const re = /]*href=['"]([^"]*)['"][^>]*>/g; - let singleUrl = ''; - if (re.exec(itemSingle.html()) !== null) { - singleUrl = RegExp.$1; - } - if (singleUrl.search('http') === -1) { - singleUrl = 'http://jwc.ahut.edu.cn' + singleUrl; - } - const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息 - // ### 判断缓存是否存在,如果存在即跳过此次获取的信息 + const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息 + // 判断缓存是否存在,如果存在即跳过此次获取的信息 if (cache) { return Promise.resolve(JSON.parse(cache)); } // 获取详情页面的介绍 - const detail_response = await got({ - method: 'get', - url: singleUrl, - }); + const detail_response = await got.get(item.link); const $ = cheerio.load(detail_response.data); - const detail_content = $('.winstyle44457 > tbody').html(); - // ### 设置 RSS feed item - const single = { - title: title, - link: singleUrl, - // author: author, - description: detail_content, - // pubDate: updateDate, - }; - // // ### 设置缓存 - ctx.cache.set(singleUrl, JSON.stringify(single)); - return Promise.resolve(single); - // } + // 设置 RSS feed item + item.description = $('.winstyle44457 > tbody').html(); + item.pubDate = new Date($('.timestyle44457').text().trim()); + // 设置缓存 + ctx.cache.set(item.link, JSON.stringify(item)); + return Promise.resolve(item); }) ); ctx.state.data = { diff --git a/lib/routes/universities/ahut/news.js b/lib/routes/universities/ahut/news.js index 83aa8e310..67ae500da 100644 --- a/lib/routes/universities/ahut/news.js +++ b/lib/routes/universities/ahut/news.js @@ -1,58 +1,38 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const url = require('url'); module.exports = async (ctx) => { - const url = `http://news.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1002`; - const response = await got({ - method: 'get', - url: url, - }); + const response = await got.get('http://news.ahut.edu.cn/list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1002'); const $ = cheerio.load(response.data); - $('tr[height="26"]').slice(20); - $('td[width="1%"]').remove(); - $('.clickstyle1022').remove(); - $('td[colspan="3"]').remove(); - $('.leaderfont1022').remove(); - // ## 获取列表 - const list = $('.winstyle1022 > tbody > tr > td').get(); - // ## 定义输出的item + + // 获取列表 + const list = $('.winstyle247968 a.c247968') + .map((index, ele) => ({ + title: $(ele).attr('title'), + link: url.resolve('http://news.ahut.edu.cn/', $(ele).attr('href')), + })) + .get(); + // 定义输出的item const out = await Promise.all( - // ### 遍历列表,筛选出自己想要的内容 + // 遍历列表,筛选出自己想要的内容 list.map(async (item) => { - const itemSingle = cheerio.load(item); - const title = itemSingle.text().trim(); - const re = /]*href=['"]([^"]*)['"][^>]*>/g; - let singleUrl = ''; - if (re.exec(itemSingle.html()) !== null) { - singleUrl = RegExp.$1; - } - if (singleUrl.search('http') === -1) { - singleUrl = 'http://news.ahut.edu.cn' + singleUrl; - } - const cache = await ctx.cache.get(singleUrl); // ### 得到全局中的缓存信息 - // ### 判断缓存是否存在,如果存在即跳过此次获取的信息 + const cache = await ctx.cache.get(item.link); // 得到全局中的缓存信息 + // 判断缓存是否存在,如果存在即跳过此次获取的信息 if (cache) { return Promise.resolve(JSON.parse(cache)); } // 获取详情页面的介绍 - const detail_response = await got({ - method: 'get', - url: singleUrl, - }); + const detail_response = await got.get(item.link); const $ = cheerio.load(detail_response.data); - const detail_content = $('.winstyle1023').html(); - // ### 设置 RSS feed item - const single = { - title: title, - link: singleUrl, - // author: author, - description: detail_content, - // pubDate: updateDate, - }; - // // ### 设置缓存 - ctx.cache.set(singleUrl, JSON.stringify(single)); - return Promise.resolve(single); - // } + + // 设置 RSS feed item + item.description = $('.winstyle1023').html(); + item.pubDate = new Date($('.timestyle1023').text().trim()); + + // 设置缓存 + ctx.cache.set(item.link, JSON.stringify(item)); + return Promise.resolve(item); }) ); ctx.state.data = { diff --git a/lib/routes/universities/bit/cs/cs.js b/lib/routes/universities/bit/cs/cs.js index 605491fa6..ab923eb31 100644 --- a/lib/routes/universities/bit/cs/cs.js +++ b/lib/routes/universities/bit/cs/cs.js @@ -6,6 +6,9 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', url: 'http://cs.bit.edu.cn/tzgg', + https: { + rejectUnauthorized: false, + }, }); const $ = cheerio.load(response.data); diff --git a/lib/routes/universities/bit/cs/utils.js b/lib/routes/universities/bit/cs/utils.js index d3d07dd1b..2efa8cc24 100644 --- a/lib/routes/universities/bit/cs/utils.js +++ b/lib/routes/universities/bit/cs/utils.js @@ -5,7 +5,11 @@ const url = require('url'); // 专门定义一个function用于加载文章内容 async function load(link) { // 异步请求文章 - const response = await got.get(link); + const response = await got.get(link, { + https: { + rejectUnauthorized: false, + }, + }); // 加载文章内容 const $ = cheerio.load(response.data); diff --git a/lib/routes/universities/bit/jwc/jwc.js b/lib/routes/universities/bit/jwc/jwc.js index 175d6cdde..52859cfe6 100644 --- a/lib/routes/universities/bit/jwc/jwc.js +++ b/lib/routes/universities/bit/jwc/jwc.js @@ -6,6 +6,9 @@ module.exports = async (ctx) => { const response = await got({ method: 'get', url: 'http://jwc.bit.edu.cn/tzgg', + https: { + rejectUnauthorized: false, + }, }); const $ = cheerio.load(response.data); diff --git a/lib/routes/universities/bit/jwc/utils.js b/lib/routes/universities/bit/jwc/utils.js index 1c32dcfb6..d2891db29 100644 --- a/lib/routes/universities/bit/jwc/utils.js +++ b/lib/routes/universities/bit/jwc/utils.js @@ -5,7 +5,11 @@ const url = require('url'); // 专门定义一个function用于加载文章内容 async function load(link) { // 异步请求文章 - const response = await got.get(link); + const response = await got.get(link, { + https: { + rejectUnauthorized: false, + }, + }); // 加载文章内容 const $ = cheerio.load(response.data); diff --git a/lib/routes/universities/cpu/home.js b/lib/routes/universities/cpu/home.js index e7f1306d8..f87507ffc 100644 --- a/lib/routes/universities/cpu/home.js +++ b/lib/routes/universities/cpu/home.js @@ -15,13 +15,13 @@ module.exports = async (ctx) => { const data = response.data; const $ = cheerio.load(data); - const $list = $('div#wp_news_w3 a').slice(0, 10).get(); + const $list = $('div#wp_news_w3 a').get(); const resultItem = await Promise.all( $list.map(async (item) => { const title = $(item).attr('title'); const href = $(item).attr('href'); - const detail_url = 'http://www.cpu.edu.cn' + href; + const detail_url = href.startsWith('/') ? `http://www.cpu.edu.cn${href}` : href; const single = { title: title, link: detail_url, @@ -37,7 +37,7 @@ module.exports = async (ctx) => { { const detail_data = detail.data; const $ = cheerio.load(detail_data); - single.description = $('table[bgcolor="#FFFFFF"]').html(); + single.description = $('table[bgcolor="#FFFFFF"]').html() || $('table.nyxx').html() || $('div.inner div.article').html(); } return Promise.resolve(single); }) diff --git a/lib/routes/universities/lntu/jwnews.js b/lib/routes/universities/lntu/jwnews.js index fd7af28b2..79752d211 100644 --- a/lib/routes/universities/lntu/jwnews.js +++ b/lib/routes/universities/lntu/jwnews.js @@ -1,26 +1,46 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const url = require('url'); module.exports = async (ctx) => { const link = 'http://jwzx.lntu.edu.cn/index/jwgg.htm'; const response = await got.get(link); + const $ = cheerio.load(response.data); - const list = $('.tr-ri li').slice(0, 10); + const list = $('.tr-ri ul').find('li').get(); + + const res = await Promise.all( + list.map(async (item) => { + let $ = cheerio.load(item); + // 通过解析后的子项地址 + const item_link = url.resolve(link, $('a').attr('href')); + + const description = await ctx.cache.tryGet(item_link, async () => { + const result = await got.get(item_link); + + $ = cheerio.load(result.data); + // remove style + $('img, div, span, p, table, td, tr').removeAttr('style'); + $('style, script').remove(); + + return $('.v_news_content') + .html() + .replace(/(]*>|<\/span>)/g, ''); + }); + + const rssitem = { + title: $('title').text().split('-')[0], + description: description, + link: item_link, + author: '辽宁工程技术大学教务处', + }; + return Promise.resolve(rssitem); + }) + ); ctx.state.data = { title: '辽宁工程技术大学教务公告', link: link, - description: '辽宁工程技术大学教务公告', - item: - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('li a').text(), - link: item.find('li a').attr('href'), - }; - }) - .get(), + item: res, }; }; diff --git a/lib/routes/universities/uestc/sice.js b/lib/routes/universities/uestc/sice.js index acd553a52..18e1e5b45 100644 --- a/lib/routes/universities/uestc/sice.js +++ b/lib/routes/universities/uestc/sice.js @@ -6,28 +6,28 @@ module.exports = async (ctx) => { const page = await browser.newPage(); // 浏览器伪装 - await page.evaluateOnNewDocument(() => { //在每个新页面打开前执行以下脚本 + await page.evaluateOnNewDocument(() => { // 在每个新页面打开前执行以下脚本 const newProto = navigator.__proto__; - delete newProto.webdriver; //删除navigator.webdriver字段 + delete newProto.webdriver; // 删除navigator.webdriver字段 navigator.__proto__ = newProto; - window.chrome = {}; //添加window.chrome字段,为增加真实性还需向内部填充一些值 + window.chrome = {}; // 添加window.chrome字段,为增加真实性还需向内部填充一些值 window.chrome.app = {"InstallState":"hehe", "RunningState":"haha", "getDetails":"xixi", "getIsInstalled":"ohno"}; - window.chrome.csi = function(){}; - window.chrome.loadTimes = function(){}; - window.chrome.runtime = function(){}; - Object.defineProperty(navigator, 'userAgent', { //userAgent在无头模式下有headless字样,所以需覆写 + window.chrome.csi = function() {}; + window.chrome.loadTimes = function() {}; + window.chrome.runtime = function() {}; + Object.defineProperty(navigator, 'userAgent', { // userAgent在无头模式下有headless字样,所以需覆写 get: () => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36", }); - Object.defineProperty(navigator, 'plugins', { //伪装真实的插件信息 + Object.defineProperty(navigator, 'plugins', { // 伪装真实的插件信息 get: () => [{"description": "Portable Document Format", "filename": "internal-pdf-viewer", "length": 1, "name": "Chrome PDF Plugin"}] }); - Object.defineProperty(navigator, 'languages', { //添加语言 + Object.defineProperty(navigator, 'languages', { // 添加语言 get: () => ["zh-CN", "zh", "en"], }); - const originalQuery = window.navigator.permissions.query; //notification伪装 + const originalQuery = window.navigator.permissions.query; // notification伪装 window.navigator.permissions.query = (parameters) => ( parameters.name === 'notifications' ? Promise.resolve({ state: Notification.permission }) : @@ -58,7 +58,6 @@ module.exports = async (ctx) => { ).get(); - ctx.state.data = { title: '信通通知公告', link: 'https://www.sice.uestc.edu.cn/tzgg/yb.htm', diff --git a/lib/routes/voa/day-photos.js b/lib/routes/voa/day-photos.js new file mode 100644 index 000000000..79a4c7751 --- /dev/null +++ b/lib/routes/voa/day-photos.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.voanews.com'; + const currentUrl = `${rootUrl}/day-photos`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.teaser__title-link') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('img').each(function () { + content(this).attr('src', content(this).attr('data-src')); + content(this).removeAttr('data-src'); + }); + + content('noscript').remove(); + + item.description = content('.multimedia-gallery__items').html(); + item.pubDate = new Date(content('.page-header__meta-item').text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/routes/voa/index.js b/lib/routes/voa/index.js new file mode 100644 index 000000000..fd37079a0 --- /dev/null +++ b/lib/routes/voa/index.js @@ -0,0 +1,55 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + let baseURL; + switch (ctx.params.language) { + case 'cantonese': + baseURL = 'https://www.voacantonese.com/'; + break; + case 'chinese': + baseURL = 'https://www.voachinese.com/'; + break; + case 'tibetan': + baseURL = 'https://www.voatibetan.com/'; + break; + default: + throw Error('The language specified does not exist'); + } + + const response = await got.get(baseURL + 'api/' + (ctx.params.channel || '')); + const $ = cheerio.load(response.data); + + const list = []; + $('item').each(function (_, e) { + const item = {}; + item.title = $(e).find('title').first().text(); + item.link = $(e).find('guid').first().text(); + item.pubDate = $(e).find('pubDate').first().text(); + item.description = $(e).find('description').first().text(); + list.push(item); + }); + + const result = await Promise.all( + list + .filter((item) => item.link) + .map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const content = await got.get(item.link); + const description = cheerio.load(content.data); + description('.wsw__embed').remove(); + + item.description = description('div#article-content div').first().html() ? description('div.cover-media') + description('div#article-content div').first().html() : item.description; + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('channel title').first().text(), + link: baseURL, + item: result, + }; +}; diff --git a/lib/routes/xiaoheihe/news.js b/lib/routes/xiaoheihe/news.js index 1eb2d2f82..a00a6730b 100644 --- a/lib/routes/xiaoheihe/news.js +++ b/lib/routes/xiaoheihe/news.js @@ -38,6 +38,7 @@ module.exports = async (ctx) => { // 存放到缓存区 ctx.cache.set(cacheKey, content); news.description = content; + news.link = `https://api.xiaoheihe.cn/maxnews/app/share/detail/${newsId}`; } return Promise.resolve(news); diff --git a/lib/routes/youtube/channel.js b/lib/routes/youtube/channel.js index 006940e3c..7f4b18aaa 100644 --- a/lib/routes/youtube/channel.js +++ b/lib/routes/youtube/channel.js @@ -13,9 +13,9 @@ module.exports = async (ctx) => { const data = (await utils.getPlaylistItems(playlistId, 'snippet,contentDetails')).data.items; ctx.state.data = { - title: `${data[0].snippet.channelTitle} 的 YouTube 视频`, + title: `${data[0].snippet.channelTitle} - YouTube`, link: `https://www.youtube.com/channel/${id}`, - description: `${data[0].snippet.channelTitle} 的 YouTube 视频`, + description: `YouTube channel ${data[0].snippet.channelTitle}`, item: data .filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video') .map((item) => { @@ -25,8 +25,8 @@ module.exports = async (ctx) => { return { title: snippet.title, description: `${ - embed ? '' : '' - }${utils.formatDescription(snippet.description)}${item.target.excerpt}
` : '', + })); + + ctx.state.data = { + title: `知乎热榜 - ${titles[category]}`, + link: `https://www.zhihu.com/hot?list=${category}`, + item: items, + }; +}; diff --git a/lib/routes/zhihu/timeline.js b/lib/routes/zhihu/timeline.js new file mode 100644 index 000000000..568c30a0e --- /dev/null +++ b/lib/routes/zhihu/timeline.js @@ -0,0 +1,33 @@ +const got = require('@/utils/got'); +const config = require('@/config').value; + +module.exports = async (ctx) => { + const cookie = config.zhihu.cookies; + if (cookie === undefined) { + throw Error('缺少知乎用户登录后的 Cookie 值'); + } + + const response = await got({ + method: 'get', + url: `https://www.zhihu.com/api/v3/moments?limit=10`, + headers: { + Cookie: cookie, + }, + }); + const feeds = response.data.data; + + const out = feeds.map((e) => ({ + title: `${e.action_text}: ${e.target.title ? e.target.title : e.target.question.title}`, + description: `${e.target.excerpt}`, + pubDate: new Date(e.updated_time * 1000), + link: e.target.url.replace('api.zhihu.com', 'zhihu.com'), + author: e.target.author.name, + guid: e.id, + })); + + ctx.state.data = { + title: `知乎关注动态`, + link: `https://www.zhihu.com/follow`, + item: out, + }; +}; diff --git a/package.json b/package.json index ff684507d..e762c5ede 100644 --- a/package.json +++ b/package.json @@ -38,17 +38,17 @@ "@types/cheerio": "0.22.23", "@types/got": "9.6.11", "@types/koa": "2.11.6", - "@vuepress/plugin-back-to-top": "1.7.1", - "@vuepress/plugin-google-analytics": "1.7.1", - "@vuepress/plugin-pwa": "1.7.1", + "@vuepress/plugin-back-to-top": "1.8.0", + "@vuepress/plugin-google-analytics": "1.8.0", + "@vuepress/plugin-pwa": "1.8.0", "cross-env": "7.0.3", - "eslint": "7.16.0", + "eslint": "7.17.0", "eslint-config-prettier": "7.1.0", - "eslint-plugin-prettier": "3.3.0", + "eslint-plugin-prettier": "3.3.1", "jest": "26.6.3", "mockdate": "3.0.2", "nock": "13.0.5", - "nodemon": "2.0.6", + "nodemon": "2.0.7", "pinyin": "2.9.1", "prettier": "2.2.1", "prettier-check": "2.0.0", @@ -60,7 +60,7 @@ "staged-git-files": "1.2.0", "string-width": "4.2.0", "supertest": "6.0.1", - "vuepress": "1.7.1", + "vuepress": "1.8.0", "yorkie": "2.0.0" }, "dependencies": { @@ -75,14 +75,14 @@ "co-redis": "2.1.1", "crypto-js": "4.0.0", "currency-symbol-map": "4.0.4", - "dayjs": "1.9.8", + "dayjs": "1.10.3", "dotenv": "8.2.0", "emailjs-imap-client": "3.1.0", "entities": "2.1.0", "etag": "1.8.1", "fanfou-sdk": "4.2.0", "git-rev-sync": "3.0.1", - "googleapis": "66.0.0", + "googleapis": "67.0.0", "got": "11.8.1", "https-proxy-agent": "5.0.0", "iconv-lite": "0.6.2", @@ -92,7 +92,7 @@ "jsdom": "16.4.0", "json-bigint": "1.0.0", "json5": "2.1.3", - "koa": "2.13.0", + "koa": "2.13.1", "koa-basic-auth": "4.0.0", "koa-favicon": "2.1.0", "koa-mount": "4.0.0", @@ -106,10 +106,10 @@ "pidusage": "2.0.21", "plist": "3.0.1", "puppeteer": "5.5.0", - "query-string": "6.13.7", + "query-string": "6.13.8", "redis": "3.0.2", "require-all": "3.0.0", - "rss-parser": "3.9.0", + "rss-parser": "3.10.0", "showdown": "1.9.1", "socks-proxy-agent": "5.0.0", "string-similarity": "^4.0.3", diff --git a/scripts/ansible/.gitignore b/scripts/ansible/.gitignore new file mode 100644 index 000000000..6117c5218 --- /dev/null +++ b/scripts/ansible/.gitignore @@ -0,0 +1,90 @@ +# Created by https://www.toptal.com/developers/gitignore/api/windows,linux,macos,ansible,vagrant +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,linux,macos,ansible,vagrant + +### Ansible ### +*.retry + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vagrant ### +# General +.vagrant/ + +# Log files (if you are creating logs in debug mode, uncomment this) +# *.log + +### Vagrant Patch ### +*.box + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,ansible,vagrant + +# vagrant logs +*.log \ No newline at end of file diff --git a/scripts/ansible/README.md b/scripts/ansible/README.md new file mode 100644 index 000000000..50cae9b71 --- /dev/null +++ b/scripts/ansible/README.md @@ -0,0 +1,20 @@ +# Readme + +Ansible playbook to deploy [RSSHub](https://github.com/DIYgod/RSSHub) on bare-metal with Redis, browserless and Caddy 2 + +Requires sudo permission + +## Usage +On `Ubuntu 20.04`, [install ansible](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-20-04), then + +```bash +sudo ansible-playbook rsshub.yaml +``` + +## Development +Install `vagrant`, then + +```bash +./try.sh +ansible-playbook rsshub.yaml +``` diff --git a/scripts/ansible/Vagrantfile b/scripts/ansible/Vagrantfile new file mode 100644 index 000000000..604af7f5a --- /dev/null +++ b/scripts/ansible/Vagrantfile @@ -0,0 +1,5 @@ +Vagrant.configure("2") do |config| + config.vm.box = "generic/ubuntu2004" + config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/" + config.ssh.extra_args = ["-t", "cd /vagrant; bash --login"] +end diff --git a/scripts/ansible/rsshub.Caddyfile b/scripts/ansible/rsshub.Caddyfile new file mode 100644 index 000000000..7781eb24f --- /dev/null +++ b/scripts/ansible/rsshub.Caddyfile @@ -0,0 +1,3 @@ +{{ domain_name }} + +reverse_proxy localhost:1200 diff --git a/scripts/ansible/rsshub.env b/scripts/ansible/rsshub.env new file mode 100644 index 000000000..d4a283725 --- /dev/null +++ b/scripts/ansible/rsshub.env @@ -0,0 +1,3 @@ +NODE_ENV=production +CACHE_TYPE=redis +PUPPETEER_WS_ENDPOINT=ws://localhost:3000 diff --git a/scripts/ansible/rsshub.service b/scripts/ansible/rsshub.service new file mode 100644 index 000000000..0c8352a44 --- /dev/null +++ b/scripts/ansible/rsshub.service @@ -0,0 +1,11 @@ +[Unit] +Description=RSSHub is an open source, easy to use, and extensible RSS feed aggregator + +[Service] +User=rsshub +WorkingDirectory=/home/rsshub/app +ExecStart=yarn start +EnvironmentFile=/home/rsshub/app/.env + +[Install] +WantedBy=multi-user.target diff --git a/scripts/ansible/rsshub.yaml b/scripts/ansible/rsshub.yaml new file mode 100644 index 000000000..33671a51c --- /dev/null +++ b/scripts/ansible/rsshub.yaml @@ -0,0 +1,130 @@ +- + name: Install RSSHub + hosts: localhost + become: true + vars_prompt: + - + name: domain_name + prompt: What is the domain name (without www, e.g. rsshub.example.com)? Use "http://localhost" for development in Vagrant VM. + private: no + tasks: + - + name: Check OS + fail: + msg: This playbook can only be run on Ubuntu 20.04 at this moment + when: ansible_distribution != 'Ubuntu' or ansible_distribution_version !='20.04' + - + name: Install GPG keys for repos + apt_key: + url: '{{ item }}' + state: present + with_items: + - https://deb.nodesource.com/gpgkey/nodesource.gpg.key + - https://dl.yarnpkg.com/debian/pubkey.gpg + - https://download.docker.com/linux/ubuntu/gpg + - https://dl.cloudsmith.io/public/caddy/stable/cfg/gpg/gpg.155B6D79CA56EA34.key + - + name: Install repos + apt_repository: + repo: '{{ item }}' + state: present + update_cache: yes + with_items: + - deb https://deb.nodesource.com/node_12.x focal main + - deb https://dl.yarnpkg.com/debian/ stable main + - deb https://download.docker.com/linux/ubuntu focal stable + - deb https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main + - + name: Install prerequisites + apt: + name: + - nodejs + - yarn + - build-essential + - python-is-python2 + - redis-server + - docker-ce + - python3-pip + - virtualenv + - python3-setuptools + - caddy + state: present + update_cache: yes + - + name: Install python module for docker + pip: + name: docker + - + name: Pull docker image for browserless + docker_image: + name: browserless/chrome + source: pull + - + name: Start redis + systemd: + state: restarted + enabled: yes + name: redis + daemon_reload: yes + - + name: Copy caddy configuration + template: + src: rsshub.Caddyfile + dest: /etc/caddy/Caddyfile + - + name: Start caddy + systemd: + state: restarted + enabled: yes + name: caddy + daemon_reload: yes + - + name: Create and start browserless container + docker_container: + name: browserless + image: browserless/chrome + state: started + restart_policy: always + published_ports: + - "3000:3000" + - + name: Create the user + user: + name: rsshub + create_home: true + shell: /bin/bash + - + name: Clone the repo + git: + repo: https://github.com/DIYgod/RSSHub.git + dest: /home/rsshub/app + update: yes + - + name: Install repo dependencies + command: yarn install --production + args: + chdir: /home/rsshub/app + - + name: Copy configuration + copy: + src: rsshub.env + dest: /home/rsshub/app/.env + - + name: Own repo to the user + file: + path: /home/rsshub/app + owner: rsshub + group: rsshub + recurse: yes + - + name: Install the systemd unit + copy: + src: rsshub.service + dest: /etc/systemd/system/rsshub.service + - + name: Start the systemd service + systemd: + state: restarted + enabled: yes + name: rsshub + daemon_reload: yes diff --git a/scripts/ansible/try.sh b/scripts/ansible/try.sh new file mode 100755 index 000000000..cd8f1df76 --- /dev/null +++ b/scripts/ansible/try.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +vagrant rsync +vagrant ssh diff --git a/scripts/workflow/test-route/identify.js b/scripts/workflow/test-route/identify.js new file mode 100644 index 000000000..7fcf08fe4 --- /dev/null +++ b/scripts/workflow/test-route/identify.js @@ -0,0 +1,82 @@ +const noFound = 'Auto: Route No Found'; + +module.exports = async ({ github, context, core }, body, number) => { + core.debug(`body: ${body}`); + const m = body.match(/```routes\r\n((.|\r\n)*)```/); + core.debug(`match: ${m}`); + let res = null; + + const removeLabel = async () => + github.issues + .removeLabel({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + name: noFound, + }) + .catch((e) => { + core.warning(e); + }); + + if (m && m[1]) { + res = m[1].trim().split('\r\n'); + core.info(`routes detected: ${res}`); + + if (res.length > 0 && res[0] === 'NOROUTE') { + core.info('PR stated no route, passing'); + await removeLabel(); + await github.issues + .addLabels({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['Auto: No Route Needed'], + }) + .catch((e) => { + core.warning(e); + }); + + return; + } else if (res.length > 0) { + core.exportVariable('TEST_CONTINUE', true); + await removeLabel(); + return res; + } + } + + core.warning('seems no route found, failing'); + + await github.issues + .addLabels({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [noFound], + }) + .catch((e) => { + core.warning(e); + }); + await github.issues + .createComment({ + issue_number: number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `自动检测失败, 请确认PR正文部分符合格式规范并重新开启, 详情请检查日志 +Auto Route test failed, please check your PR body format and reopen pull request. Check logs for more details`, + }) + .catch((e) => { + core.warning(e); + }); + await github.pulls + .update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_nulber: number, + state: 'closed', + }) + .catch((e) => { + core.warning(e); + }); + + throw 'Please follow the PR rules: failed to detect route'; +}; diff --git a/scripts/workflow/test-route/test.js b/scripts/workflow/test-route/test.js new file mode 100644 index 000000000..45e5067e9 --- /dev/null +++ b/scripts/workflow/test-route/test.js @@ -0,0 +1,65 @@ +/* eslint-disable */ + +module.exports = async ({ github, context, core }, baseUrl, routes, number) => { + if (routes[0] === 'NOROUTE') { + return; + } + + const links = routes.map((e) => { + const l = e.startsWith('/') ? e : `/${e}`; + return `${baseUrl}${l}`; + }); + + let com = 'Successfully generated as following:\n\n'; + + for (const lks of links) { + core.info(`testing route: ${lks}`); + // Intended, one at a time + const res = await github.request(`GET ${lks}`).catch((err) => { + com += ` + +