From 8b2aaf8bb0143b74605b30d12923fb59eb485ebb Mon Sep 17 00:00:00 2001 From: AgFlore Date: Mon, 5 Oct 2020 19:31:36 +0800 Subject: [PATCH 01/12] feat: add author/personal follow for initium (#5798) --- docs/traditional-media.md | 15 +++++++++++++++ lib/routes/initium/full.js | 31 ++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/docs/traditional-media.md b/docs/traditional-media.md index e914ff81b..88971d963 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -279,6 +279,21 @@ Type 栏目: +### 作者 + + + +### 个人订阅追踪动态 + + + +::: warning 注意 + +需要自建,详情见部署页面的配置模块。 + +::: + + ## 多维新闻网 ### 要闻 diff --git a/lib/routes/initium/full.js b/lib/routes/initium/full.js index b84f0ccb7..12414f908 100644 --- a/lib/routes/initium/full.js +++ b/lib/routes/initium/full.js @@ -4,23 +4,21 @@ const cheerio = require('cheerio'); const resolve_url = require('url').resolve; module.exports = async (ctx) => { - // model是channel/tag/etc.,而type是latest/feature/quest-academy/etc. + // model是channel/tag/etc.,而type是latest/feature/quest-academy这些一级栏目/标签/作者名的slug名。如果是追踪的话,那就是model是follow,type是articles。 const model = ctx.params.model || 'channel'; const type = ctx.params.type || 'latest'; const language = ctx.params.language || 'zh-hans'; let listurl; let listlink; switch (model) { - /* case 'author': listurl = `https://api.theinitium.com/api/v2/author/?language=${language}&slug=${type}`; listlink = `https://theinitium.com/author/${type}/`; break; - case 'follows': - listurl = `https://api.theinitium.com/api/v2/user/follows/?language=${language}&slug=${type}`; + case 'follow': + listurl = `https://api.theinitium.com/api/v2/user/follows/${type}/?language=${language}`; listlink = `https://theinitium.com/follow/`; break; - */ case 'channel': listurl = `https://api.theinitium.com/api/v2/channel/articles/?language=${language}&slug=${type}`; listlink = `https://theinitium.com/channel/${type}/`; @@ -90,9 +88,11 @@ module.exports = async (ctx) => { }, }); - const name = response.data.name; - const articles = response.data.digests; - const image = 'https://d32kak7w9u5ewj.cloudfront.net/static/bundles/0b9cf7fe9c518887768e6c485764cd12.ico'; + const name = response.data.name || (response.data[model] && response.data[model].name) || '追踪'; + // 从v1直升的channel和tags里面是digests,v2新增的author和follow出来都是results + const articles = response.data.results ? response.data.results : response.data.digests; + // 如果model=author,那就是avatar;否则都是cover,要么就没封面 + const image = response.data[model] && (response.data[model].cover || response.data[model].avatar); const getFullText = async (slug) => { let content = await ctx.cache.get(slug + language); @@ -125,6 +125,18 @@ module.exports = async (ctx) => { } if (data.content) { content += data.content.replace('