From 19d9b74377ea86ca94f28fc8e163cce8a667f62f Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 12:02:34 +0300 Subject: [PATCH 01/12] Gracefully handle any hubspot form loading error and present an error message --- src/_includes/hubspot/hs-form.njk | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/_includes/hubspot/hs-form.njk b/src/_includes/hubspot/hs-form.njk index 32d727e0a3..1572522ddf 100644 --- a/src/_includes/hubspot/hs-form.njk +++ b/src/_includes/hubspot/hs-form.njk @@ -11,5 +11,23 @@ } }); } + function fallback() { + const targetScript = [...document.scripts].find( + s => s.src === 'https://js-eu1.hsforms.net/forms/embed/v2.js' || s.src === 'http://js-eu1.hsforms.net/forms/embed/v2.js' + ); + + if (targetScript && targetScript.parentNode) { + const errorSection = document.createElement('section'); + errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white'); + errorSection.innerHTML = ` +

Hmm… there was supposed to be a form here.

+

+ If you’re using strict privacy settings or navigating in private mode, it might be blocked. + Try adjusting your settings or switching browsers to continue. +

+ `; + targetScript.parentNode.insertBefore(errorSection, targetScript.nextSibling); + } + } - \ No newline at end of file + From 7288b0bec2812e7542fb193d8668e30aae6603ba Mon Sep 17 00:00:00 2001 From: Costin Serban Date: Fri, 9 May 2025 12:04:41 +0300 Subject: [PATCH 02/12] Update src/_includes/hubspot/hs-form.njk Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/_includes/hubspot/hs-form.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/hubspot/hs-form.njk b/src/_includes/hubspot/hs-form.njk index 1572522ddf..6672c7c502 100644 --- a/src/_includes/hubspot/hs-form.njk +++ b/src/_includes/hubspot/hs-form.njk @@ -13,7 +13,7 @@ } function fallback() { const targetScript = [...document.scripts].find( - s => s.src === 'https://js-eu1.hsforms.net/forms/embed/v2.js' || s.src === 'http://js-eu1.hsforms.net/forms/embed/v2.js' + s => s.src.includes('js-eu1.hsforms.net/forms/embed/v2.js') ); if (targetScript && targetScript.parentNode) { From 1941fbd4264dec09c9884ea49346b99a250529ce Mon Sep 17 00:00:00 2001 From: Yndira Escobar <129537638+Yndira-E@users.noreply.github.com> Date: Fri, 9 May 2025 11:34:13 +0200 Subject: [PATCH 03/12] Update src/_includes/hubspot/hs-form.njk --- src/_includes/hubspot/hs-form.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/hubspot/hs-form.njk b/src/_includes/hubspot/hs-form.njk index 6672c7c502..b8f8785ebc 100644 --- a/src/_includes/hubspot/hs-form.njk +++ b/src/_includes/hubspot/hs-form.njk @@ -18,7 +18,7 @@ if (targetScript && targetScript.parentNode) { const errorSection = document.createElement('section'); - errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white'); + errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white', 'px-4'); errorSection.innerHTML = `

Hmm… there was supposed to be a form here.

From dce5c957558811b1377164f3fceec16ce5adedb6 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 14:10:23 +0300 Subject: [PATCH 04/12] handle error on other hs forms --- .eleventy.js | 32 +++++++++++------------ src/_includes/base.js | 19 ++++++++++++-- src/_includes/hubspot/hs-book-meeting.njk | 2 +- src/_includes/hubspot/hs-form.njk | 21 ++------------- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 6d6155509a..341cc0f029 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -59,17 +59,17 @@ module.exports = function(eleventyConfig) { if (!content) return ''; const match = content.match(/]*>([\s\S]*?)<\/h1>/); - + if (match) { const textContent = match[1].replace(/<\/?[^>]+>/gi, '').trim(); return textContent; } - + return null; }); // Add a global data variable for the current date - eleventyConfig.addGlobalData("currentDateISO", new Date().toISOString()); + eleventyConfig.addGlobalData("currentDateISO", new Date().toISOString()); // Make filters globally accessible global.isFuturePost = eleventyConfig.getFilter('isFuturePost'); @@ -118,7 +118,7 @@ module.exports = function(eleventyConfig) { return `

