Skip to content

Commit

Permalink
fix(route/gocn): 修复Gocn站点RSS记录 (#13524)
Browse files Browse the repository at this point in the history
* fix: 修复Gocn站点RSS记录

Signed-off-by: Atlan <Atlan_OPS@163.com>

* feat: 修复Gocn站点RSS,并添加最新动态的RSS分类

Signed-off-by: Atlan <Atlan_OPS@163.com>

* fix: 完善Gocn站点RSS规则

Signed-off-by: Atlan <Atlan_OPS@163.com>

* fix: 完善gocn站点RSS

Signed-off-by: Atlan <Atlan_OPS@163.com>

* fix: 完善Gocn站点RSS

Signed-off-by: Atlan <Atlan_OPS@163.com>

* Apply suggestions from code review

---------

Signed-off-by: Atlan <Atlan_OPS@163.com>
  • Loading branch information
AtlanCI authored Oct 17, 2023
1 parent e69da84 commit e000ae8
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 159 deletions.
23 changes: 14 additions & 9 deletions lib/v2/gocn/jobs.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
const got = require('@/utils/got');
const util = require('./util');
const { parseDate } = require('@/utils/parse-date');
const { renderHTML } = require('./utils');

module.exports = async (ctx) => {
const base_url = 'https://gocn.vip/topics';
const api_url = 'https://gocn.vip/apiv3/topic/jobs?currentPage=1&grade=new';
const api_url = 'https://gocn.vip/api/files?spaceGuid=Gd7OHl&currentPage=1&sort=1';
const base_url = 'https://gocn.vip/c/3lQ6GbD5ny/s/Gd7OHl';
const job_url = 'https://gocn.vip/c/3lQ6GbD5ny';

const response = await got({
url: api_url,
headers: {
Referer: base_url,
},
});

const list = response.data.data.list;
const items = response.data.data.list.map((item) => ({
title: item.name,
link: `${job_url}/s/${item.spaceGuid}/d/${item.guid}`,
description: renderHTML(JSON.parse(item.content)),
pubDate: parseDate(item.ctime, 'X'),
author: item.nickname,
}));

ctx.state.data = {
title: `GoCN社区-招聘`,
link: base_url,
description: `获取GoCN站点最新招聘`,
item: await Promise.all(list.map((item) => ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))),
description: `获取GoCN站点招聘`,
item: items,
};
};
4 changes: 3 additions & 1 deletion lib/v2/gocn/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
'/': ['AtlanCI', 'CcccFz'],
'/jobs': ['CcccFz'],
'/jobs': ['AtlanCI', 'CcccFz'],
'/news': ['AtlanCI'],
'/topics': ['AtlanCI', 'CcccFz'],
};
31 changes: 31 additions & 0 deletions lib/v2/gocn/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { renderHTML } = require('./utils');

module.exports = async (ctx) => {
const base_url = 'https://gocn.vip/c/3lQ6GbD5ny/home';
const article_url = 'https://gocn.vip/c/3lQ6GbD5ny';
const api_url = 'https://gocn.vip/api/home/page';

const response = await got({
url: api_url,
headers: {
Referer: base_url,
},
});

const items = response.data.data.articlePageList.list.map((item) => ({
title: item.name,
link: `${article_url}/s/${item.spaceGuid}/d/${item.guid}`,
description: renderHTML(JSON.parse(item.content)),
pubDate: parseDate(item.ctime, 'X'),
author: item.nickname,
}));

ctx.state.data = {
title: `GoCN社区-最新动态`,
link: base_url,
description: `获取GoCN站点最新动态`,
item: items,
};
};
10 changes: 8 additions & 2 deletions lib/v2/gocn/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ module.exports = {
_name: 'GoCN',
'.': [
{
title: '文章',
title: '最新动态',
docs: 'https://docs.rsshub.app/routes/programming#GoCN',
source: ['/'],
target: '/gocn',
target: '/gocn/news',
},
{
title: '每日新闻',
docs: 'https://docs.rsshub.app/routes/programming#GoCN',
source: ['/'],
target: '/gocn/topics',
},
{
title: '招聘',
Expand Down
4 changes: 3 additions & 1 deletion lib/v2/gocn/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = function (router) {
router.get('/', require('./topics'));
router.get('/', require('./news'));
router.get('/jobs', require('./jobs'));
router.get('/news', require('./news'));
router.get('/topics', require('./topics'));
};
22 changes: 15 additions & 7 deletions lib/v2/gocn/topics.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const got = require('@/utils/got');
const util = require('./util');
const { parseDate } = require('@/utils/parse-date');
const { renderHTML } = require('./utils');

module.exports = async (ctx) => {
const base_url = 'https://gocn.vip/topics';
const api_url = 'https://gocn.vip/apiv3/topic/list?currentPage=1&cate2Id=0&grade=new';
const base_url = 'https://gocn.vip/c/3lQ6GbD5ny/home';
const article_url = 'https://gocn.vip/c/3lQ6GbD5ny';
const api_url = 'https://gocn.vip/api/files?spaceGuid=Gd7BTB&currentPage=1&sort=1';

const response = await got({
url: api_url,
Expand All @@ -12,12 +14,18 @@ module.exports = async (ctx) => {
},
});

const list = response.data.data.list;
const items = response.data.data.list.map((item) => ({
title: item.name,
link: `${article_url}/s/${item.spaceGuid}/d/${item.guid}`,
description: renderHTML(JSON.parse(item.content)),
pubDate: parseDate(item.ctime, 'X'),
author: item.nickname,
}));

ctx.state.data = {
title: `GoCN社区-文章`,
title: `GoCN社区-每日新闻`,
link: base_url,
description: `获取GoCN站点最新文章`,
item: await Promise.all(list.map((item) => ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))),
description: `获取GoCN站点每日新闻`,
item: items,
};
};
17 changes: 0 additions & 17 deletions lib/v2/gocn/util.js

This file was deleted.

38 changes: 38 additions & 0 deletions lib/v2/gocn/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const elementMap = {
code_block: (element) => `<pre><code class="${element.language}">${element.children[0].text}</code></pre>`,
a: (element) => `<a href="${element.url}">${renderHTML(element.children)}</a>`,
blockquote: (element) => `<blockquote>${renderHTML(element.children)}</blockquote>`,
br: () => '<br>',
h1: (element) => `<h1>${element.children[0].text}</h1>`,
h2: (element) => `<h2>${element.children[0].text}</h2>`,
h3: (element) => `<h3>${element.children[0].text}</h3>`,
h4: (element) => `<h4>${element.children[0].text}</h4>`,
h5: (element) => `<h5>${element.children[0].text}</h5>`,
h6: (element) => `<h6>${element.children[0].text}</h6>`,
img: (element) => `<img src="${element.url}">`,
p: (element) => `<p>${renderHTML(element.children)}</p>`,
strong: (element) => `<strong>${renderHTML(element.children)}</strong>`,
ol: (element) => `<ol>${renderHTML(element.children)}</ol>`,
ul: (element) => `<ul>${renderHTML(element.children)}</ul>`,
li: (element) => `<li>${renderHTML(element.children)}</li>`,
lic: (element) => element.children[0].text,
};

function renderHTML(json) {
return json
.map((element) => {
const handler = elementMap[element.type];
if (handler) {
return handler(element);
} else if (element.hasOwnProperty('text')) {
return element.text;
} else {
throw new Error(`Unknown handled type: ${element.type}, ${JSON.stringify(element)}`);
}
})
.join('');
}

module.exports = {
renderHTML,
};
Loading

0 comments on commit e000ae8

Please sign in to comment.