feat(routes): Support fetching by different publication cycle and flitering by votes for Huggingfce papers. (#19858)
* feat(routes): Support fetching by different publication cycle and flitering by votes for Huggingfce papers. * feat(routes): add comment links * fix(routes): string concatenation style & remove upvotes info from description * fix(routes): remove comments
This commit is contained in:
@@ -4,10 +4,10 @@ import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/daily-papers',
|
||||
path: '/daily-papers/:cycle?/:voteFliter?',
|
||||
categories: ['programming'],
|
||||
example: '/huggingface/daily-papers',
|
||||
parameters: {},
|
||||
example: '/huggingface/daily-papers/week/50',
|
||||
parameters: { cycle: 'The publication cycle you want to follow. Choose from: date, week, month. Default: date', voteFliter: 'Filter papers by vote count.' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
@@ -18,21 +18,57 @@ export const route: Route = {
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['huggingface.co/papers', 'huggingface.co/'],
|
||||
source: ['huggingface.co/papers/:cycle'],
|
||||
target: '/daily-papers/:cycle',
|
||||
},
|
||||
],
|
||||
name: 'Daily Papers',
|
||||
maintainers: ['zeyugao'],
|
||||
maintainers: ['zeyugao', 'ovo-tim'],
|
||||
handler,
|
||||
url: 'huggingface.co/papers',
|
||||
};
|
||||
|
||||
async function handler() {
|
||||
const { body: response } = await got('https://huggingface.co/papers');
|
||||
interface Paper {
|
||||
id: string;
|
||||
summary: string;
|
||||
upvotes: number;
|
||||
authors: { name: string }[];
|
||||
}
|
||||
|
||||
interface DailyPaperItem {
|
||||
title: string;
|
||||
paper: Paper;
|
||||
publishedAt: string;
|
||||
}
|
||||
|
||||
interface PapersData {
|
||||
dailyPapers: DailyPaperItem[];
|
||||
}
|
||||
|
||||
async function handler(ctx) {
|
||||
const { cycle = 'date', voteFliter = '0' } = ctx.req.param();
|
||||
let url: string;
|
||||
switch (cycle) {
|
||||
case 'date':
|
||||
url = 'https://huggingface.co/papers';
|
||||
break;
|
||||
case 'week':
|
||||
// We don't actually need to get the week number, because huggingface.co/papers/week/YYYY-W52 will redirect to the latest week
|
||||
url = `https://huggingface.co/papers/week/${new Date().getFullYear()}-W52`;
|
||||
break;
|
||||
case 'month':
|
||||
url = `https://huggingface.co/papers/month/${new Date().toISOString().slice(0, 7)}`;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Invalid cycle: ${cycle}`);
|
||||
}
|
||||
|
||||
const { body: response } = await got(url);
|
||||
const $ = load(response);
|
||||
const papers = $('main > div[data-target="DailyPapers"]').data('props');
|
||||
const papers = $('main > div[data-target="DailyPapers"]').data('props') as PapersData;
|
||||
|
||||
const items = papers.dailyPapers
|
||||
.filter((item) => item.paper.upvotes >= voteFliter)
|
||||
.map((item) => ({
|
||||
title: item.title,
|
||||
link: `https://arxiv.org/abs/${item.paper.id}`,
|
||||
|
||||
Reference in New Issue
Block a user