Skip to content

Commit

Permalink
Merge branch 'DIYgod:master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenXiangcheng1 authored Jul 26, 2024
2 parents 1f0fc05 + bc0f3d4 commit 74a74e4
Show file tree
Hide file tree
Showing 23 changed files with 665 additions and 193 deletions.
29 changes: 29 additions & 0 deletions lib/routes/autocentre/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Data, Route } from '@/types';
import parser from '@/utils/rss-parser';

export const route: Route = {
path: '/',
name: 'Автомобільний сайт N1 в Україні',
categories: ['new-media'],
maintainers: ['driversti'],
example: '/autocentre',
handler,
};

const createItem = (item) => ({
title: item.title,
link: item.link,
description: item.contentSnippet,
});

async function handler(): Promise<Data> {
const feed = await parser.parseURL('https://www.autocentre.ua/rss');

return {
title: feed.title as string,
link: feed.link,
description: feed.description,
language: 'uk',
item: await Promise.all(feed.items.map((item) => createItem(item))),
};
}
7 changes: 7 additions & 0 deletions lib/routes/autocentre/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'Автоцентр.ua',
url: 'autocentre.ua',
description: 'Автоцентр.ua: автоновини - Автомобільний сайт N1 в Україні',
};
48 changes: 48 additions & 0 deletions lib/routes/chlinlearn/daily-blog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch'; // 统一使用的请求库
import { parseDate } from '@/utils/parse-date'; // 解析日期的工具函数
import timezone from '@/utils/timezone';

export const route: Route = {
path: '/daily-blog',
name: '值得一读技术博客',
maintainers: ['huyyi'],
categories: ['programming'],
example: '/chlinlearn/daily-blog',
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['daily-blog.chlinlearn.top/blogs/*'],
target: '/chlinlearn/daily-blog',
},
],
handler: async () => {
const data = await ofetch('https://daily-blog.chlinlearn.top/api/daily-blog/getBlogs/new?type=new&pageNum=1&pageSize=20', {
headers: {
Referer: 'https://daily-blog.chlinlearn.top/blogs/1',
},
});
const items = data.rows.map((item) => ({
title: item.title,
link: item.url,
author: item.author,
img: item.icon,
pubDate: timezone(parseDate(item.publishTime), +8),
}));
return {
// 源标题
title: '值得一读技术博客',
// 源链接
link: 'https://daily-blog.chlinlearn.top/blogs/1',
// 源文章
item: items,
};
},
};
6 changes: 6 additions & 0 deletions lib/routes/chlinlearn/namespcae.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'chlinlearn的技术博客',
url: 'daily-blog.chlinlearn.top',
};
2 changes: 1 addition & 1 deletion lib/routes/dongqiudi/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ async function handler(ctx) {
return {
title: `${teamName} 比赛结果`,
link,
item: out.slice(-10, out.length),
item: out.slice(-10),
};
}
46 changes: 46 additions & 0 deletions lib/routes/inspirehep/author.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { AuthorResponse, LiteratureResponse } from './types';
import cache from '@/utils/cache';

import { baseUrl, parseLiterature } from './utils';

export const route: Route = {
path: '/authors/:id',
example: '/inspirehep/authors/1696909',
parameters: { id: 'Author ID' },
name: 'Author Search',
maintainers: ['TonyRL'],
radar: [
{
source: ['inspirehep.net/authors/:id'],
},
],
handler,
};

export const getAuthorById = (id: string) => cache.tryGet(`inspirehep:author:${id}`, () => ofetch<AuthorResponse>(`${baseUrl}/api/authors/${id}`));

async function handler(ctx) {
const id = ctx.req.param('id');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25;

const authorInfo = (await getAuthorById(id)) as AuthorResponse;
const response = await ofetch<LiteratureResponse>(`${baseUrl}/api/literature`, {
query: {
sort: 'mostrecent',
size: limit,
page: 1,
search_type: 'hep-author-publication',
author: authorInfo.metadata.facet_author_name,
},
});

const items = parseLiterature(response.hits.hits);

return {
title: `${authorInfo.metadata.name.preferred_name} - INSPIRE`,
link: `${baseUrl}/authors/${id}`,
item: items,
};
}
42 changes: 42 additions & 0 deletions lib/routes/inspirehep/literature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { LiteratureResponse } from './types';

import { baseUrl, parseLiterature } from './utils';

export const route: Route = {
path: '/literature/:q',
example: '/inspirehep/literature/Physics',
parameters: { q: 'Search keyword' },
name: 'Literature Search',
maintainers: ['TonyRL'],
radar: [
{
source: ['inspirehep.net/literature'],
target: (_params, url) => `/inspirehep/literature/${new URL(url).searchParams.get('q')}`,
},
],
handler,
};

async function handler(ctx) {
const q = ctx.req.param('q');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 25;

const response = await ofetch<LiteratureResponse>(`${baseUrl}/api/literature`, {
query: {
sort: 'mostrecent',
size: limit,
page: 1,
q,
},
});

const items = parseLiterature(response.hits.hits);

return {
title: 'Literature Search - INSPIRE',
link: `${baseUrl}/literature?sort=mostrecent&size=${limit}&page=1&q=${q}`,
item: items,
};
}
7 changes: 7 additions & 0 deletions lib/routes/inspirehep/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: 'INSPIRE',
url: 'inspirehep.net',
categories: ['journal'],
};
Loading

0 comments on commit 74a74e4

Please sign in to comment.