starshard/peafowl
Template
1
Fork 0
mirror of https://github.com/starshardstudio/peafowl.git synced 2024-11-21 20:44:19 +00:00
peafowl/_includes/index.tsx

243 lines
7 KiB
TypeScript
Raw Permalink Normal View History

2024-11-05 12:46:02 +00:00
import { compareDate } from "../_utils/date.ts";
2024-06-16 11:49:13 +00:00
import { GameData } from "../_utils/game.ts";
2024-11-05 12:46:02 +00:00
import { GameTable } from "../_components/GameTable.tsx";
import { compareGameProgress } from "../_utils/game.ts";
import { GlobalData } from "../_utils/site.ts";
2024-11-05 12:51:18 +00:00
import { AnimeTable } from "../_components/AnimeTable.tsx";
import { AnimeData } from "../_utils/anime.ts";
2024-06-16 11:49:13 +00:00
2024-11-05 12:46:02 +00:00
export const layout = "base.tsx";
2024-06-16 11:49:13 +00:00
2024-11-05 12:46:02 +00:00
export default function (data: GlobalData, helpers: Lume.Helpers) {
const intro_section = data.content
? (
<section id={"index-section-intro"}>
{data.children}
</section>
)
: null;
2024-06-16 11:49:13 +00:00
2024-11-05 12:46:02 +00:00
const games: GameData[] = data.search.pages("game");
2024-06-16 11:49:13 +00:00
const active_games = games
2024-11-05 12:46:02 +00:00
.filter((game) => game.active)
.sort(compareDate as any);
2024-06-16 11:49:13 +00:00
const active_games_section = (
<section id={"index-section-games-active"} className={"flex flex-v"}>
<h3>
Now playing
</h3>
<div>
2024-11-05 12:46:02 +00:00
<GameTable
games={active_games}
columns={["progress", "name", "hoursplayed", "date"]}
priority={"progress"}
/>
2024-06-16 11:49:13 +00:00
</div>
</section>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
const top_games = games
.sort((a, b) => ((b.rating ?? 0) - (a.rating ?? 0)))
2024-11-05 12:46:02 +00:00
.slice(0, 10);
2024-06-16 11:49:13 +00:00
const top_games_section = (
<section id={"index-section-games-top"} className={"flex flex-v"}>
<h3>
Top games
</h3>
<div>
2024-11-05 12:46:02 +00:00
<GameTable
games={top_games}
columns={["rating", "name", "hascontent"]}
priority={"rating"}
/>
2024-06-16 11:49:13 +00:00
</div>
</section>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
const played_games = games
.sort((a, b) => ((b.hours_played ?? 0) - (a.hours_played ?? 0)))
2024-11-05 12:46:02 +00:00
.slice(0, 10);
2024-06-16 11:49:13 +00:00
const played_games_section = (
<section id={"index-section-games-top"} className={"flex flex-v"}>
<h3>
Most played games
</h3>
<div>
2024-11-05 12:46:02 +00:00
<GameTable
games={played_games}
columns={["hoursplayed", "name"]}
/>
2024-06-16 11:49:13 +00:00
</div>
</section>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
const progress_games = games
2024-11-05 12:11:03 +00:00
.sort((a, b) => -compareGameProgress(a, b))
2024-11-05 12:46:02 +00:00
.slice(0, 10);
2024-06-16 11:49:13 +00:00
const progress_games_section = (
<section id={"index-section-games-top"} className={"flex flex-v"}>
<h3>
Most progressed games
</h3>
<div>
2024-11-05 12:46:02 +00:00
<GameTable
games={progress_games}
columns={["progress", "name", "hoursplayed"]}
priority={"progress"}
/>
2024-06-16 11:49:13 +00:00
</div>
</section>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
const latest_games = games
.sort((a, b) => -compareDate(a, b))
2024-11-05 12:46:02 +00:00
.slice(0, 10);
2024-06-16 11:49:13 +00:00
const latest_games_section = (
<section id={"index-section-games-latest"} className={"flex flex-v"}>
<h3>
Latest updates
</h3>
<div>
2024-11-05 12:46:02 +00:00
<GameTable
games={latest_games}
columns={["hascontent", "name", "date"]}
/>
2024-06-16 11:49:13 +00:00
</div>
</section>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
2024-07-07 02:45:11 +00:00
const games_cols = (
2024-11-05 12:46:02 +00:00
games.length > 0
)
? (
<section className={"flex flex-v"}>
<h2>
Videogames
<small>
<a href={helpers.url("~/list-games.md")}>
<i
className={"fa-sharp fa-solid fa-magnifying-glass"}
/>{" "}
View all
</a>
</small>
</h2>
{active_games.length > 0 && (
<div className={"flex flex-1"}>
{active_games_section}
</div>
)}
<div className={"flex flex-2"}>
{top_games_section}
{progress_games_section}
2024-06-16 11:49:13 +00:00
</div>
2024-11-05 12:46:02 +00:00
<div className={"flex flex-2"}>
{played_games_section}
{latest_games_section}
</div>
</section>
)
: null;
2024-06-16 11:49:13 +00:00
2024-11-05 12:51:18 +00:00
const anime: AnimeData[] = data.search.pages("anime");
const active_anime = anime
.filter((ani) => ani.active)
.sort(compareDate as any);
const active_anime_section = (
<section id={"index-section-anime-active"} className={"flex flex-v"}>
<h3>
Now playing
</h3>
<div>
<AnimeTable
anime={active_anime}
columns={["progress", "name", "date"]}
priority={"progress"}
/>
</div>
</section>
);
const top_anime = anime
.sort((a, b) => ((b.rating ?? 0) - (a.rating ?? 0)))
.slice(0, 10);
const top_anime_section = (
<section id={"index-section-anime-top"} className={"flex flex-v"}>
<h3>
Top anime
</h3>
<div>
<AnimeTable
anime={top_anime}
columns={["rating", "name", "hascontent"]}
priority={"rating"}
/>
</div>
</section>
);
const latest_anime = anime
.sort((a, b) => -compareDate(a, b))
.slice(0, 10);
const latest_anime_section = (
<section id={"index-section-anime-latest"} className={"flex flex-v"}>
<h3>
Latest updates
</h3>
<div>
<AnimeTable
anime={latest_anime}
columns={["hascontent", "name", "date"]}
/>
</div>
</section>
);
const anime_cols = (
anime.length > 0
)
? (
<section className={"flex flex-v"}>
<h2>
Anime
<small>
<a href={helpers.url("~/list-anime.md")}>
<i
className={"fa-sharp fa-solid fa-magnifying-glass"}
/>{" "}
View all
</a>
</small>
</h2>
{active_anime.length > 0 && (
<div className={"flex flex-1"}>
{active_anime_section}
</div>
)}
<div className={"flex flex-2"}>
{top_anime_section}
{latest_anime_section}
</div>
</section>
)
2024-11-05 13:00:54 +00:00
: null;
2024-11-05 12:51:18 +00:00
2024-06-16 11:49:13 +00:00
return (
<main id={"index-main"} className={"flex flex-v"}>
{intro_section}
{games_cols}
2024-11-05 13:00:54 +00:00
{anime_cols}
2024-06-16 11:49:13 +00:00
</main>
2024-11-05 12:46:02 +00:00
);
2024-06-16 11:49:13 +00:00
}