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(add route): Add steam curator reviews route #18044

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
73 changes: 73 additions & 0 deletions lib/routes/steam/curator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import { getCurrentPath } from '@/utils/helpers';
import path from 'node:path';
import { art } from '@/utils/render';

const __dirname = getCurrentPath(import.meta.url);

export const route: Route = {
path: '/curator/:id',
categories: ['game'],
example: '/steam/curator/34646096-80-Days',
parameters: {
id: "Steam curator id. It usually consists of a sereis of numbers and the curator's name.",
TonyRL marked this conversation as resolved.
Show resolved Hide resolved
},
radar: [
{
title: 'Latest Curator Reviews',
source: ['store.steampowered.com/curator/:id'],
target: '/curator/:id',
},
],
description: 'The Latest reviews from a Steam Curator.',
name: 'Latest Curator Reviews',
maintainers: ['naremloa', 'fenxer'],
handler: async (ctx) => {
const { id } = ctx.req.param();

const url = `https://store.steampowered.com/curator/${id}`;
const response = await ofetch(url);
const $ = load(response);
naremloa marked this conversation as resolved.
Show resolved Hide resolved

const items = await Promise.all(
naremloa marked this conversation as resolved.
Show resolved Hide resolved
$('#RecommendationsRows .recommendation')
.toArray()
.slice(0, 1)
naremloa marked this conversation as resolved.
Show resolved Hide resolved
.map((item) => {
const el = $(item);
const appTitle = el.find('img').attr('alt')!;
const appLink = el.find('.recommendation_link').first().attr('href');
const appImage = el.find('img').attr('src') ?? '';
const reviewContent = el.find('.recommendation_desc').text().trim();
const reviewDateText = el.find('.curator_review_date').text().trim();

const currentYearPattern = /,\s\b\d{4}\b$/;
const reviewPubDate = currentYearPattern.test(reviewDateText) ? parseDate(`${reviewDateText}, ${new Date().getFullYear()}`) : parseDate(reviewDateText);

const description = art(path.join(__dirname, 'templates/curator-description.art'), { image: appImage, description: reviewContent });

return {
title: appTitle,
link: appLink,
description,
pubDate: reviewPubDate,
media: {
content: {
url: appImage,
medium: 'image',
},
},
};
})
);

return {
title: `Steam Curator ${id} Reviews`,
link: url,
item: items,
};
},
};
4 changes: 4 additions & 0 deletions lib/routes/steam/templates/curator-description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ if image }}
<img src="{{ image }}"/>
{{ /if }}
<p>{{ description }}</p>
Loading