forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 添加电鸭社区分类文章路由 (DIYgod#11758)
* feat(route): 添加电鸭社区分类文章路由 * fix(route): 修复eslint错误 * Update lib/v2/eleduck/posts.js * Update lib/v2/eleduck/posts.js * fix(route): 增加维护者文件 * refactor: migrate to v2 ---------
- Loading branch information
1 parent
247643e
commit d5ada18
Showing
9 changed files
with
142 additions
and
40 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
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
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 got = require('@/utils/got'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { data: response } = await got('https://svc.eleduck.com/api/v1/posts', { | ||
searchParams: { | ||
category: 5, | ||
}, | ||
}); | ||
|
||
const data = response.posts.map((item) => ({ | ||
id: item.id, | ||
title: item.title, | ||
link: `https://eleduck.com/posts/${item.id}`, | ||
author: item.user.nickname, | ||
description: item.summary, | ||
pubDate: parseDate(item.published_at), | ||
category: item.tags.map((tag) => tag.name), | ||
})); | ||
|
||
const out = await Promise.all( | ||
data.map((job) => | ||
ctx.cache.tryGet(job.link, async () => { | ||
const { data: jobDetail } = await got(`https://svc.eleduck.com/api/v1/posts/${job.id}`); | ||
|
||
job.description = jobDetail.post.content; | ||
|
||
return job; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '招聘 | 电鸭社区', | ||
link: 'https://eleduck.com/category/5', | ||
item: out, | ||
}; | ||
}; |
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,4 @@ | ||
module.exports = { | ||
'/jobs': ['sfyumi'], | ||
'/posts/:id?': ['running-grass'], | ||
}; |
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,42 @@ | ||
const got = require('@/utils/got'); | ||
|
||
const getCateName = async (ctx, cid = 0) => { | ||
const key = 'eleduck-categories'; | ||
const cates = await ctx.cache.tryGet(key, async () => { | ||
const res = await got(`https://svc.eleduck.com/api/v1/categories`); | ||
const map = {}; | ||
res.data.categories.forEach((item) => { | ||
map[item.id] = item.name; | ||
}); | ||
return map; | ||
}); | ||
|
||
return cates[cid] || '全部'; | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const cid = ctx.params.id || 0; | ||
|
||
const response = await got(`https://svc.eleduck.com/api/v1/posts?category=${cid}`); | ||
|
||
const { posts } = response.data; | ||
if (posts === undefined) { | ||
throw new Error("没有获取到数据"); | ||
} | ||
|
||
const cname = await getCateName(ctx, cid); | ||
|
||
ctx.state.data = { | ||
title: `电鸭社区的文章--${cname}`, | ||
link: `https://eleduck.com/categories/${cid}`, | ||
description: `电鸭社区的文章,栏目为${cname}`, | ||
item: posts.map((item) => ({ | ||
title: item.title, | ||
description: item.summary, | ||
pubDate: item.published_at, | ||
link: `https://eleduck.com/${item.category.id === 22 ? 'tposts' : 'posts'}/${item.id}`, | ||
author: item.user.nickname, | ||
})), | ||
}; | ||
|
||
}; |
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,25 @@ | ||
module.exports = { | ||
'eleduck.com': { | ||
_name: '电鸭社区', | ||
'.': [ | ||
{ | ||
title: '工作机会', | ||
docs: 'https://docs.rsshub.app/bbs.html#dian-ya-she-qu-fen-lei-wen-zhang', | ||
source: ['/categories/5', '/'], | ||
target: '/eleduck/jobs', | ||
}, | ||
{ | ||
title: '分类文章', | ||
docs: 'https://docs.rsshub.app/bbs.html#dian-ya-she-qu-fen-lei-wen-zhang', | ||
source: '/categories/:cid', | ||
target: (params) => `/eleduck/posts${params.cid}`, | ||
}, | ||
{ | ||
title: '全部文章', | ||
docs: 'https://docs.rsshub.app/bbs.html#dian-ya-she-qu-fen-lei-wen-zhang', | ||
source: '*', | ||
target: () => '/eleduck/posts', | ||
}, | ||
], | ||
}, | ||
}; |
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,4 @@ | ||
module.exports = (router) => { | ||
router.get('/jobs', require('./jobs')); | ||
router.get('/posts/:id?', require('./posts')); | ||
}; |