add genre tags

This commit is contained in:
ld3zian 2025-01-15 15:50:26 -07:00
parent 6079bd3b97
commit a8b95aa752
4 changed files with 145 additions and 35 deletions

View file

@ -3,6 +3,8 @@ import {
fetchComics,
isValidLanguage,
isValidContentType,
fetchGenres,
getGenreNames,
} from "../../../lib/api";
import type { APIRoute } from "astro";
@ -13,28 +15,38 @@ export const GET: APIRoute = async ({ params, request }) => {
return new Response("Invalid language or content type", { status: 400 });
}
const comics = await fetchComics(lang, type);
const [comics, genres] = await Promise.all([
fetchComics(lang, type),
fetchGenres(),
]);
const siteURL = new URL(request.url).origin;
return rss({
title: `ComicK - ${lang.toUpperCase()} ${type.toUpperCase()}`,
description: `A simple RSS feed for ComicK!`,
site: "https://github.com/ld3z/manga-rss",
items: comics.map((comic) => ({
title: `${comic.md_comics.title} - Chapter ${comic.chap}`,
link: `https://comick.io/comic/${comic.md_comics.slug}`,
pubDate: new Date(comic.updated_at),
description: `Chapter ${comic.chap} of ${
comic.md_comics.title
} is now available on ComicK!
${
comic.md_comics.md_covers[0]
? `<img src="https://meo.comick.pictures/${comic.md_comics.md_covers[0].b2key}"
alt="Cover" style="max-width: 300px;" />`
: ""
}
`,
})),
items: comics.map((comic) => {
const genreNames = getGenreNames(comic.md_comics.genres, genres);
const genresHtml = genreNames.length > 0
? `<p>Genres: ${genreNames.join(', ')}</p>`
: '';
return {
title: `${comic.md_comics.title} - Chapter ${comic.chap}`,
link: `https://comick.io/comic/${comic.md_comics.slug}`,
pubDate: new Date(comic.updated_at),
description: `Chapter ${comic.chap} of ${comic.md_comics.title} is now available on ComicK!
${genresHtml}
${
comic.md_comics.md_covers[0]
? `<img src="https://meo.comick.pictures/${comic.md_comics.md_covers[0].b2key}"
alt="Cover" style="max-width: 300px;" />`
: ""
}
`,
};
}),
});
};
@ -58,6 +70,5 @@ export function getStaticPaths() {
{ params: { lang: "zh", type: "nsfw" } },
{ params: { lang: "sv", type: "sfw" } },
{ params: { lang: "sv", type: "nsfw" } },
// Add other combinations as needed
];
}
}