Support sortby upvotes in Huggingface Daily Papers

This commit is contained in:
Elsa
2024-02-17 15:11:35 +08:00
parent 1886554878
commit 6e43f8e8a2
3 changed files with 14 additions and 4 deletions
+8 -2
View File
@@ -4,17 +4,23 @@ const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { body: response } = await got('https://huggingface.co/papers');
const sortby = ctx.params.sortby || 'time';
const $ = cheerio.load(response);
const papers = $('main > div[data-target="DailyPapers"]').data('props');
const items = papers.dailyPapers.map((item) => ({
let items = papers.dailyPapers.map((item) => ({
title: item.title,
link: `https://arxiv.org/abs/${item.paper.id}`,
description: item.paper.summary.replaceAll('\n', ' '),
pubDate: parseDate(item.publishedAt),
pubDate: sortby === 'time' ? parseDate(item.publishedAt) : undefined,
author: item.paper.authors.map((author) => author.name).join(', '),
upvotes: item.paper.upvotes,
}));
if (sortby === 'votes') {
items = items.sort((a, b) => b.upvotes - a.upvotes);
}
ctx.state.data = {
title: 'Huggingface Daily Papers',
link: 'https://huggingface.co/papers',
+1 -1
View File
@@ -1,4 +1,4 @@
module.exports = (router) => {
router.get('/blog-zh', require('./blog-zh'));
router.get('/daily-papers', require('./daily-papers'));
router.get('/daily-papers/:sortby?', require('./daily-papers'));
};
+5 -1
View File
@@ -490,7 +490,11 @@ Subscribe to the updates (threads and submission) from a paritcular Hacker News
### Daily Papers {#huggingface-daily-papers}
<Route author="zeyugao" example="/huggingface/daily-papers" path="/huggingface/daily-papers" />
<Route author="zeyugao" example="/huggingface/daily-papers/time" path="/huggingface/daily-papers/:sortby?" paramsDesc={['排序方式,见下表,默认为发布时间']}>
| 时间 | upvotes |
| ---- | ------- |
| time | votes |
</Route>
### 中文博客 {#huggingface-zhong-wen-bo-ke}