From 44f212c4e0fca29cb00a6b73cb1ac27b3a49eae1 Mon Sep 17 00:00:00 2001 From: VaiTon Date: Tue, 7 Jan 2025 22:32:08 +0100 Subject: [PATCH] feat(PDF): add `page` param (#360) * inject page params into iframe pdf * fix(svelte): use reactivity instead of assignments --------- Co-authored-by: Diebbo --- src/routes/[...dir]/[file=pdf]/+page.svelte | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/routes/[...dir]/[file=pdf]/+page.svelte b/src/routes/[...dir]/[file=pdf]/+page.svelte index a80e652..04eed75 100644 --- a/src/routes/[...dir]/[file=pdf]/+page.svelte +++ b/src/routes/[...dir]/[file=pdf]/+page.svelte @@ -11,11 +11,27 @@ iframe.contentWindow?.focus(); // Focus the iframe }); - $: title = getTitle(data.url); - function getTitle(url: string) { + function genTitle(url: string) { const part = url.split('/'); return part[part.length - 1].split('?')[0]; } + $: title = genTitle(data.url); + + function genIframeUrl(baseUrl: string) { + const params = $page.url.searchParams; + + if (params.has('page')) { + const pageParam = params.get('page'); + // if page is a number, append it to the url (security) + const pageParamNumber = Number(pageParam); + if (!isNaN(pageParamNumber)) { + baseUrl += `#page=${pageParamNumber}`; + } + } + + return baseUrl; + } + $: iframeUrl = genIframeUrl(data.url); @@ -25,7 +41,7 @@ - +