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.
feat(routes/ceph): add ceph blog (DIYgod#16980)
* feat(routes/ceph): add ceph blog * Apply suggestions from code review Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix(route/ceph): add 1hour cache for index, fix url double slash * fix(route/ceph): remove unnecessary caching ---------
- Loading branch information
1 parent
f6c71d5
commit 8234e4a
Showing
2 changed files
with
79 additions
and
0 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,72 @@ | ||
import { Data, Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { Context } from 'hono'; | ||
|
||
export const route: Route = { | ||
path: '/blog/:topic?', | ||
categories: ['blog'], | ||
example: '/ceph/blog/a11y', | ||
parameters: { | ||
category: 'filter blog post by category, return all posts if not specified', | ||
}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['ceph.io/'], | ||
}, | ||
], | ||
name: 'Blog', | ||
maintainers: ['pandada8'], | ||
handler, | ||
url: 'ceph.io', | ||
}; | ||
|
||
async function handler(ctx: Context): Promise<Data> { | ||
const { category } = ctx.req.param(); | ||
const url = category ? `https://ceph.io/en/news/blog/category/${category}/` : 'https://ceph.io/en/news/blog/'; | ||
const response = await got.get(url); | ||
const data = response.data; | ||
const $ = load(data); | ||
const list = $('#main .section li') | ||
.toArray() | ||
.map((e) => { | ||
const element = $(e); | ||
const title = element.find('a').text().trim(); | ||
const pubDate = parseDate(element.find('time').attr('datetime')); | ||
return { | ||
title, | ||
link: new URL(element.find('a').attr('href'), 'https://ceph.io').href, | ||
pubDate, | ||
}; | ||
}); | ||
|
||
const result = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const itemReponse = await got.get(item.link); | ||
const data = itemReponse.data; | ||
const item$ = load(data); | ||
|
||
item.author = item$('#main section > div:nth-child(1) span').text().trim(); | ||
item.description = item$('#main section > div:nth-child(2) > div').html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: 'Ceph Blog', | ||
link: url, | ||
item: result, | ||
}; | ||
} |
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,7 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'Ceph', | ||
url: 'ceph.io', | ||
description: 'Ceph is an open source distributed storage system designed to evolve with data.', | ||
}; |