diff --git a/docs/programming.md b/docs/programming.md index 462b02bae..326e5dbdc 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -1176,11 +1176,11 @@ GitHub 官方也提供了一些 RSS: -## 印记中文周刊 +## 印记中文 -### 最新一期 +### 周刊 - JavaScript - + ## 政采云前端技术团队 diff --git a/lib/router.js b/lib/router.js index 50d1ec257..c018f1af0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1790,7 +1790,7 @@ router.get('/archdaily', lazyloadRouteHandler('./routes/archdaily/home')); router.get('/aptonic/action/:untested?', lazyloadRouteHandler('./routes/aptonic/action')); // 印记中文周刊 -router.get('/docschina/jsweekly', lazyloadRouteHandler('./routes/docschina/jsweekly')); +// router.get('/docschina/jsweekly', lazyloadRouteHandler('./routes/docschina/jsweekly')); // im2maker router.get('/im2maker/:channel?', lazyloadRouteHandler('./routes/im2maker/index')); diff --git a/lib/routes/docschina/jsweekly.js b/lib/routes/docschina/jsweekly.js deleted file mode 100644 index 25ac63999..000000000 --- a/lib/routes/docschina/jsweekly.js +++ /dev/null @@ -1,47 +0,0 @@ -const got = require('../../utils/got.js'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const baseURL = 'https://weekly.docschina.org'; - const res = await got({ - method: 'get', - url: baseURL + '/javascript', - headers: { - Referer: baseURL, - }, - }); - - const $ = cheerio.load(res.data); - - const link = $('.sidebar-link').eq(1).attr('href'); - const title = $('.site-name').text(); - const description = $('a[href="https://javascriptweekly.com/"]').parent().text(); - - const articles = await got({ - method: 'get', - url: baseURL + link, - headers: { - Referer: baseURL, - }, - }); - - const $2 = cheerio.load(articles.data); - const articlesList = $2('.page .content').children(); - const items = articlesList - .map((item, element) => { - const $article = cheerio.load(element); - return { - title: $article('h3>a[rel="noopener noreferrer"]').text(), - description: $article('p').text(), - link: $article('h3>a[rel="noopener noreferrer"]').attr('href'), - }; - }) - .get() - .filter((item) => item.title !== ''); - ctx.state.data = { - title, - link: baseURL, - description, - item: items.splice(0), - }; -}; diff --git a/lib/v2/docschina/jsweekly.js b/lib/v2/docschina/jsweekly.js new file mode 100644 index 000000000..d97aac877 --- /dev/null +++ b/lib/v2/docschina/jsweekly.js @@ -0,0 +1,114 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const md = require('markdown-it')(); + +module.exports = async (ctx) => { + const baseURL = 'https://docschina.org'; + const { data: res } = await got(`${baseURL}/weekly/js/docs/`); + + const $ = cheerio.load(res); + + const title = $('head title').text(); + const vendorLink = $('body script') + .toArray() + .find((i) => + $(i) + .attr('src') + .match(/vendor/) + ).attribs.src; + + const { data: vendor } = await got(`https:${vendorLink}`); + const env = vendor.match(/default.init\({env:"(.*?)"}\)/)[1]; // docschina-live-10765e + const dataVersion = vendor.match(/,dataVersion:"(\d{4}-\d{2}-\d{2})",/)[1]; // 2020-01-10 + + // const seqId = Math.random().toString(16).slice(2); + const { data: document } = await got.post('https://tcb-api.tencentcloudapi.com/web', { + headers: { + origin: 'https://docschina.org', + // referer: 'https://docschina.org/', + // 'x-sdk-version': '@cloudbase/js-sdk/1.3.3', + // 'x-seqid': seqId, + }, + searchParams: { + env, + }, + json: { + action: 'database.queryDocument', + collectionName: 'js_weekly_document', + dataVersion, + env, + limit: 100, + query: JSON.stringify({ + path: '/', + }), + queryType: 'WHERE', + // seqId, + }, + }); + + const { data: sidebar } = await got.post('https://tcb-api.tencentcloudapi.com/web', { + headers: { + origin: 'https://docschina.org', + }, + searchParams: { + env, + }, + json: { + action: 'database.queryDocument', + collectionName: 'js_weekly_sidebar', + dataVersion, + env, + limit: 100, + query: JSON.stringify({ + pages: { + $in: [document.data.list[0]._id], + }, + }), + }, + }); + + const list = sidebar.data.list[0].value + .filter((i) => i.key !== 'home') + .map((i) => ({ + title: i.title, + link: `${baseURL}/weekly/js${i.path}`, + key: i.key, + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: document } = await got.post('https://tcb-api.tencentcloudapi.com/web', { + headers: { + origin: 'https://docschina.org', + }, + searchParams: { + env, + }, + json: { + action: 'database.queryDocument', + collectionName: 'js_weekly_document', + dataVersion, + env, + limit: 100, + query: JSON.stringify({ + path: item.key, + }), + }, + }); + + item.description = md.render(document.data.list[0].content); + + delete item.key; + return item; + }) + ) + ); + + ctx.state.data = { + title, + link: `${baseURL}/weekly/js/docs/`, + icon: 'https://docschina.org/favicon.ico', + item: items, + }; +}; diff --git a/lib/v2/docschina/maintainer.js b/lib/v2/docschina/maintainer.js new file mode 100644 index 000000000..e0fd0ea39 --- /dev/null +++ b/lib/v2/docschina/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/jsweekly': ['daijinru'], +}; diff --git a/lib/v2/docschina/radar.js b/lib/v2/docschina/radar.js new file mode 100644 index 000000000..0afa73904 --- /dev/null +++ b/lib/v2/docschina/radar.js @@ -0,0 +1,13 @@ +module.exports = { + docschina: { + _name: '印记中文', + '.': [ + { + title: '周刊 - JavaScript', + docs: 'https://docs.rsshub.app/programming.html#yin-ji-zhong-wen-zhou-kan', + source: ['/weekly/js/*', '/weekly/js', '/'], + target: '/docschina/jsweekly', + }, + ], + }, +}; diff --git a/lib/v2/docschina/router.js b/lib/v2/docschina/router.js new file mode 100644 index 000000000..fd113cfa9 --- /dev/null +++ b/lib/v2/docschina/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/jsweekly', require('./jsweekly')); +};