Files
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

39 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const titles = {
total: '全站',
focus: '国际',
science: '科学',
car: '汽车',
zvideo: '视频',
fashion: '时尚',
depth: '时事',
digital: '数码',
sport: '体育',
school: '校园',
film: '影视',
};
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'total';
const response = await got({
method: 'get',
url: `https://www.zhihu.com/api/v3/feed/topstory/hot-lists/${category}?limit=50`,
});
const items = response.data.data.map((item) => ({
link: `https://www.zhihu.com/question/${item.target.id}`,
title: item.target.title,
pubDate: parseDate(item.target.created * 1000),
description: item.target.excerpt ? `<p>${item.target.excerpt}</p>` : '',
}));
ctx.state.data = {
title: `知乎热榜 - ${titles[category]}`,
link: `https://www.zhihu.com/hot?list=${category}`,
item: items,
};
};