Skip to content

Commit

Permalink
Merge pull request #671 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Dec 12, 2024
2 parents fc6b4ea + 2a90282 commit d5a8580
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 46 deletions.
54 changes: 54 additions & 0 deletions lib/routes/chongdiantou/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Route } from '@/types';
import { namespace } from './namespace';
import ofetch from '@/utils/ofetch';
import logger from '@/utils/logger';

async function getPosts() {
try {
// Fetch data directly from the API without caching
const response = await ofetch('https://www.chongdiantou.com/wp-json/wp/v2/posts?_embed&per_page=10', {
headers: {
method: 'GET',
},
});
return response.map((post) => ({
title: post.title.rendered,
link: post.link,
pubDate: new Date(post.date_gmt), // Use date_gmt instead of date
category: post._embedded['wp:term'][0].map((term) => term.name).join(', '),
description: post.content.rendered,
author: post._embedded.author[0].name,
image: post._embedded['wp:featuredmedia'] ? post._embedded['wp:featuredmedia'][0].source_url : '',
}));
} catch (error) {
logger.error('Error fetching posts:', error);
return [];
}
}

export const route: Route = {
path: '/',
categories: namespace.categories,
example: '/chongdiantou',
radar: [
{
source: ['www.chongdiantou.com'],
},
],
name: '最新资讯',
maintainers: ['Geraldxm'],
handler,
url: 'www.chongdiantou.com',
};

async function handler() {
const items = await getPosts();

return {
title: '充电头网 - 最新资讯',
description: '充电头网新闻资讯',
link: 'https://www.chongdiantou.com/',
image: 'https://static.chongdiantou.com/wp-content/uploads/2021/02/2021021806172389.png',
item: items,
};
}
9 changes: 9 additions & 0 deletions lib/routes/chongdiantou/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '充电头网',
url: 'www.chongdiantou.com',
categories: ['new-media'],
lang: 'zh-CN',
description: '充电头网是国内最早进行消费类电源技术及其周边配件(快充、充电头、充电器、无线充、车充、车载充电器、数据线、充电线材、移动电源及电芯、USB插排)评测、拆解的专业机构。',
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"telegram": "2.26.8",
"tiny-async-pool": "2.1.0",
"title": "4.0.1",
"tldts": "6.1.66",
"tldts": "6.1.67",
"tosource": "2.0.0-alpha.3",
"tough-cookie": "5.0.0",
"tsx": "4.19.2",
Expand Down Expand Up @@ -161,7 +161,7 @@
"@types/mailparser": "3.4.5",
"@types/markdown-it": "14.1.2",
"@types/module-alias": "2.0.4",
"@types/node": "22.10.1",
"@types/node": "22.10.2",
"@types/sanitize-html": "2.13.0",
"@types/supertest": "6.0.2",
"@types/tiny-async-pool": "2.0.3",
Expand Down
88 changes: 44 additions & 44 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5a8580

Please sign in to comment.