Skip to content

Commit ece1fe2

Browse files
authored
Merge pull request #14 from rudi-q/feature/seo-optimization
feat: implement route-based PDF handling with dedicated upload and vi…
2 parents f25dc24 + 25cb7f5 commit ece1fe2

File tree

10 files changed

+1794
-51
lines changed

10 files changed

+1794
-51
lines changed

src/app.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ declare global {
88
// interface PageState {}
99
// interface Platform {}
1010
}
11+
12+
// Extend Window interface for our custom cleanup properties
13+
interface Window {
14+
__pdfRouteCleanup?: {
15+
unlistenFileOpened: Promise<() => void>;
16+
unlistenStartupReady: Promise<() => void>;
17+
unlistenDebug: Promise<() => void>;
18+
};
19+
__pdfUploadCleanup?: {
20+
unlistenFileOpened: Promise<() => void>;
21+
unlistenStartupReady: Promise<() => void>;
22+
unlistenDebug: Promise<() => void>;
23+
};
24+
}
1125
}
1226

1327
// Declare .svelte modules for TypeScript

src/app.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<!-- Favicon and Icons -->
77
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
88
<link rel="apple-touch-icon" href="%sveltekit.assets%/logo.png" />
9-
<link rel="mask-icon" href="%sveltekit.assets%/logo.svg" color="#8B9474" />
109

1110
<!-- Viewport and Mobile -->
1211
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />

src/routes/+page.svelte

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
let maxFileLoadingAttempts = 10;
4242
let fileLoadingTimer: number | null = null;
4343
44-
// Check for PDF URL parameter reactively
44+
// Redirect from /?pdf=URL to /pdf/URL for better URL structure
4545
$: if (browser && $page && $page.url) {
4646
const pdfUrl = $page.url.searchParams.get('pdf');
47-
if (pdfUrl && !currentFile) {
48-
console.log('[PDF URL] Found PDF parameter:', pdfUrl);
49-
handlePdfUrlLoad(pdfUrl);
47+
if (pdfUrl) {
48+
console.log('[PDF URL] Redirecting to new URL structure:', pdfUrl);
49+
const encodedUrl = encodeURIComponent(pdfUrl);
50+
goto(`/pdf/${encodedUrl}`);
5051
}
5152
}
5253
@@ -67,13 +68,22 @@
6768
return;
6869
}
6970
70-
console.log('Setting currentFile and hiding welcome');
71-
currentFile = file;
72-
showWelcome = false;
73-
74-
// Set current PDF for auto-save functionality
75-
setCurrentPDF(file.name, file.size);
76-
console.log('Updated state:', { currentFile: !!currentFile, showWelcome });
71+
console.log('Storing file and navigating to pdf-upload route');
72+
// Store file in sessionStorage temporarily
73+
const fileReader = new FileReader();
74+
fileReader.onload = (e) => {
75+
const arrayBuffer = e.target?.result as ArrayBuffer;
76+
const fileData = {
77+
name: file.name,
78+
size: file.size,
79+
type: file.type,
80+
data: Array.from(new Uint8Array(arrayBuffer)) // Convert to array for JSON storage
81+
};
82+
sessionStorage.setItem('tempPdfFile', JSON.stringify(fileData));
83+
console.log('File stored in sessionStorage, navigating...');
84+
goto('/pdf-upload');
85+
};
86+
fileReader.readAsArrayBuffer(file);
7787
}
7888
7989
function isValidPdfUrl(url: string): boolean {
@@ -644,8 +654,8 @@
644654
return;
645655
}
646656
647-
// Navigate to the same page with the PDF parameter
648-
goto(`/?pdf=${encodeURIComponent(trimmedUrl)}`);
657+
// Navigate to the new PDF route structure
658+
goto(`/pdf/${encodeURIComponent(trimmedUrl)}`);
649659
}
650660
651661
function handleUrlCancel() {
@@ -670,13 +680,18 @@
670680
const blankPdfFile = await createBlankPDF();
671681
console.log('Blank PDF created:', blankPdfFile.name, blankPdfFile.size, 'bytes');
672682
673-
// Load the blank PDF just like a regular file
674-
currentFile = blankPdfFile;
675-
showWelcome = false;
676-
677-
// Set current PDF for auto-save functionality
678-
setCurrentPDF(blankPdfFile.name, blankPdfFile.size);
679-
console.log('Blank PDF loaded successfully!');
683+
console.log('Storing blank PDF and navigating to pdf-upload route');
684+
// Store file in sessionStorage temporarily
685+
const arrayBuffer = await blankPdfFile.arrayBuffer();
686+
const fileData = {
687+
name: blankPdfFile.name,
688+
size: blankPdfFile.size,
689+
type: blankPdfFile.type,
690+
data: Array.from(new Uint8Array(arrayBuffer))
691+
};
692+
sessionStorage.setItem('tempPdfFile', JSON.stringify(fileData));
693+
console.log('Blank PDF stored in sessionStorage, navigating...');
694+
goto('/pdf-upload');
680695
} catch (error) {
681696
console.error('Failed to create blank PDF:', error);
682697
alert('Failed to create blank PDF. Please try again.');

src/routes/pdf-upload/+page.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Disable prerendering for this route since it handles dynamic user-uploaded files
2+
// and depends on sessionStorage data that's only available at runtime
3+
export const prerender = false;

0 commit comments

Comments
 (0)