mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
feat(route): add Go语言中文网板块 (#12274)
This commit is contained in:
@@ -350,13 +350,17 @@ GitHub 官方也提供了一些 RSS:
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
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 cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const base_url = 'https://studygolang.com';
|
||||
const { FetchGoItems } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const jobs_url = 'https://studygolang.com/go/jobs';
|
||||
ctx.params.id = 'jobs';
|
||||
|
||||
const response = await got({
|
||||
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))),
|
||||
ctx.state.data = await FetchGoItems(ctx);
|
||||
};
|
||||
};
|
||||
|
||||
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 = {
|
||||
'/jobs': ['CcccFz'],
|
||||
'/weekly': ['Weilet'],
|
||||
'/go/:id?': ['nczitzk'],
|
||||
'/jobs': ['CcccFz', 'nczitzk'],
|
||||
'/weekly': ['CWeilet', 'nczitzk'],
|
||||
};
|
||||
|
||||
@@ -2,17 +2,23 @@ module.exports = {
|
||||
'studygolang.com': {
|
||||
_name: 'Go 语言中文网',
|
||||
'.': [
|
||||
{
|
||||
title: '板块',
|
||||
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||
source: ['/go/:id', '/'],
|
||||
target: '/studygolang/go/:id?',
|
||||
},
|
||||
{
|
||||
title: '招聘',
|
||||
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||
source: ['/'],
|
||||
target: '/studygolang/jobs',
|
||||
source: ['/go/jobs', '/'],
|
||||
target: '/studygolang/go/jobs',
|
||||
},
|
||||
{
|
||||
title: '周刊',
|
||||
docs: 'https://docs.rsshub.app/programming.html#go-yu-yan-zhong-wen-wang',
|
||||
source: ['/go/weekly', '/'],
|
||||
target: '/studygolang/weekly',
|
||||
target: '/studygolang/go/weekly',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/go/:id?', require('./go'));
|
||||
router.get('/jobs', require('./jobs'));
|
||||
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 cheerio = require('cheerio');
|
||||
const { FetchGoItems } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://studygolang.com/go/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.params.id = 'weekly';
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Go语言爱好者周刊',
|
||||
link: url,
|
||||
item: resultItem,
|
||||
};
|
||||
ctx.state.data = await FetchGoItems(ctx);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user