-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a script to build help (#223)
* feat: create a script to build help * chore: use native base64 * chore: fix eslint * chore: fix prettier in build_help * chore: add help.html in prettier ignore
- Loading branch information
Showing
6 changed files
with
388 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/lib/canvas_editor/cursors_24px.js | ||
/openchemlib | ||
/war | ||
/help.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
import { readdir, readFile, writeFile } from 'node:fs/promises'; | ||
|
||
const homedir = new URL( | ||
'../openchemlib/src/main/resources/html/', | ||
import.meta.url, | ||
); | ||
|
||
// loading the images | ||
const pngNames = await readdir(new URL('editor', homedir)).then((files) => | ||
files.filter((file) => file.endsWith('.png')), | ||
); | ||
const images = {}; | ||
for (const pngName of pngNames) { | ||
const blob = await readFile(new URL(`editor/${pngName}`, homedir), 'base64'); | ||
const encoded = toBase64URL(blob, 'image/png'); | ||
images[pngName] = encoded; | ||
} | ||
|
||
// loading the html file | ||
let html = await readFile(new URL('editor/editor.html', homedir), 'utf8'); | ||
for (const [pngName, encoded] of Object.entries(images)) { | ||
html = html.replaceAll(`src="${pngName}"`, `src="${encoded}"`); | ||
} | ||
|
||
// loading css | ||
let css = await readFile(new URL('styles.css', homedir), 'utf8'); | ||
html = html.replace( | ||
'<link type="text/css" href="../styles.css" rel="stylesheet">', | ||
`<style>${css}</style>`, | ||
); | ||
|
||
await writeFile(new URL('../help.html', import.meta.url), html); | ||
|
||
function toBase64URL(base64, type) { | ||
return `data:${type};base64,${base64}`; | ||
} |