Files
RSSHub/lib/routes/1point3acres/post.js
T
Daniel Li (李丹阳)andSukka d77a039f05 style(eslint): add no-implicit-coercion rule (#8175)
* refactor: add no-implicit-coercion rule for ESLint

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* fix: errors from deepscan

* Update docs/en/joinus/quick-start.md

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update docs/joinus/quick-start.md

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/av01/tag.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/gov/taiwan/mnd.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* Update lib/routes/ps/product.js

Co-authored-by: Sukka <isukkaw@gmail.com>

* refactor: minify html string

Co-authored-by: Sukka <isukkaw@gmail.com>
2021-09-15 21:22:11 +08:00

51 lines
1.8 KiB
JavaScript

const got = require('@/utils/got');
const bbcode = require('bbcodejs');
module.exports = async (ctx) => {
const category = ctx.params.category;
let url;
let title;
if (category === 'new') {
url = 'https://api.1point3acres.com/api/threads?type=new&pg=1&ps=20&includes=summary';
title = '最新帖子';
} else {
url = 'https://api.1point3acres.com/api/threads?type=hot&pg=1&ps=20&includes=summary';
title = '热门帖子';
}
const responseBasic = await got({
method: 'get',
url,
});
const data = responseBasic.data.threads;
const bbcodeParser = new bbcode.Parser();
const items = await Promise.all(
data.map(async (item) => {
const result = {
title: item.subject,
description: `${item.summary}...<br><br><small>作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}</small>`,
link: `https://instant.1point3acres.com/thread/${item.tid}`,
};
try {
await ctx.cache.tryGet(item.link, async () => {
const detail = await got({
method: 'get',
url: `https://api.1point3acres.com/instant/threads/${item.tid}`,
referer: 'https://instant.1point3acres.com/',
});
result.description = `${bbcodeParser.toHTML(detail.data.thread.message_bbcode)}<br><br><small>作者 ${item.author} · 回复 ${item.replies} · 查看 ${item.views}</small>`;
});
} catch (error) {
// nothing
}
return result;
})
);
ctx.state.data = {
title: `一亩三分地 - ${title}`,
link: `https://www.1point3acres.com/bbs/`,
item: items,
};
};