fix(itch): incorrect devlog authors (#20073)

* fix(itch): devlog authors

* selector
This commit is contained in:
Keo 2025-09-16 23:40:02 +08:00 committed by GitHub
parent 2f92886dae
commit ae1f40e0ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 3 deletions

View File

@ -36,6 +36,7 @@ export const route: Route = {
async function handler(ctx) {
const user = ctx.req.param('user') ?? '';
const id = ctx.req.param('id') ?? '';
const limit = Number.parseInt(ctx.req.query('limit')) || 20;
if (!isValidHost(user)) {
throw new InvalidParameterError('Invalid user');
}
@ -51,6 +52,7 @@ async function handler(ctx) {
let items = $('.title')
.toArray()
.slice(0, limit)
.map((item) => {
item = $(item);
@ -71,12 +73,14 @@ async function handler(ctx) {
const content = load(detailResponse.data);
item.author = detailResponse.data.match(/"author":{".*?","name":"(.*?)"/)[1];
item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*?)"/)[1]);
const infoJson = content('script[type="application/ld+json"]:contains("@type":"BlogPosting")');
const info = JSON.parse(content(infoJson).text());
item.author = info.author.name;
item.pubDate = info.datePublished;
item.description = art(path.join(__dirname, 'templates/description.art'), {
images: content('.post_image')
.toArray()
.map((i) => content(i).attr('src')),
.map((e) => content(e).attr('src')),
description: content('.post_body').html(),
});