From 911842dc06f0e1b9351c17e47b9c59d3e116c101 Mon Sep 17 00:00:00 2001 From: Leopere Date: Sat, 10 May 2025 16:27:15 -0400 Subject: [PATCH] Fix CSP for PDF download button by moving to external script --- docker/resume/Caddyfile | 4 ++-- docker/resume/index.html | 21 +-------------------- docker/resume/pdf-download.js | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 docker/resume/pdf-download.js diff --git a/docker/resume/Caddyfile b/docker/resume/Caddyfile index 9f19f31..688f10b 100644 --- a/docker/resume/Caddyfile +++ b/docker/resume/Caddyfile @@ -29,7 +29,7 @@ colinknapp.com { Cache-Control "public, max-age=31536000, immutable" # CSP with hashes for scripts and styles - Content-Security-Policy "default-src 'none'; script-src 'self' 'sha256-ryQsJ+aghKKD/CeXgx8jtsnZT3Epp3EjIw8RyHIq544=' 'sha256-anTkUs/oFZJulKUMaMjZlwaALEmPOP8op0psAo5Bhh8='; style-src 'self' 'sha256-Mo+7o3oPEKpX7fqRvTtunvQHlIDhJ0SxAMG1PCNniCI='; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none';" + Content-Security-Policy "default-src 'none'; script-src 'self' 'sha256-ryQsJ+aghKKD/CeXgx8jtsnZT3Epp3EjIw8RyHIq544=' 'sha256-anTkUs/oFZJulKUMaMjZlwaALEmPOP8op0psAo5Bhh8=' 'sha256-BASkmAmg7eoYCMd6odA6kQ8yGsFnoxaX48WbQvMkehs='; style-src 'self' 'sha256-Mo+7o3oPEKpX7fqRvTtunvQHlIDhJ0SxAMG1PCNniCI='; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none';" } # Handle 404s @@ -79,7 +79,7 @@ colinknapp.com { Cache-Control "public, max-age=31536000, immutable" # CSP with hashes for scripts and styles - Content-Security-Policy "default-src 'none'; script-src 'self' 'sha256-ryQsJ+aghKKD/CeXgx8jtsnZT3Epp3EjIw8RyHIq544=' 'sha256-anTkUs/oFZJulKUMaMjZlwaALEmPOP8op0psAo5Bhh8='; style-src 'self' 'sha256-Mo+7o3oPEKpX7fqRvTtunvQHlIDhJ0SxAMG1PCNniCI='; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none';" + Content-Security-Policy "default-src 'none'; script-src 'self' 'sha256-ryQsJ+aghKKD/CeXgx8jtsnZT3Epp3EjIw8RyHIq544=' 'sha256-anTkUs/oFZJulKUMaMjZlwaALEmPOP8op0psAo5Bhh8=' 'sha256-BASkmAmg7eoYCMd6odA6kQ8yGsFnoxaX48WbQvMkehs='; style-src 'self' 'sha256-Mo+7o3oPEKpX7fqRvTtunvQHlIDhJ0SxAMG1PCNniCI='; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none';" } # Handle 404s diff --git a/docker/resume/index.html b/docker/resume/index.html index c1b630d..f5102b6 100644 --- a/docker/resume/index.html +++ b/docker/resume/index.html @@ -7,6 +7,7 @@ Colin Knapp Portfolio +
@@ -23,7 +24,6 @@ aria-label="Download as PDF" title="Download resume as PDF" tabindex="0" - onclick="downloadAsPDF()" >📄
@@ -202,24 +202,5 @@

Accessibility: This website is designed and developed to meet WCAG 2.1 Level AAA standards, ensuring the highest level of accessibility for all users. Features include high contrast ratios, keyboard navigation, screen reader compatibility, and responsive design. The site supports both light and dark modes with automatic system preference detection.

- \ No newline at end of file diff --git a/docker/resume/pdf-download.js b/docker/resume/pdf-download.js new file mode 100644 index 0000000..3e47b59 --- /dev/null +++ b/docker/resume/pdf-download.js @@ -0,0 +1,22 @@ +document.addEventListener('DOMContentLoaded', function() { + const downloadButton = document.getElementById('downloadPDF'); + if (downloadButton) { + downloadButton.addEventListener('click', function() { + // Store current theme + const currentTheme = document.body.getAttribute('data-theme'); + + // Force light theme for PDF + document.body.setAttribute('data-theme', 'light'); + + // Wait for theme change to apply + setTimeout(function() { + window.print(); + + // Restore original theme + setTimeout(function() { + document.body.setAttribute('data-theme', currentTheme); + }, 100); + }, 100); + }); + } +}); \ No newline at end of file