Skip to content

Commit

Permalink
fix(svelte): use reactivity instead of assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon committed Dec 9, 2024
1 parent 3532acc commit d899f37
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/routes/[...dir]/[file=pdf]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
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);
if ($page.url.searchParams.has('page')) {
data.url += `#page=${$page.url.searchParams.get('page')}`;
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)
if (!isNaN(Number(pageParam))) {
baseUrl += `#page=${pageParam}`;
}
}
return baseUrl;
}
$: iframeUrl = genIframeUrl(data.url);
</script>

<svelte:head>
Expand All @@ -29,7 +40,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 d899f37

Please sign in to comment.