From 5f7aa34023f3b6dae3df29c075f59eef03a593a6 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Thu, 6 May 2021 15:44:03 +0200 Subject: [PATCH] Record build info for Wasm demo --- .github/workflows/build.yml | 6 ++++++ examples/wasm/www/build-info.json | 1 + examples/wasm/www/index.html | 15 ++++++++++++++- examples/wasm/www/index.js | 15 +++++++++++++-- examples/wasm/www/webpack.config.js | 2 +- 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 examples/wasm/www/build-info.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c8242c3..fae8f7f5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -140,6 +140,12 @@ jobs: with: name: textwrap-wasm-demo-app + - name: Record build info + run: | + cat > build-info.json < Textwrap WebAssembly demo @@ -45,6 +53,11 @@

Textwrap WebAssembly Demo

+ + diff --git a/examples/wasm/www/index.js b/examples/wasm/www/index.js index 664d2257..a01e9783 100644 --- a/examples/wasm/www/index.js +++ b/examples/wasm/www/index.js @@ -1,5 +1,16 @@ import { draw_wrapped_text } from "textwrap-wasm-demo"; +fetch("build-info.json").then(response => response.json()).then(buildInfo => { + if (buildInfo.date && buildInfo.commit) { + document.getElementById("build-date").innerText = buildInfo.date; + + let link = document.createElement("a"); + link.href = `https://github.com/mgeisler/textwrap/commit/${buildInfo.commit}`; + link.innerText = buildInfo.commit.slice(0, 7); + document.getElementById("build-commit").replaceWith(link); + } +}) + function redraw(event) { let fontFamily = document.getElementById("font-family").value; let canvas = document.getElementById("canvas"); @@ -30,13 +41,13 @@ document.getElementById("line-width-text").addEventListener("input", (event) => window.addEventListener("resize", (event) => { const X_OFFSET = 8; // To accommodate the size of the slider knob. - const BOTTOM_MARGIN = 16; + let footer = document.getElementById("footer"); let canvas = document.getElementById("canvas"); let width = canvas.parentNode.clientWidth; canvas.width = width; - canvas.height = window.innerHeight - BOTTOM_MARGIN - canvas.offsetTop; + canvas.height = footer.offsetTop - canvas.offsetTop; let lineWidth = document.getElementById("line-width"); let lineWidthText = document.getElementById("line-width-text"); diff --git a/examples/wasm/www/webpack.config.js b/examples/wasm/www/webpack.config.js index 9a687e5d..a7042d60 100644 --- a/examples/wasm/www/webpack.config.js +++ b/examples/wasm/www/webpack.config.js @@ -9,7 +9,7 @@ module.exports = { }, mode: "development", plugins: [ - new CopyWebpackPlugin({patterns: ['index.html', '../README.md']}) + new CopyWebpackPlugin({patterns: ['index.html', '../README.md', "build-info.json"]}) ], experiments: { syncWebAssembly: true,