mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 18:18:06 +08:00
feat(route): add Go语言中文网板块 (#12274)
This commit is contained in:
@@ -350,13 +350,17 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
## Go 语言中文网
|
## Go 语言中文网
|
||||||
|
|
||||||
|
### 板块
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/studygolang/go/daily" path="/studygolang/go/:id?" :paramsDesc="['板块 id,默认为周刊']" radar="1"/>
|
||||||
|
|
||||||
### 周刊
|
### 周刊
|
||||||
|
|
||||||
<Route author="Weilet" example="/studygolang/weekly" path="/studygolang/weekly" radar="1"/>
|
<Route author="Weilet nczitzk" example="/studygolang/weekly" path="/studygolang/weekly" radar="1"/>
|
||||||
|
|
||||||
### 招聘
|
### 招聘
|
||||||
|
|
||||||
<Route author="CcccFz" example="/studygolang/jobs" path="/studygolang/jobs" radar="1" rssbud="1"/>
|
<Route author="CcccFz nczitzk" example="/studygolang/jobs" path="/studygolang/jobs" radar="1" rssbud="1"/>
|
||||||
|
|
||||||
## GoCN
|
## GoCN
|
||||||
|
|
||||||
|
|||||||
5
lib/v2/studygolang/go.js
Normal file
5
lib/v2/studygolang/go.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const { FetchGoItems } = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
ctx.state.data = await FetchGoItems(ctx);
|
||||||
|
};
|
||||||
@@ -1,37 +1,7 @@
|
|||||||
const got = require('@/utils/got');
|
const { FetchGoItems } = require('./utils');
|
||||||
const cheerio = require('cheerio');
|
|
||||||
const { parseDate } = require('@/utils/parse-date');
|
|
||||||
const timezone = require('@/utils/timezone');
|
|
||||||
const base_url = 'https://studygolang.com';
|
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const jobs_url = 'https://studygolang.com/go/jobs';
|
ctx.params.id = 'jobs';
|
||||||
|
|
||||||
const response = await got({
|
ctx.state.data = await FetchGoItems(ctx);
|
||||||
url: jobs_url,
|
|
||||||
headers: {
|
|
||||||
Referer: base_url,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const $ = cheerio.load(response.data);
|
|
||||||
const list = $('.topics .topic').get();
|
|
||||||
|
|
||||||
ctx.state.data = {
|
|
||||||
title: 'Go语言中文网 | 招聘',
|
|
||||||
link: jobs_url,
|
|
||||||
description: `获取Go语言中文网的最新招聘`,
|
|
||||||
item: await Promise.all(list.map((item) => getFeedItem(item))),
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getFeedItem(item) {
|
|
||||||
const $ = cheerio.load(item);
|
|
||||||
const title = $('.title a');
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: title.attr('title'),
|
|
||||||
link: `${base_url}${title.attr('href')}`,
|
|
||||||
pubDate: timezone(parseDate($('.meta .timeago').attr('title'), 'YYYY-MM-DD hh:mm:ss'), +8),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
'/jobs': ['CcccFz'],
|
'/go/:id?': ['nczitzk'],
|
||||||
'/weekly': ['Weilet'],
|
'/jobs': ['CcccFz', 'nczitzk'],
|
||||||
|
'/weekly': ['CWeilet', 'nczitzk'],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,17 +2,23 @@ module.exports = {
|
|||||||
'studygolang.com': {
|
'studygolang.com': {
|
||||||
_name: 'Go 语言中文网',
|
_name: 'Go 语言中文网',
|
||||||
'.': [
|
'.': [
|
||||||
|
{
|
||||||
|
title: '板块',
|
||||||
|
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||||
|
source: ['/go/:id', '/'],
|
||||||
|
target: '/studygolang/go/:id?',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: '招聘',
|
title: '招聘',
|
||||||
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||||
source: ['/'],
|
source: ['/go/jobs', '/'],
|
||||||
target: '/studygolang/jobs',
|
target: '/studygolang/go/jobs',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '周刊',
|
title: '周刊',
|
||||||
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||||
source: ['/go/weekly', '/'],
|
source: ['/go/weekly', '/'],
|
||||||
target: '/studygolang/weekly',
|
target: '/studygolang/go/weekly',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module.exports = function (router) {
|
module.exports = function (router) {
|
||||||
|
router.get('/go/:id?', require('./go'));
|
||||||
router.get('/jobs', require('./jobs'));
|
router.get('/jobs', require('./jobs'));
|
||||||
router.get('/weekly', require('./weekly'));
|
router.get('/weekly', require('./weekly'));
|
||||||
};
|
};
|
||||||
|
|||||||
74
lib/v2/studygolang/utils.js
Normal file
74
lib/v2/studygolang/utils.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const timezone = require('@/utils/timezone');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
const md = require('markdown-it')({
|
||||||
|
html: true,
|
||||||
|
linkify: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
FetchGoItems: async (ctx) => {
|
||||||
|
const id = ctx.params.id ?? 'weekly';
|
||||||
|
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
|
||||||
|
|
||||||
|
const rootUrl = 'https://studygolang.com';
|
||||||
|
const currentUrl = `${rootUrl}/go/${id}`;
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: currentUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
let items = $('.right-info .title')
|
||||||
|
.slice(0, limit)
|
||||||
|
.toArray()
|
||||||
|
.map((item) => {
|
||||||
|
item = $(item);
|
||||||
|
|
||||||
|
const a = item.find('a');
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: a.text(),
|
||||||
|
link: `${rootUrl}${a.attr('href')}`,
|
||||||
|
author: item.next().find('.author').text(),
|
||||||
|
category: item
|
||||||
|
.next()
|
||||||
|
.find('.node')
|
||||||
|
.toArray()
|
||||||
|
.map((n) => $(n).text()),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
items = await Promise.all(
|
||||||
|
items.map((item) =>
|
||||||
|
ctx.cache.tryGet(item.link, async () => {
|
||||||
|
const detailResponse = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: item.link,
|
||||||
|
});
|
||||||
|
|
||||||
|
const content = cheerio.load(detailResponse.data);
|
||||||
|
|
||||||
|
item.pubDate = timezone(parseDate(content('.timeago').first().attr('title')), +8);
|
||||||
|
|
||||||
|
try {
|
||||||
|
item.description = md.render(content('.content').html());
|
||||||
|
} catch (e) {
|
||||||
|
// no-empty
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `Go语言中文网 - ${$('.title h2').text()}`,
|
||||||
|
link: currentUrl,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,29 +1,7 @@
|
|||||||
const got = require('@/utils/got');
|
const { FetchGoItems } = require('./utils');
|
||||||
const cheerio = require('cheerio');
|
|
||||||
|
|
||||||
module.exports = async (ctx) => {
|
module.exports = async (ctx) => {
|
||||||
const url = 'https://studygolang.com/go/weekly';
|
ctx.params.id = 'weekly';
|
||||||
const response = await got({
|
|
||||||
method: 'get',
|
|
||||||
url,
|
|
||||||
});
|
|
||||||
const $ = cheerio.load(response.data);
|
|
||||||
const resultItem = $('div.topic div.title')
|
|
||||||
.map((_index, elem) => {
|
|
||||||
elem = $(elem);
|
|
||||||
const $link = elem.find('a');
|
|
||||||
const title = $link.text();
|
|
||||||
const link = $link.attr('href');
|
|
||||||
return {
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.get();
|
|
||||||
|
|
||||||
ctx.state.data = {
|
ctx.state.data = await FetchGoItems(ctx);
|
||||||
title: 'Go语言爱好者周刊',
|
|
||||||
link: url,
|
|
||||||
item: resultItem,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user