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,7 +3,7 @@ import Layout from '../../layouts/Layout.astro';
import ComicCard from '../../components/ComicCard.astro';
import LanguageSelector from '../../components/LanguageSelector.astro';
import RSSLink from '../../components/RSSLink.astro';
import { fetchComics, isValidLanguage, isValidContentType } from '../../lib/api';
import { fetchComics, isValidLanguage, isValidContentType, fetchGenres } from '../../lib/api';
import type { Comic } from '../../lib/types';
export async function getStaticPaths() {
@ -25,6 +25,7 @@ if (!isValidLanguage(lang!) || !isValidContentType(type!)) {
let comics: Comic[] = [];
let error: string | null = null;
const genres = await fetchGenres();
try {
comics = await fetchComics(lang, type);
@ -52,7 +53,7 @@ try {
{comics.length > 0 ? (
<div class="comics-grid">
{comics.map(comic => (
<ComicCard comic={comic} />
<ComicCard comic={comic} genres={genres} />
))}
</div>
) : (

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