Files
RSSHub/lib/v2/zhihu/pin/utils.js
T
08602c778c fix(route): 修复/zhihu/question无法获取,需要设置非登录状态下cookie (#9729)
* 修复/zhihu/question,需要设置非登录状态下cookie

* Update lib/routes/zhihu/execlib/g_encrypt.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* 根据TonyRL review建议进行了修改

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* 增加cookie中dc_0字段检验

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* Update lib/routes/zhihu/question.js

Co-authored-by: Rongrong <Rongronggg9@outlook.com>

* refactor: migrate to v2

* fix: Incomplete URL substring sanitization

Co-authored-by: Rongrong <Rongronggg9@outlook.com>
2022-05-14 00:21:11 +08:00

61 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { parseDate } = require('@/utils/parse-date');
module.exports = {
generateData: (data) =>
data.map((item) => {
const target = item.target ? item.target : item;
const pubDate = parseDate(target.created * 1000);
const author = target.author.name;
const title = `${author}:${target.excerpt_title}`;
const link = `https://www.zhihu.com/pin/${target.id}`;
const description = target.content.reduce((description, item) => {
switch (item.type) {
case 'text':
description += `<div>${item.content}</div>`;
break;
case 'image':
description += `<img src="${item.url.replace(/_.+\.jpg/g, '.jpg')}" />`;
break;
case 'video':
try {
description += `<video
controls="controls"
width="${item.playlist.hd.width}"
height="${item.playlist.hd.height}"
poster="${item.cover_info.thumbnail}"
src="${item.playlist.hd.play_url}"
>`;
} catch (e) {
description += `<video
controls="controls"
width="${item.playlist.pop().width}"
height="${item.playlist.pop().height}"
poster="${item.thumbnail}"
src="${item.playlist.pop().play_url}"
>`;
}
break;
case 'link':
description += `<div><a href="${item.url}">${item.title}</a><br><img src="${item.image_url}" /></div>`;
break;
default:
description += '未知类型,请点击<a href="https://github.com/DIYgod/RSSHub/issues">链接</a>提交issue';
}
return description;
}, `<a href="https://www.zhihu.com${target.author.url}">${author}</a>:`);
return {
title,
description,
author,
pubDate,
link,
};
}),
};