From db9b74a54afc940d9f09e0a85d333d749cd022f3 Mon Sep 17 00:00:00 2001 From: Max Gerlings <124243961+gerlingsm@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:11:25 +0200 Subject: [PATCH 1/8] Move excalidraw script import to worker.js --- excalidraw/assets/index.html | 1 - excalidraw/src/worker.js | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/excalidraw/assets/index.html b/excalidraw/assets/index.html index 360d73f92..0a465648f 100644 --- a/excalidraw/assets/index.html +++ b/excalidraw/assets/index.html @@ -3,6 +3,5 @@ - diff --git a/excalidraw/src/worker.js b/excalidraw/src/worker.js index 8aaa204d3..b51446f31 100644 --- a/excalidraw/src/worker.js +++ b/excalidraw/src/worker.js @@ -20,6 +20,9 @@ export default class Worker { try { await page.setViewport({ height: 800, width: 600 }) await page.goto(this.pageUrl) + await page.addScriptTag({ + path: `${path.join(__dirname, '..', 'assets', 'excalidraw', 'excalidraw.production.min.js')}` + }); // QUESTION: should we reuse the page for performance reason ? return await page.evaluate(async (definition) => { const svgElement = await window.ExcalidrawLib.exportToSvg(JSON.parse(definition)) From 4c06424905b97760b53fe0bf97a000cce747bf67 Mon Sep 17 00:00:00 2001 From: Max Gerlings <124243961+gerlingsm@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:12:09 +0200 Subject: [PATCH 2/8] add custom asset path over env variable --- excalidraw/src/worker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/excalidraw/src/worker.js b/excalidraw/src/worker.js index b51446f31..6f0e8abd1 100644 --- a/excalidraw/src/worker.js +++ b/excalidraw/src/worker.js @@ -9,6 +9,7 @@ export default class Worker { constructor (browserInstance) { this.browserWSEndpoint = browserInstance.wsEndpoint() this.pageUrl = process.env.KROKI_EXCALIDRAW_PAGE_URL || `file://${path.join(__dirname, '..', 'assets', 'index.html')}` + this.assetPath = process.env.KROKI_EXCALIDRAW_ASSET_PATH || '' } async convert (task) { @@ -23,6 +24,9 @@ export default class Worker { await page.addScriptTag({ path: `${path.join(__dirname, '..', 'assets', 'excalidraw', 'excalidraw.production.min.js')}` }); + await page.addScriptTag({ + content: `window.EXCALIDRAW_ASSET_PATH="${this.assetPath}"` + }); // QUESTION: should we reuse the page for performance reason ? return await page.evaluate(async (definition) => { const svgElement = await window.ExcalidrawLib.exportToSvg(JSON.parse(definition)) From ce1b59b2bede180868f4d46ffa68f3091cf41e95 Mon Sep 17 00:00:00 2001 From: Max Gerlings <124243961+gerlingsm@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:14:41 +0200 Subject: [PATCH 3/8] Add empty env variable to dockerfile --- excalidraw/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/excalidraw/Dockerfile b/excalidraw/Dockerfile index 238304ffc..854881014 100644 --- a/excalidraw/Dockerfile +++ b/excalidraw/Dockerfile @@ -12,6 +12,7 @@ WORKDIR /usr/local/kroki/ RUN mkdir -p /usr/local/kroki/node && chown kroki:kroki -R /usr/local/kroki ENV KROKI_EXCALIDRAW_PAGE_URL=file:///usr/local/kroki/assets/index.html +ENV KROKI_EXCALIDRAW_ASSET_PATH= ENV PUPPETEER_EXECUTABLE_PATH=/usr/lib/chromium/chrome #ENV DEBUG="puppeteer:*" ENV LEVEL="info" From fd8a5285492a8970ed677c2ea998c3dd9ba6d8c5 Mon Sep 17 00:00:00 2001 From: Max Gerlings <124243961+gerlingsm@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:09:45 +0200 Subject: [PATCH 4/8] Update excalidraw documentation --- docs/modules/setup/pages/configuration.adoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/modules/setup/pages/configuration.adoc b/docs/modules/setup/pages/configuration.adoc index a4efc07fe..17e58257f 100644 --- a/docs/modules/setup/pages/configuration.adoc +++ b/docs/modules/setup/pages/configuration.adoc @@ -218,6 +218,12 @@ TIP: Keep in mind that browsers also have a URI limit on `` tags. Most modern browsers https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers/417184#417184[support a URI length greater than 64000] on `` tags but this value is probably a bit excessive. We recommend to use a maximum length that's not greater than 8192 and not greater than 5120 if you are supporting IE 11. +== Excalidraw Asset Path + +By default excalidraw loads the assets from a public CDN. (unkpg) +Its possible to change this behaviour over the KROKI_EXCALIDRAW_ASSET_PATH env variable, which is empty by default +More informationen about the asset path can be found here: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/installation + == Enabling SSL on the server By default, SSL/TLS is not enabled on the server but you can enable it by setting `KROKI_SSL` environment variable to `true`. From 5fe69e1822821fe8a5a2e8b4f57c77c61a2dd19c Mon Sep 17 00:00:00 2001 From: Max Gerlings <124243961+gerlingsm@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:15:40 +0200 Subject: [PATCH 5/8] update formatting --- docs/modules/setup/pages/configuration.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/modules/setup/pages/configuration.adoc b/docs/modules/setup/pages/configuration.adoc index 17e58257f..df4fc1107 100644 --- a/docs/modules/setup/pages/configuration.adoc +++ b/docs/modules/setup/pages/configuration.adoc @@ -221,7 +221,9 @@ We recommend to use a maximum length that's not greater than 8192 and not greate == Excalidraw Asset Path By default excalidraw loads the assets from a public CDN. (unkpg) + Its possible to change this behaviour over the KROKI_EXCALIDRAW_ASSET_PATH env variable, which is empty by default + More informationen about the asset path can be found here: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/installation == Enabling SSL on the server From ec65329370cd908d3e8a6e9ed0d18a463bd88695 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Thu, 12 Oct 2023 17:42:04 +0200 Subject: [PATCH 6/8] Add a comment and move the global definition before loading excalidraw.production.min.js --- excalidraw/src/worker.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/excalidraw/src/worker.js b/excalidraw/src/worker.js index 6f0e8abd1..2b9c21215 100644 --- a/excalidraw/src/worker.js +++ b/excalidraw/src/worker.js @@ -21,12 +21,13 @@ export default class Worker { try { await page.setViewport({ height: 800, width: 600 }) await page.goto(this.pageUrl) - await page.addScriptTag({ - path: `${path.join(__dirname, '..', 'assets', 'excalidraw', 'excalidraw.production.min.js')}` - }); await page.addScriptTag({ content: `window.EXCALIDRAW_ASSET_PATH="${this.assetPath}"` - }); + }) + // excalidraw.production.min.js is using the EXCALIDRAW_ASSET_PATH variable. + await page.addScriptTag({ + path: `${path.join(__dirname, '..', 'assets', 'excalidraw', 'excalidraw.production.min.js')}` + }) // QUESTION: should we reuse the page for performance reason ? return await page.evaluate(async (definition) => { const svgElement = await window.ExcalidrawLib.exportToSvg(JSON.parse(definition)) From f2a025394b4f38009bab7b9f813253c3b3b1728d Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Thu, 12 Oct 2023 17:48:25 +0200 Subject: [PATCH 7/8] Apply suggestions from documentation review --- docs/modules/setup/pages/configuration.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/modules/setup/pages/configuration.adoc b/docs/modules/setup/pages/configuration.adoc index df4fc1107..d44835389 100644 --- a/docs/modules/setup/pages/configuration.adoc +++ b/docs/modules/setup/pages/configuration.adoc @@ -220,11 +220,11 @@ We recommend to use a maximum length that's not greater than 8192 and not greate == Excalidraw Asset Path -By default excalidraw loads the assets from a public CDN. (unkpg) +By default, Excalidraw loads assets from a public CDN (https://unpkg.com). -Its possible to change this behaviour over the KROKI_EXCALIDRAW_ASSET_PATH env variable, which is empty by default +It's possible to change this behavior by setting the `KROKI_EXCALIDRAW_ASSET_PATH` environment variable, which is empty by default. -More informationen about the asset path can be found here: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/installation +More information about Excalidraw' static assets can be found here: https://docs.excalidraw.com/docs/@excalidraw/excalidraw/installation == Enabling SSL on the server From e3bdbe5ed9201023631e7e16fd85ad3c40250eed Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Thu, 12 Oct 2023 17:49:27 +0200 Subject: [PATCH 8/8] Title capitalization --- docs/modules/setup/pages/configuration.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modules/setup/pages/configuration.adoc b/docs/modules/setup/pages/configuration.adoc index d44835389..bc9362104 100644 --- a/docs/modules/setup/pages/configuration.adoc +++ b/docs/modules/setup/pages/configuration.adoc @@ -218,7 +218,7 @@ TIP: Keep in mind that browsers also have a URI limit on `` tags. Most modern browsers https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers/417184#417184[support a URI length greater than 64000] on `` tags but this value is probably a bit excessive. We recommend to use a maximum length that's not greater than 8192 and not greater than 5120 if you are supporting IE 11. -== Excalidraw Asset Path +== Excalidraw static assets By default, Excalidraw loads assets from a public CDN (https://unpkg.com).