forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
4 changed files
with
109 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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插排)评测、拆解的专业机构。', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.