Skip to content

Commit

Permalink
feat(PDF): add page param (#360)
Browse files Browse the repository at this point in the history
* inject page params into iframe pdf

* fix(svelte): use reactivity instead of assignments

---------

Co-authored-by: Diebbo <[email protected]>
  • Loading branch information
VaiTon and Diebbo authored Jan 7, 2025
1 parent bf5daa9 commit 44f212c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/routes/[...dir]/[file=pdf]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
</script>

<svelte:head>
Expand All @@ -25,7 +41,7 @@

<Breadcrumbs url={$page.url} borderRadius={null} />

<iframe bind:this={iframe} title="Embedded resource" src={data.url} class="h-full w-full"></iframe>
<iframe bind:this={iframe} title="Embedded resource" src={iframeUrl} class="h-full w-full"></iframe>

<style>
:global(html),
Expand Down

0 comments on commit 44f212c

Please sign in to comment.