Skip to content

Commit 2eb14e4

Browse files
committed
fix: resolved loading annotation pdfs with spaces
1 parent 14bc1ff commit 2eb14e4

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

content/utils/download-annotation-pdfs.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ async function downloadPDF(url, outputPath) {
3434
function getFilenameFromUrl(url) {
3535
const urlObj = new URL(url)
3636
const pathname = urlObj.pathname
37-
const filename = decodeURIComponent(path.basename(pathname))
37+
let filename = decodeURIComponent(path.basename(pathname))
38+
39+
// Sanitize filename: replace spaces and problematic characters with hyphens
40+
filename = filename.replace(/[\s]+/g, '-')
3841

3942
// Ensure it has .pdf extension
4043
if (!filename.toLowerCase().endsWith('.pdf')) {

quartz/components/AnnotationViewer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export default ((userOpts?: Partial<AnnotationViewerOptions>) => {
9696
const getLocalPdfPath = (url: string): string => {
9797
try {
9898
const urlObj = new URL(url)
99-
const filename = decodeURIComponent(urlObj.pathname.split('/').pop() || 'document.pdf')
99+
let filename = decodeURIComponent(urlObj.pathname.split('/').pop() || 'document.pdf')
100+
// Sanitize filename: replace spaces and problematic characters with hyphens
101+
filename = filename.replace(/[\s]+/g, '-')
100102
return `/assets/annotated-documents/${filename}`
101103
} catch {
102104
return url // Fallback to original URL if parsing fails

0 commit comments

Comments
 (0)