Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): 新增 多知网-行业洞察 #17844

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/routes/duozhi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/industry/insight',
categories: ['new-media'],
example: '/duozhi/industry/insight/',
url: 'www.duozhi.com/industry/insight/',
name: '行业洞察',
maintainers: ['p3psi-boo'],
handler,
};

async function handler() {
const baseUrl = 'http://www.duozhi.com';
const response = await got({
method: 'get',
url: `${baseUrl}/industry/insight/`,
});

const $ = load(response.data);
const list = $('.post-item')
.toArray()
.map((_, item) => {
const $item = $(item);
const $link = $item.find('.post-title').first();
const $desc = $item.find('.post-desc').first();
const $author = $item.find('.post-attr').first();
const $date = $item.find('.post-attr').last();

return {
title: $link.text().trim(),
link: new URL($link.attr('href') || '', baseUrl).href,
description: $desc.text().trim(),
author: $author.text().trim().split('  ')[0],
pubDate: parseDate($date.text().split('|')[0].trim()),
};
});

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 = $('.subject-content').html() || item.description;
return item;
})
)
);

return {
title: '多知网 - 行业洞察',
link: `${baseUrl}/industry/insight/`,
item: items,
};
}
8 changes: 8 additions & 0 deletions lib/routes/duozhi/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: 'duozhi.com',
description: '',
lang: 'zh-CN',
};
Loading