diff options
| author | Fuwn <[email protected]> | 2024-10-09 00:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-09 00:41:43 -0700 |
| commit | 998b63a35256ac985a5a2714dd1ca451af4dfd8a (patch) | |
| tree | 50796121a9d5ab0330fdc5d7e098bda2860d9726 /src/routes/updates | |
| parent | feat(graphql): add badgeCount field (diff) | |
| download | due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.tar.xz due.moe-998b63a35256ac985a5a2714dd1ca451af4dfd8a.zip | |
chore(prettier): use spaces instead of tabs
Diffstat (limited to 'src/routes/updates')
| -rw-r--r-- | src/routes/updates/+page.svelte | 268 |
1 files changed, 134 insertions, 134 deletions
diff --git a/src/routes/updates/+page.svelte b/src/routes/updates/+page.svelte index 61ed9678..9af001b4 100644 --- a/src/routes/updates/+page.svelte +++ b/src/routes/updates/+page.svelte @@ -1,144 +1,144 @@ <script lang="ts"> - /* eslint svelte/no-at-html-tags: "off" */ - - import { browser } from '$app/environment'; - import HeadTitle from '$lib/Home/HeadTitle.svelte'; - import Skeleton from '$lib/Loading/Skeleton.svelte'; - import { createHeightObserver } from '$lib/Utility/html'; - import root from '$lib/Utility/root'; - import { onDestroy, onMount } from 'svelte'; - - let feed: { items: { title: string; link: string; content: string }[] } | null | undefined = - undefined; - let novelFeed: - | { - data: { - items: { srcurl: string; postfix?: string; chapter: number; series: { name: string } }[]; - }; - } - | undefined = undefined; - let startTime: number; - let mangaEndTime: number; - let novelEndTime: number; - let directLink = browser ? new URLSearchParams(window.location.search).has('d') : false; - let heightObserver: NodeJS.Timeout; - - onMount(async () => { - heightObserver = setInterval(() => createHeightObserver(false), 0); - - startTime = performance.now(); - novelFeed = await (await fetch(root('/api/updates/all-novels'))).json(); - novelEndTime = performance.now() - startTime; - startTime = performance.now(); - feed = await (await fetch(root('/api/updates/manga'))).json(); - mangaEndTime = performance.now() - startTime; - }); - - onDestroy(() => clearInterval(heightObserver)); - - 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) => - title - .replace(/(Vol\. \d+ )?Ch\. \d+(-\d+(\.\d+)?)?$/, '') - .replace(/\? ~.*$/, '') - .trim(); - - // const italicTitle = (title: string) => - // title.replace(/^(.*?) (Vol\.|Ch\.|\bOneshot\b)/, '<i>$1</i> $2'); - - const chapterTitle = (title: string) => title.replace(/^(.*?) (Vol\.|Ch\.|\bOneshot\b)/, '$2'); + /* eslint svelte/no-at-html-tags: "off" */ + + import { browser } from '$app/environment'; + import HeadTitle from '$lib/Home/HeadTitle.svelte'; + import Skeleton from '$lib/Loading/Skeleton.svelte'; + import { createHeightObserver } from '$lib/Utility/html'; + import root from '$lib/Utility/root'; + import { onDestroy, onMount } from 'svelte'; + + let feed: { items: { title: string; link: string; content: string }[] } | null | undefined = + undefined; + let novelFeed: + | { + data: { + items: { srcurl: string; postfix?: string; chapter: number; series: { name: string } }[]; + }; + } + | undefined = undefined; + let startTime: number; + let mangaEndTime: number; + let novelEndTime: number; + let directLink = browser ? new URLSearchParams(window.location.search).has('d') : false; + let heightObserver: NodeJS.Timeout; + + onMount(async () => { + heightObserver = setInterval(() => createHeightObserver(false), 0); + + startTime = performance.now(); + novelFeed = await (await fetch(root('/api/updates/all-novels'))).json(); + novelEndTime = performance.now() - startTime; + startTime = performance.now(); + feed = await (await fetch(root('/api/updates/manga'))).json(); + mangaEndTime = performance.now() - startTime; + }); + + onDestroy(() => clearInterval(heightObserver)); + + 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) => + title + .replace(/(Vol\. \d+ )?Ch\. \d+(-\d+(\.\d+)?)?$/, '') + .replace(/\? ~.*$/, '') + .trim(); + + // const italicTitle = (title: string) => + // title.replace(/^(.*?) (Vol\.|Ch\.|\bOneshot\b)/, '<i>$1</i> $2'); + + const chapterTitle = (title: string) => title.replace(/^(.*?) (Vol\.|Ch\.|\bOneshot\b)/, '$2'); </script> <HeadTitle route="Updates" path="/updates" /> <div class="list-container"> - <details open class="list"> - <summary> - Manga - <small class="opaque">{mangaEndTime ? mangaEndTime / 1000 : '...'}s</small> - </summary> - - {#if feed === null} - Failed to load feed - {:else if feed !== undefined} - <ul> - {#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`} - > - <i>{@html clipTitle(reformatChapter(item.title))}</i> - </a> - {@html chapterTitle(reformatChapter(item.title))} - {/if} - </li> - {/each} - </ul> - {:else} - <Skeleton card={false} count={5} height="0.9rem" list /> - {/if} - </details> - - <details open class="list"> - <summary> - Novels - <small class="opaque">{novelEndTime ? novelEndTime / 1000 : '...'}s</small> - </summary> - - {#if novelFeed === null} - Failed to load feed - {:else if novelFeed !== undefined} - <ul> - {#each novelFeed.data.items as item} - <li> - {#if directLink} - <a href={item.srcurl}> - <i>{@html item.series.name}</i> - {@html item.postfix || `Ch. ${item.chapter}`} - </a> - {:else} - <a - href={`https://anilist.co/search/manga?search=${item.series.name}&sort=SEARCH_MATCH`} - > - <i>{@html item.series.name}</i> - </a> - {@html item.postfix || `Ch. ${item.chapter}`} - {/if} - </li> - {/each} - </ul> - {:else} - <Skeleton card={false} count={5} height="0.9rem" list /> - {/if} - </details> + <details open class="list"> + <summary> + Manga + <small class="opaque">{mangaEndTime ? mangaEndTime / 1000 : '...'}s</small> + </summary> + + {#if feed === null} + Failed to load feed + {:else if feed !== undefined} + <ul> + {#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`} + > + <i>{@html clipTitle(reformatChapter(item.title))}</i> + </a> + {@html chapterTitle(reformatChapter(item.title))} + {/if} + </li> + {/each} + </ul> + {:else} + <Skeleton card={false} count={5} height="0.9rem" list /> + {/if} + </details> + + <details open class="list"> + <summary> + Novels + <small class="opaque">{novelEndTime ? novelEndTime / 1000 : '...'}s</small> + </summary> + + {#if novelFeed === null} + Failed to load feed + {:else if novelFeed !== undefined} + <ul> + {#each novelFeed.data.items as item} + <li> + {#if directLink} + <a href={item.srcurl}> + <i>{@html item.series.name}</i> + {@html item.postfix || `Ch. ${item.chapter}`} + </a> + {:else} + <a + href={`https://anilist.co/search/manga?search=${item.series.name}&sort=SEARCH_MATCH`} + > + <i>{@html item.series.name}</i> + </a> + {@html item.postfix || `Ch. ${item.chapter}`} + {/if} + </li> + {/each} + </ul> + {:else} + <Skeleton card={false} count={5} height="0.9rem" list /> + {/if} + </details> </div> <style> - .list-container { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); - align-items: start; - gap: 1em; - flex-wrap: wrap; - } - - .list { - overflow-y: auto; - min-width: 300px; - flex: 1 1 300px; - } + .list-container { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); + align-items: start; + gap: 1em; + flex-wrap: wrap; + } + + .list { + overflow-y: auto; + min-width: 300px; + flex: 1 1 300px; + } </style> |