player filters! favourites! stats!
also, small fixes/improvements, new ryuji feature: "if in array", "if not in array"
This commit is contained in:
46
build.ts
46
build.ts
@@ -9,6 +9,10 @@ import _host_info from './host_info.json';
|
||||
interface Listing {
|
||||
name: string;
|
||||
type: "anime" | "manga" | "music";
|
||||
favourites: {
|
||||
listing: boolean; //whether to mark entire listing as favourite
|
||||
chapters: string[]; //favourite chapters
|
||||
}; //marked as not optional here, but in the actual host_info.json file, it is optional
|
||||
}
|
||||
|
||||
interface DirectoryVars {
|
||||
@@ -33,10 +37,23 @@ interface MangaVars {
|
||||
prev_chapter?: string | boolean;
|
||||
}
|
||||
|
||||
const listings: Listing[] = _host_info.listings.filter((listing: any): listing is Listing => typeof listing.name === "string" && (listing?.type === "anime" || listing?.type === "manga" || listing?.type === "music"));
|
||||
const listings: Listing[] = _host_info.listings.map(
|
||||
(listing: any) =>
|
||||
//add empty "favourites" if not present in the json
|
||||
listing.favourites ? listing : {
|
||||
...listing,
|
||||
favourites: {
|
||||
listing: false,
|
||||
chapters: []
|
||||
}
|
||||
}
|
||||
).filter(
|
||||
(listing: any): listing is Listing =>
|
||||
typeof listing.name === "string" && (listing?.type === "anime" || listing?.type === "manga" || listing?.type === "music")
|
||||
);
|
||||
|
||||
let renderer: Renderer = new Renderer("templates", "components");
|
||||
let builder: Builder = new Builder("/build");;
|
||||
let builder: Builder = new Builder("/build");
|
||||
|
||||
//static page
|
||||
builder.serve_static_folder("static");
|
||||
@@ -60,6 +77,7 @@ let music_serve_paths: string[] = [];
|
||||
let music_vars: MusicVars[] = [];
|
||||
|
||||
let songs: string[] = [];
|
||||
let manga_pages_count: number = 0;
|
||||
|
||||
for (let i = 0; i < listings.length; i++) {
|
||||
const listing: Listing = listings[i];
|
||||
@@ -85,6 +103,7 @@ for (let i = 0; i < listings.length; i++) {
|
||||
const chapter: string = chapters[j];
|
||||
manga_serve_paths.push(`/${listing.type}/${listing.name}/${chapter}`);
|
||||
const images: string[] = readdirSync(path.join(__dirname, `/static_assets/${listing.type}_assets/${listing.name}/${chapter}`), { withFileTypes: true }).map((d) => d.name);
|
||||
manga_pages_count += images.length;
|
||||
manga_vars.push({
|
||||
listing,
|
||||
chapter,
|
||||
@@ -113,13 +132,34 @@ builder.serve_templates(renderer, anime_serve_paths, "anime", anime_vars);
|
||||
builder.serve_templates(renderer, manga_serve_paths, "manga", manga_vars);
|
||||
builder.serve_templates(renderer, music_serve_paths, "music", music_vars);
|
||||
|
||||
builder.serve_template(renderer, "/stats", "stats", {
|
||||
manga_series_count: listings.filter((l) => l.type === "manga").length,
|
||||
manga_chapters_count: manga_serve_paths.length,
|
||||
manga_pages_count,
|
||||
anime_series_count: listings.filter((l) => l.type === "anime").length,
|
||||
anime_episodes_count: anime_serve_paths.length,
|
||||
artists_count: listings.filter((l) => l.type === "music").length,
|
||||
songs_count: songs.length,
|
||||
});
|
||||
|
||||
builder.serve_template(renderer, "/player", "player", {
|
||||
songs,
|
||||
artists: listings.filter((l) => l.type === "music").map(
|
||||
(l) => (
|
||||
{
|
||||
name: l.name,
|
||||
songs: songs.filter((s) => s.startsWith(`${l.name}/`)).map((song) => song.slice(`${l.name}/`.length)),
|
||||
sanitized_name: l.name.replaceAll("\"", "\\\""),
|
||||
songs: songs.filter((s) => s.startsWith(`${l.name}/`)).map(
|
||||
(song) => (
|
||||
{
|
||||
name: song.slice(`${l.name}/`.length),
|
||||
//I don't think " can be in file names... but just in case
|
||||
sanitized_name: song.slice(`${l.name}/`.length).replaceAll("\"", "\\\""),
|
||||
favourite: l.favourites.chapters.includes(song.slice(`${l.name}/`.length)),
|
||||
}
|
||||
)
|
||||
),
|
||||
favourite: l.favourites.listing,
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user