Convert a directory of typst files to html files.
Currently, the native typst to html export does not allow compiling to several html files. This project exists as a workaround to that.
- Make sure you have the following programs installed:
- Typst
- Just a command runner
- Fish shell
- Python (optional, for testing the website)
- This setup only works on Mac and Linux, not Windows
- Now you can clone this repo:
git clone https://github.com/EnzoMoser/typ2html
Go into the cloned repo:
cd typ2html/Run the following command. This will compile the example files located in typst:
justNow you should have a new directory called html/. These are the corresponding html files compiled from the typst/ directory.
We can test the compiled html with a HTTP server. To run a local one using Python:
just hostNow open your browser and go to http://0.0.0.0:1102/. You now have a website built from typst!
Inside typst/, create as many directories with corresponding index.typ files and edit these files to your desires. The script will recursively look for the and compile the file index.typ inside the typst/ directory. If you make a new index.typ, make sure to include the following:
#import ".conf.typ": conf
#show: conf
// The rest goes hereThe default title will be the directory name, except for root, which is "home". To change the title:
#import ".conf.typ": conf
#show: conf.with(title: [Custom title here])
You can edit style.css to change the CSS style and also typst/.conf.typ to change the default layout
Calling just performs the following:
- Make the
html/directory and symlinkstyle.cssinside it - Recursively create symlinks to
.conf.typinside every folder intypst/that containsindex.typ - Cleanup/remove
.conf.typsymlinks that don't haveindex.typin the same dir - Recursively create a
.content.tomlfile that lists subdirectories that haveindex.typintypst/ - Cleanup/remove
.content.tomlfiles that don't haveindex.typin the same dir functions/gen_content.fish - Recursively compile each
index.typinsidetypst/intoindex.htmlinsidehtml/ - Remove files and folders from
html/that aren't intypst/
Also, checkout out shiroa, which is a fancier tool that allows for more complex websites made from typst