diff --git a/lib/routes/zhihu/timeline.ts b/lib/routes/zhihu/timeline.ts index bafa3130b..1c3aaab4e 100644 --- a/lib/routes/zhihu/timeline.ts +++ b/lib/routes/zhihu/timeline.ts @@ -30,18 +30,21 @@ export const route: Route = { :::`, }; -async function handler() { +async function handler(ctx) { const cookie = config.zhihu.cookies; if (cookie === undefined) { throw new Error('缺少知乎用户登录后的 Cookie 值'); } - const response = await got({ method: 'get', - url: `https://www.zhihu.com/api/v3/moments?desktop=true`, + url: `https://www.zhihu.com/api/v3/moments`, headers: { Cookie: cookie, }, + searchParams: { + desktop: true, + limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15, + }, }); const feeds = response.data.data; @@ -99,18 +102,19 @@ async function handler() { if (!e || !e.target) { return {}; } + const link = buildLink(e); return { title: `${e.action_text_tpl.replace('{}', buildActors(e))}: ${getOne([e.target.title, e.target.question ? e.target.question.title : ''])}`, description: utils.ProcessImage(`
${getOne([e.target.content_html, getContent(e.target.content), e.target.detail, e.target.excerpt, ''])}
`), pubDate: parseDate(e.updated_time * 1000), - link: buildLink(e), + link, author: e.target.author ? e.target.author.name : '', - guid: this.link, + guid: link, }; }; const out = feeds - .filter((e) => e && e.type && e.type !== 'feed_advert') + .filter((e) => e.verb && e.verb !== 'MEMBER_VOTEUP_ARTICLE' && e.verb !== 'MEMBER_VOTEUP_ANSWER') .map((e) => { if (e && e.type && e.type === 'feed_group') { // A feed group contains a list of feeds whose structure is the same as a single feed @@ -123,7 +127,7 @@ async function handler() { .join('') : ''; const pubDate = e.list && Array.isArray(e.list) && e.list.length > 0 ? parseDate(e.list[0].updated_time * 1000) : new Date(); - const guid = `${title} ${pubDate}`; + const guid = e.link; return { title, description, diff --git a/lib/routes/zhihu/utils.ts b/lib/routes/zhihu/utils.ts index d1790c56d..217bb9ebb 100644 --- a/lib/routes/zhihu/utils.ts +++ b/lib/routes/zhihu/utils.ts @@ -15,8 +15,12 @@ export default { const href = $(elem).attr('href'); if (href?.startsWith('https://link.zhihu.com/?target=')) { const url = new URL(href); - const target = url.searchParams.get('target'); - $(elem).attr('href', decodeURIComponent(target)); + const target = url.searchParams.get('target') || ''; + try { + $(elem).attr('href', decodeURIComponent(target)); + } catch { + // sometimes the target is not a valid url + } } });