Skip to content

Commit

Permalink
feat(route): 新增 新芽网 (DIYgod#17841)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo authored Dec 17, 2024
1 parent 0e1762f commit 5b41734
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
73 changes: 73 additions & 0 deletions lib/routes/newseed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';

export const route: Route = {
path: '/latest',
categories: ['new-media'],
example: '/newseed/latest',
url: 'news.newseed.cn',
name: '最新新闻',
maintainers: ['p3psi-boo'],
handler,
};

async function handler() {
const baseUrl = 'https://news.newseed.cn/';
const response = await got({
method: 'get',
url: baseUrl,
});

const $ = load(response.data);

const list = $('#news-list li')
.toArray()
.map((item) => {
const element = $(item);
const a = element.find('h3 a');
const link = a.attr('href') || '';
const title = a.text();
const image = element.find('.img img').attr('src');
const info = element.find('.info');
const author = info.find('.author a').text();
const pubDate = info.find('.date').text();
const tags = element
.find('.tag a')
.toArray()
.map((el) => $(el).text())
.filter((tag) => tag !== author);

return {
title,
link,
author,
pubDate,
category: tags,
description: image ? `<img src="${image}"><br>${title}` : title,
};
});

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await got({
method: 'get',
url: item.link,
});

const $ = load(response.data);
item.description = $('.news-content').html() || item.description;
return item;
})
)
);

return {
title: '新芽 - 最新新闻',
link: baseUrl,
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/newseed/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '新芽',
url: 'newseed.cn',
description: '新芽是专注于互联网创业的媒体平台,提供创业资讯、投融资信息、创业活动、创业服务等。',
lang: 'zh-CN',
};

0 comments on commit 5b41734

Please sign in to comment.