${markdownContent}
`; }); - let flowId = 0; // Keep a global counter to allow more than one + let flowId = 0; // Keep a global counter to allow more than one eleventyConfig.addPairedShortcode("renderFlow", function (flow, height = 200) { flowId++; // Increment the flowId to allow multiple flows on the same page @@ -132,7 +132,7 @@ module.exports = function(eleventyConfig) { const coreNodes = JSON.parse(fs.readFileSync(path.join(__dirname, 'src', '_data', 'coreNodes.json'), 'utf-8')); // Transform coreNodes object into an array - return Object.entries(coreNodes).map(([key, nodes]) => ({ key, nodes })); + return Object.entries(coreNodes).map(([key, nodes]) => ({ key, nodes })); }) eleventyConfig.addAsyncShortcode("coreNodeDoc", async function (category, node) { @@ -176,7 +176,7 @@ module.exports = function(eleventyConfig) { array.sort((t1, t2) => { var a = t1[attr]; var b = t2[attr]; - + return a > b ? 1 : (a === b ? 0 : -1); // eslint-disable-line no-nested-ternary }); @@ -265,7 +265,7 @@ module.exports = function(eleventyConfig) { if (parts[parts.length-1] === "index") { parts.pop(); } - + let path = ""; return "/"+parts.map(p => { let url = `${path}/${p}`; @@ -352,7 +352,7 @@ module.exports = function(eleventyConfig) { .sort((a, b) => b.commonTags - a.commonTags || b.date - a.date) .slice(0, 5); }); - + // Custom async filters eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (code, callback) { try { @@ -406,7 +406,7 @@ module.exports = function(eleventyConfig) { let data = fs.readFileSync(relativeFilePath, function(err, contents) { if (err) return err return contents - }); + }); return data.toString('utf8'); } @@ -439,7 +439,7 @@ module.exports = function(eleventyConfig) { }); } - + `; }); @@ -468,7 +468,7 @@ module.exports = function(eleventyConfig) { return `
  • ${iconSvg}${label}
  • ` } }); - + // Eleventy Image shortcode // https://www.11ty.dev/docs/plugins/image/ if (DEV_MODE) { @@ -505,7 +505,7 @@ module.exports = function(eleventyConfig) { return await imageHandler(imageSrc, imageDescription, title, [imageSize], null, currentWorkingFilePath, eleventyConfig, async=true, DEV_MODE); }); - + // Create a collection for sidebar navigation eleventyConfig.addCollection('nav', function(collection) { let nav = {} @@ -695,7 +695,7 @@ module.exports = function(eleventyConfig) { }, {}); const folderPath = env.page.inputPath - + // Check if the image has the 'data-zoomable' attribute const widths = 'data-zoomable' in attributes ? [1920] : [650]; // maximum width an image can be displayed at as part of blog prose @@ -725,12 +725,12 @@ module.exports = function(eleventyConfig) { if (hrefIndex >= 0) { let href = tokens[idx].attrs[hrefIndex][1]; const classIndex = tokens[idx].attrIndex('class'); - + // Exclude the link if it has the class 'header-anchor' if (classIndex >= 0 && tokens[idx].attrs[classIndex][1] === 'header-anchor') { return self.renderToken(tokens, idx, options); } - + // Ensure the URL has a trailing slash, but do not update if it contains a '#' or ends with '.md' or https if (!href.endsWith('/') && !href.includes('#') && !href.endsWith('.md') && !href.endsWith('.zip') && !href.includes('https')) { href += '/'; @@ -741,7 +741,7 @@ module.exports = function(eleventyConfig) { return self.renderToken(tokens, idx, options); }; - + eleventyConfig.setLibrary("md", markdownLib) if (!DEV_MODE) { diff --git a/src/_includes/base.js b/src/_includes/base.js index bef6a04087..6b65013d80 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -9,7 +9,7 @@ const blockedScripts = [ ] function needsToBeBlocked(src) { - return blockedScripts.some((blockedScript) => blockedScript.test(src)) + return blockedScripts.some((blockedScript) => blockedScript.test(src)) } // Patch document.createElement to allow blocking of unwanted scripts injected externally @@ -63,4 +63,19 @@ document.createElement = function(...args) { } return scriptElt -} \ No newline at end of file +} + +function hsFallback (element) { + if (element && element.parentNode) { + const errorSection = document.createElement('section'); + errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white', 'px-4'); + errorSection.innerHTML = ` +

    Hmm… there was supposed to be a form here.

    +

    + If you’re using strict privacy settings or navigating in private mode, it might be blocked. + Try adjusting your settings or switching browsers to continue. +

    + `; + element.parentNode.insertBefore(errorSection, element.nextSibling); + } +} diff --git a/src/_includes/hubspot/hs-book-meeting.njk b/src/_includes/hubspot/hs-book-meeting.njk index 22d8260e4c..2573ea8a0a 100644 --- a/src/_includes/hubspot/hs-book-meeting.njk +++ b/src/_includes/hubspot/hs-book-meeting.njk @@ -1,2 +1,2 @@
    - \ No newline at end of file + diff --git a/src/_includes/hubspot/hs-form.njk b/src/_includes/hubspot/hs-form.njk index b8f8785ebc..03fc133bf3 100644 --- a/src/_includes/hubspot/hs-form.njk +++ b/src/_includes/hubspot/hs-form.njk @@ -8,26 +8,9 @@ capture('{{ cta or hubspot.cta }}', { 'page': '{{ hubspot.reference or title }}' }) - } + }, }); } - function fallback() { - const targetScript = [...document.scripts].find( - s => s.src.includes('js-eu1.hsforms.net/forms/embed/v2.js') - ); - if (targetScript && targetScript.parentNode) { - const errorSection = document.createElement('section'); - errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white', 'px-4'); - errorSection.innerHTML = ` -

    Hmm… there was supposed to be a form here.

    -

    - If you’re using strict privacy settings or navigating in private mode, it might be blocked. - Try adjusting your settings or switching browsers to continue. -

    - `; - targetScript.parentNode.insertBefore(errorSection, targetScript.nextSibling); - } - } - + From 1e927ec237db1f32e440b4e7ab8f2941516a6f0e Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 14:23:27 +0300 Subject: [PATCH 05/12] handle error on other blog hs form --- src/_includes/hubspot/hs-newsletter.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/hubspot/hs-newsletter.njk b/src/_includes/hubspot/hs-newsletter.njk index 5cf10742cb..690e249a44 100644 --- a/src/_includes/hubspot/hs-newsletter.njk +++ b/src/_includes/hubspot/hs-newsletter.njk @@ -10,4 +10,4 @@ }); } - \ No newline at end of file + From 2589d394a056e86c2803f96100fa76032af838d2 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 14:31:03 +0300 Subject: [PATCH 06/12] handle error on the last hsform i could find --- src/_includes/migration.njk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_includes/migration.njk b/src/_includes/migration.njk index fcf4f8f043..66d9e9afff 100644 --- a/src/_includes/migration.njk +++ b/src/_includes/migration.njk @@ -65,7 +65,7 @@ function migrateFile() { // Your migration logic goes here - + var file = null var selectedFile = document.getElementById("dashboard1-flow-file").files if (selectedFile) { @@ -125,4 +125,4 @@ }); } - \ No newline at end of file + From 46ea0e20f3a4bc620a1a5872f53848df6cfc5b23 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 14:57:00 +0300 Subject: [PATCH 07/12] fix IDE overreaction on white spaces --- src/_includes/base.js | 2 +- src/_includes/hubspot/hs-form.njk | 3 +-- src/_includes/migration.njk | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/_includes/base.js b/src/_includes/base.js index 6b65013d80..f3e6f6fc0e 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -9,7 +9,7 @@ const blockedScripts = [ ] function needsToBeBlocked(src) { - return blockedScripts.some((blockedScript) => blockedScript.test(src)) + return blockedScripts.some((blockedScript) => blockedScript.test(src)) } // Patch document.createElement to allow blocking of unwanted scripts injected externally diff --git a/src/_includes/hubspot/hs-form.njk b/src/_includes/hubspot/hs-form.njk index 03fc133bf3..d342f38d16 100644 --- a/src/_includes/hubspot/hs-form.njk +++ b/src/_includes/hubspot/hs-form.njk @@ -8,9 +8,8 @@ capture('{{ cta or hubspot.cta }}', { 'page': '{{ hubspot.reference or title }}' }) - }, + } }); } - diff --git a/src/_includes/migration.njk b/src/_includes/migration.njk index 66d9e9afff..a7bb5e66d6 100644 --- a/src/_includes/migration.njk +++ b/src/_includes/migration.njk @@ -65,7 +65,7 @@ function migrateFile() { // Your migration logic goes here - + var file = null var selectedFile = document.getElementById("dashboard1-flow-file").files if (selectedFile) { From a043772d3bde9c6eb2af7d946fd9352c8396f056 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 14:58:36 +0300 Subject: [PATCH 08/12] fix IDE overreaction on white spaces pt2 --- .eleventy.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 341cc0f029..e78c76b059 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -59,17 +59,17 @@ module.exports = function(eleventyConfig) { if (!content) return ''; const match = content.match(/]*>([\s\S]*?)<\/h1>/); - + if (match) { const textContent = match[1].replace(/<\/?[^>]+>/gi, '').trim(); return textContent; } - + return null; }); // Add a global data variable for the current date - eleventyConfig.addGlobalData("currentDateISO", new Date().toISOString()); + eleventyConfig.addGlobalData("currentDateISO", new Date().toISOString()); // Make filters globally accessible global.isFuturePost = eleventyConfig.getFilter('isFuturePost'); @@ -118,7 +118,7 @@ module.exports = function(eleventyConfig) { return `
    ${markdownContent}
    `; }); - let flowId = 0; // Keep a global counter to allow more than one + let flowId = 0; // Keep a global counter to allow more than one eleventyConfig.addPairedShortcode("renderFlow", function (flow, height = 200) { flowId++; // Increment the flowId to allow multiple flows on the same page @@ -132,7 +132,7 @@ module.exports = function(eleventyConfig) { const coreNodes = JSON.parse(fs.readFileSync(path.join(__dirname, 'src', '_data', 'coreNodes.json'), 'utf-8')); // Transform coreNodes object into an array - return Object.entries(coreNodes).map(([key, nodes]) => ({ key, nodes })); + return Object.entries(coreNodes).map(([key, nodes]) => ({ key, nodes })); }) eleventyConfig.addAsyncShortcode("coreNodeDoc", async function (category, node) { @@ -176,7 +176,7 @@ module.exports = function(eleventyConfig) { array.sort((t1, t2) => { var a = t1[attr]; var b = t2[attr]; - + return a > b ? 1 : (a === b ? 0 : -1); // eslint-disable-line no-nested-ternary }); @@ -265,7 +265,7 @@ module.exports = function(eleventyConfig) { if (parts[parts.length-1] === "index") { parts.pop(); } - + let path = ""; return "/"+parts.map(p => { let url = `${path}/${p}`; @@ -352,7 +352,7 @@ module.exports = function(eleventyConfig) { .sort((a, b) => b.commonTags - a.commonTags || b.date - a.date) .slice(0, 5); }); - + // Custom async filters eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (code, callback) { try { @@ -406,7 +406,7 @@ module.exports = function(eleventyConfig) { let data = fs.readFileSync(relativeFilePath, function(err, contents) { if (err) return err return contents - }); + }); return data.toString('utf8'); } @@ -468,7 +468,7 @@ module.exports = function(eleventyConfig) { return `
  • ${iconSvg}${label}
  • ` } }); - + // Eleventy Image shortcode // https://www.11ty.dev/docs/plugins/image/ if (DEV_MODE) { @@ -505,7 +505,7 @@ module.exports = function(eleventyConfig) { return await imageHandler(imageSrc, imageDescription, title, [imageSize], null, currentWorkingFilePath, eleventyConfig, async=true, DEV_MODE); }); - + // Create a collection for sidebar navigation eleventyConfig.addCollection('nav', function(collection) { let nav = {} @@ -695,7 +695,7 @@ module.exports = function(eleventyConfig) { }, {}); const folderPath = env.page.inputPath - + // Check if the image has the 'data-zoomable' attribute const widths = 'data-zoomable' in attributes ? [1920] : [650]; // maximum width an image can be displayed at as part of blog prose @@ -725,12 +725,12 @@ module.exports = function(eleventyConfig) { if (hrefIndex >= 0) { let href = tokens[idx].attrs[hrefIndex][1]; const classIndex = tokens[idx].attrIndex('class'); - + // Exclude the link if it has the class 'header-anchor' if (classIndex >= 0 && tokens[idx].attrs[classIndex][1] === 'header-anchor') { return self.renderToken(tokens, idx, options); } - + // Ensure the URL has a trailing slash, but do not update if it contains a '#' or ends with '.md' or https if (!href.endsWith('/') && !href.includes('#') && !href.endsWith('.md') && !href.endsWith('.zip') && !href.includes('https')) { href += '/'; @@ -741,7 +741,7 @@ module.exports = function(eleventyConfig) { return self.renderToken(tokens, idx, options); }; - + eleventyConfig.setLibrary("md", markdownLib) if (!DEV_MODE) { From 03a439caae11abe2347c4bb828bfba2c069a9751 Mon Sep 17 00:00:00 2001 From: Costin Serban Date: Fri, 9 May 2025 14:59:09 +0300 Subject: [PATCH 09/12] Update src/_includes/base.js Co-authored-by: Zeger-Jan van de Weg --- src/_includes/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/base.js b/src/_includes/base.js index f3e6f6fc0e..f31402faa3 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -73,7 +73,7 @@ function hsFallback (element) {

    Hmm… there was supposed to be a form here.

    If you’re using strict privacy settings or navigating in private mode, it might be blocked. - Try adjusting your settings or switching browsers to continue. + Try adjusting your settings or switching browsers to continue, or send an email to sales@flowfuse.com.

    `; element.parentNode.insertBefore(errorSection, element.nextSibling); From 85b3dd32d16a0eefbf38c48bb5b176c04b94949d Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 15:00:41 +0300 Subject: [PATCH 10/12] convert the email string into an email anchor --- src/_includes/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/base.js b/src/_includes/base.js index f31402faa3..40f294b37c 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -73,7 +73,7 @@ function hsFallback (element) {

    Hmm… there was supposed to be a form here.

    If you’re using strict privacy settings or navigating in private mode, it might be blocked. - Try adjusting your settings or switching browsers to continue, or send an email to sales@flowfuse.com. + Try adjusting your settings or switching browsers to continue, or email sales@flowfuse.com.

    `; element.parentNode.insertBefore(errorSection, element.nextSibling); From 909a8ba220ed67688b548074adaab01c14a0ea57 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 16:01:56 +0300 Subject: [PATCH 11/12] hardcode error title color --- src/_includes/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/base.js b/src/_includes/base.js index 40f294b37c..8a50f5df52 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -70,7 +70,7 @@ function hsFallback (element) { const errorSection = document.createElement('section'); errorSection.classList.add('text-center', 'border', 'border-indigo-300', 'rounded-lg', 'bg-white', 'px-4'); errorSection.innerHTML = ` -

    Hmm… there was supposed to be a form here.

    +

    Hmm… there was supposed to be a form here.

    If you’re using strict privacy settings or navigating in private mode, it might be blocked. Try adjusting your settings or switching browsers to continue, or email sales@flowfuse.com. From eb0e4cd8876b084c4ca685ca1d3d69e44afc3bc3 Mon Sep 17 00:00:00 2001 From: cstns Date: Fri, 9 May 2025 16:07:49 +0300 Subject: [PATCH 12/12] revert sales email --- src/_includes/base.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_includes/base.js b/src/_includes/base.js index 8a50f5df52..4e8feb59eb 100644 --- a/src/_includes/base.js +++ b/src/_includes/base.js @@ -73,7 +73,7 @@ function hsFallback (element) {

    Hmm… there was supposed to be a form here.

    If you’re using strict privacy settings or navigating in private mode, it might be blocked. - Try adjusting your settings or switching browsers to continue, or email sales@flowfuse.com. + Try adjusting your settings or switching browsers to continue.

    `; element.parentNode.insertBefore(errorSection, element.nextSibling);