Skip to content

Commit

Permalink
fix(route/fortunechina): Fix (#16059)
Browse files Browse the repository at this point in the history
* fix(route/fortunechina): Fix

* Improve support for `jingxuan`

* Update index.ts

* Revert "Update index.ts"

This reverts commit 7684e44.

* .

* .

* .

* .
  • Loading branch information
dzx-dzx committed Jul 14, 2024
1 parent ab866df commit e051917
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions lib/routes/fortunechina/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate, parseRelativeDate } from '@/utils/parse-date';
import randUserAgent from '@/utils/rand-user-agent';

const UA = randUserAgent({ browser: 'mobile safari', os: 'ios', device: 'mobile' });

export const route: Route = {
path: '/:category?',
Expand Down Expand Up @@ -36,15 +39,12 @@ async function handler(ctx) {
const rootUrl = 'https://www.fortunechina.com';
const currentUrl = `${rootUrl}${category ? `/${category}` : ''}`;

const response = await got({
method: 'get',
url: currentUrl,
});
const response = await ofetch(currentUrl);

const $ = load(response.data);
const $ = load(response);

let items = $('.main')
.find('h3 a')
.find(category === '' ? 'a:has(h2)' : 'h2 a')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15)
.toArray()
.map((item) => {
Expand All @@ -61,14 +61,15 @@ async function handler(ctx) {
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
const detailResponse = await ofetch(item.link, {
headers: {
'User-Agent': UA,
}
});

const content = load(detailResponse.data);
const content = load(detailResponse);

const spans = content('.mod-info span').text();
const spans = content('.date').text();
let matches = spans.match(/(\d{4}-\d{2}-\d{2})/);
if (matches) {
item.pubDate = parseDate(matches[1]);
Expand All @@ -79,11 +80,22 @@ async function handler(ctx) {
}
}

item.author = content('.name').text();
item.author = content('.author').text();

content('.mod-info, .title, .eval-zan, .eval-pic, .sae-more, .ugo-kol, .word-text .word-box .word-cn').remove();

item.description = content('#articleContent, .eval-desc').html();
item.description = content(item.link.includes('content') ? '.contain .text' : '.contain .top').html();
if (item.link.includes('jingxuan')) {
item.description += content('.eval-mod_ugo').html();
}
else if (item.link.includes('events')) {
const eventDetails = await ofetch(`https://www.bagevent.com/event/${item.link.match(/\d+/)[0]}`);
const $event = load(eventDetails);
item.description = $event(".page_con").html();
}
else if (item.link.includes('zhuanlan')) {
item.description += content('.mod-word').html();
}

return item;
})
Expand Down

0 comments on commit e051917

Please sign in to comment.