Static webpages are well renowned for their speed, security, and simplicity. A very common misconception is that static webpages can’t enjoy Javascript. Here is how I got this website to template applications that use Javascript and WASM using Hugo’s shortcode system.
addapp (JS + CSS) shortcode
Create a new shortcode file in theme/<name>/layouts/shortcodes/addapp.html
:
|
|
Then call the shortcode, for example, in this website’s game sokoban (file:
content/apps/sokoban.md
):
|
|
Then, put the javascript files in assets/app/<name>/app.js
. The file name must
be app.js
. Do the same for the .css
files.
For HTML, put the file in layouts/partials/apps/<name>/app.html
. This would
allow for shortcodes and other hugo functionality to be used by the app’s HTML.
Link the .css
files in app.html
like so:
|
|
Link any extra .js
files in app.html
like so:
|
|
addapp + WASM binaries
Create the directory contents/apps/<name>
, then move the file
content/apps/sokoban.md
to content/apps/sokoban/index.md
. Afterwards, place
the game.data
and the game.wasm
Emscripten generated files in the same
directory.
content/apps/sokoban/
├── game.data
├── game.wasm
└── index.md
assets/apps/sokoban
├── app.js
├── sokoshell.css
└── sokoshell.js