From fe887b7b5e8105df5c806f51fcf5ce089911db68 Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Sat, 30 Dec 2023 06:26:53 +0000 Subject: [PATCH 1/2] fix: export HTML currently exports JS popups --- client/lib/exportHTML.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/lib/exportHTML.js b/client/lib/exportHTML.js index 1d00ccea5..4badcc10b 100644 --- a/client/lib/exportHTML.js +++ b/client/lib/exportHTML.js @@ -57,6 +57,9 @@ window.ExportHtml = Popup => { Array.from( document.querySelectorAll('#header-main-bar .board-header-btns'), ).forEach(elem => elem.remove()); + Array.from( + document.querySelectorAll('.js-pop-over, .pop-over'), + ).forEach(elem => elem.remove()); Array.from(document.querySelectorAll('.list-composer')).forEach(elem => elem.remove(), ); From 4d6e6a85e083b44774ca5e400763b6c9713bcd14 Mon Sep 17 00:00:00 2001 From: Lewis Cowles Date: Sat, 30 Dec 2023 06:41:10 +0000 Subject: [PATCH 2/2] feat: download webfonts as well Prior to this I was manually saving the fonts, and I don't remember documenting either. Now there should be no documentation needed. --- client/lib/exportHTML.js | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/client/lib/exportHTML.js b/client/lib/exportHTML.js index 4badcc10b..04b2c7892 100644 --- a/client/lib/exportHTML.js +++ b/client/lib/exportHTML.js @@ -155,6 +155,50 @@ window.ExportHtml = Popup => { ); }; + const getWebFonts = () => { + fontUrls = []; + + for (let sheet of document.styleSheets) { + // Get the base URL of the stylesheet + let baseUrl = sheet.href ? new URL(sheet.href).origin : window.location.origin; + + try { + for (let rule of sheet.cssRules) { + if (rule.type === CSSRule.FONT_FACE_RULE) { + let src = rule.style.getPropertyValue('src'); + let urlMatch = src.match(/url\(["']?(.+?)["']?\)/); + if (urlMatch) { + let fontUrl = urlMatch[1]; + + // Resolve the URL relative to the stylesheet's base URL + let resolvedUrl = new URL(fontUrl, baseUrl); + fontUrls.push(resolvedUrl.href); // Using .href to get the absolute URL + } + } + } + } catch (e) { + console.log('Access to stylesheet blocked:', e); + } + } + + return fontUrls; + }; + + const downloadFonts = async(elements, zip) => { + await asyncForEach(elements, async elem => { + const response = await fetch(elem); + const responseBody = await response.blob(); + const filename = elem.split('/') + .pop() + .split('?') + .shift() + .split('#') + .shift(); + const fileFullPath = `webfonts/${filename}`; + zip.file(fileFullPath, responseBody); + }); + } + const downloadCardCovers = async (elements, zip, boardSlug) => { await asyncForEach(elements, async elem => { const response = await fetch( @@ -197,6 +241,7 @@ window.ExportHtml = Popup => { await downloadStylesheets(getStylesheetList(), zip); await downloadSrcAttached(getSrcAttached(), zip, boardSlug); await downloadCardCovers(getCardCovers(), zip, boardSlug); + await downloadFonts(getWebFonts(), zip); addBoardHTMLToZip(boardSlug, zip);