Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routes/ceph): add ceph blog #16980

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions lib/routes/ceph/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,45 @@ export const route: Route = {
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 link = element.find('a').attr('href');
const pubDate = parseDate(element.find('time').attr('datetime'));
return await cache.tryGet(
url,
async () => {
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,
};
});

return {
title,
link: 'https://ceph.io/' + link,
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);

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;
})
)
);

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,
};
},
3600
pandada8 marked this conversation as resolved.
Show resolved Hide resolved
);

return {
title: 'Ceph Blog',
link: url,
item: result,
};
}