fix(route): docschina js weekly (#11043)
This commit is contained in:
+3
-3
@@ -1176,11 +1176,11 @@ GitHub 官方也提供了一些 RSS:
|
||||
|
||||
</Route>
|
||||
|
||||
## 印记中文周刊
|
||||
## 印记中文
|
||||
|
||||
### 最新一期
|
||||
### 周刊 - JavaScript
|
||||
|
||||
<Route author="daijinru" example="/docschina/jsweekly" path="/docschina/jsweekly"/>
|
||||
<Route author="daijinru" example="/docschina/jsweekly" path="/docschina/jsweekly" radar="1" rssbud="1"/>
|
||||
|
||||
## 政采云前端技术团队
|
||||
|
||||
|
||||
+1
-1
@@ -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'));
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/jsweekly': ['daijinru'],
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/jsweekly', require('./jsweekly'));
|
||||
};
|
||||
Reference in New Issue
Block a user