aboutsummaryrefslogtreecommitdiff
path: root/src/routes/updates/+page.svelte
blob: 26af53bc933272cd28232805c0e8ac4792af9411 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script lang="ts">
	import { browser } from '$app/environment';
	import { onMount } from 'svelte';

	type Feed = { items: { title: string; link: string; content: string }[] } | null | undefined;

	let feed: Feed = undefined;
	let novelFeed: Feed = undefined;
	let startTime: number;
	let mangaEndTime: number;
	let novelEndTime: number;
	let directLink = browser ? new URLSearchParams(window.location.search).has('d') : false;

	onMount(async () => {
		startTime = performance.now();
		novelFeed = await (await fetch('/api/novel-updates')).json();
		novelEndTime = performance.now() - startTime;
		startTime = performance.now();
		feed = await (await fetch('/api/manga-updates')).json();
		mangaEndTime = performance.now() - startTime;
	});

	const reformatChapter = (title: string) =>
		title
			.replace(/\[.*?\]\s/, '')
			.replace(/c\.Oneshot/, 'Oneshot')
			.replace(/c\.(\d+-\d+)/, 'Ch. $1')
			.replace(/v\.(\d+)\s/, 'Vol. $1 ')
			.replace(/c\.(\d+)/, 'Ch. $1');

	const clipTitle = (title: string): string =>
		title
			.replace(/(Vol\. \d+ )?Ch\. \d+(-\d+(\.\d+)?)?$/, '')
			.replace(/\? ~.*$/, '')
			.trim();

	const italicTitle = (title: string) => title.replace(/^(.*?) Ch\.|\bOneshot\b/, '<i>$1</i> Ch.');
</script>

<div id="list-container">
	<div>
		<details open>
			<summary>
				Manga
				<small style="opacity: 50%">{(mangaEndTime || 0) / 1000}s</small>
			</summary>

			<ul>
				{#if feed === null}
					<li>Failed to load feed</li>
				{:else if feed !== undefined}
					{#each feed.items as item}
						<li>
							{#if directLink}
								<i>{reformatChapter(item.title)}</i>

								{@html item.content}
							{:else}
								<a
									href={`https://anilist.co/search/manga?search=${clipTitle(
										reformatChapter(item.title)
									)}&sort=SEARCH_MATCH`}
								>
									{@html italicTitle(reformatChapter(item.title))}
								</a>
							{/if}
						</li>
					{/each}
				{:else}
					<li>Loading ...</li>
				{/if}
			</ul>
		</details>
	</div>

	<div>
		<details open>
			<summary>
				Light Novels
				<small style="opacity: 50%">{(novelEndTime || 0) / 1000}s</small>
			</summary>

			<ul>
				{#if novelFeed === null}
					<li>Failed to load feed</li>
				{:else if novelFeed !== undefined}
					{#each novelFeed.items as item}
						<li>
							<a href={item.link}>
								{reformatChapter(item.title)}
							</a>
						</li>
					{/each}
				{:else}
					<li>Loading ...</li>
				{/if}
			</ul>
		</details>
	</div>
</div>

<style>
	#list-container {
		display: grid;
		grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
	}
</style>