From 7a2faa74ad98cb16fed562f472777d3cf6a2912f Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Nov 2020 23:47:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=A7=82=E5=AF=9F=E8=80=85?= =?UTF-8?q?=E7=BD=91=E8=A7=82=E5=AD=A6=E9=99=A2=20(#6143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 10 +++++ lib/router.js | 1 + lib/routes/guancha/member.js | 71 ++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 lib/routes/guancha/member.js diff --git a/docs/new-media.md b/docs/new-media.md index 665f1e7b14..3bdd249971 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -797,6 +797,16 @@ others = 热点新闻 + 滚动新闻 +### 观学院 + + + +| 精选 | 观书堂 | 在线课 | 观学院 | +| --------- | ------ | ------- | -------- | +| recommend | books | courses | huodongs | + + + ### 风闻话题 diff --git a/lib/router.js b/lib/router.js index 349115fbcc..b146d36ee8 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1701,6 +1701,7 @@ router.get('/zfrontier/board/:boardId', require('./routes/zfrontier/board_postli // 观察者网 router.get('/guancha/topic/:id/:order?', require('./routes/guancha/topic')); +router.get('/guancha/member/:caty?', require('./routes/guancha/member')); router.get('/guancha/personalpage/:uid', require('./routes/guancha/personalpage')); router.get('/guancha/:caty?', require('./routes/guancha/index')); diff --git a/lib/routes/guancha/member.js b/lib/routes/guancha/member.js new file mode 100644 index 0000000000..50157e17ea --- /dev/null +++ b/lib/routes/guancha/member.js @@ -0,0 +1,71 @@ +const got = require('@/utils/got'); + +const title = { + recommend: '精选', + books: '观书堂', + courses: '在线课', + huodongs: '观学院', +}; + +module.exports = async (ctx) => { + const caty = ctx.params.caty || 'recommend'; + + const rootUrl = 'https://member.guancha.cn'; + const apiUrl = `${rootUrl}/zaixianke/home`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items; + + switch (caty) { + case 'books': + items = response.data.data.books.map((item) => ({ + title: item.title, + link: `${rootUrl}/guanshutang/summary.html?id=${item.id}`, + description: `

[${item.audio_time}] ${item.desc_short}

`, + pubDate: new Date(parseInt(item.cover.split('/').pop().substr(0, 10)) * 1000).toUTCString(), + })); + break; + + case 'courses': + items = response.data.data.courses.data.map((item) => { + let description = '', + pubDate = new Date(0); + + for (const i of item.items) { + const newPubDate = new Date(i.publish_time); + pubDate = pubDate > newPubDate ? pubDate : newPubDate; + description += `${i.title}
`; + } + + return { + title: item.name, + link: `${rootUrl}/zaixianke/summary.html?id=${item.id}`, + author: item.author_name, + description: `

${item.desc_short}


${description}`, + pubDate: pubDate.toUTCString(), + }; + }); + break; + + default: + items = response.data.data[caty].map((item) => ({ + title: item.title, + link: item.jump_url, + author: item.author_name, + description: `

${item.summary}

`, + enclosure_url: item.media_url, + enclosure_length: item.media_size, + enclosure_type: 'audio/mpeg', + pubDate: new Date(item.created_at * 1000).toUTCString(), + })); + } + + ctx.state.data = { + title: `观学院 - ${title[caty]}`, + link: `${rootUrl}/index.html`, + item: items, + }; +};