diff --git a/docs/other.md b/docs/other.md index 2652bcd03b..31b0ff9e78 100644 --- a/docs/other.md +++ b/docs/other.md @@ -215,6 +215,11 @@ type 为 all 时,category 参数不支持 cost 和 free +## 电鸭社区 + +### 工作机会 + + ## 福利资源-met.red ### 福利资源-met.red diff --git a/lib/router.js b/lib/router.js index 53443f5997..6967568e35 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1783,6 +1783,9 @@ router.get('/mail/imap/:email', require('./routes/mail/imap')); // 智联招聘 router.get('/zhilian/:city/:keyword', require('./routes/zhilian/index')); +// 电鸭社区 +router.get('/eleduck/jobs', require('./routes/eleduck/jobs')); + // 北华航天工业学院 - 新闻 router.get('/nciae/news', require('./routes/universities/nciae/news')); diff --git a/lib/routes/eleduck/jobs.js b/lib/routes/eleduck/jobs.js new file mode 100644 index 0000000000..aa98a1a90d --- /dev/null +++ b/lib/routes/eleduck/jobs.js @@ -0,0 +1,38 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: `https://svc.eleduck.com/api/v1/posts?category=5&page=1`, + }); + + const data = response.data.posts; + + const out = await Promise.all( + data.map(async (job) => { + const url = `https://svc.eleduck.com/api/v1/posts/${job.id}`; + const cache = await ctx.cache.get(url); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got.get(url); + const jobDetail = response.data.post; + + const single = { + title: jobDetail.title, + link: `https://eleduck.com/posts/${job.id}`, + author: jobDetail.user.nickname, + description: jobDetail.content.main, + pubDate: new Date(jobDetail.published_at).toUTCString(), + }; + ctx.cache.set(url, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '电鸭社区-工作机会', + link: 'https://eleduck.com/?category=5', + item: out, + }; +};