Skip to content

Commit

Permalink
feat(route): 新增多知网-行业洞察
Browse files Browse the repository at this point in the history
  • Loading branch information
p3psi-boo committed Dec 11, 2024
1 parent 17e2fc7 commit cc12a47
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
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',
};

0 comments on commit cc12a47

Please sign in to comment.