-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route/gocn): 修复Gocn站点RSS记录 (#13524)
* 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
Showing
9 changed files
with
239 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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¤tPage=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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.