Crates.io | zb |
lib.rs | zb |
version | 0.1.2 |
source | src |
created_at | 2022-04-29 22:27:51.022061 |
updated_at | 2024-06-24 12:29:42.40296 |
description | a zip blog |
homepage | |
repository | https://code.rosaelefanten.org/zb |
max_upload_size | |
id | 577906 |
size | 120,232 |
This is my approach at creating a self-contained website. The whole site will be embedded as a Zip archive right in the server binary file, so it is probably the most portable website you'll ever have.
One of zb
's unique features it that it will render HTML, Markdown and Org-Mode files, so if you prefer to write .org
files instead of HTML, zb
has you covered.
I first saw the concept of single binary websites in Ted Unangst's blog where he complained that Go couldn't do this just as easily, because of its broken support for embedded Zip files. As I play with both Go and Rust every now and then, I thought "how hard could it be to do it in Rust?".
Quite surprisingly (for me), it wasn't really hard at all.
You'll need a Zip file, containing your website. For the default start page, zb
will search for one of the following files in the root path:
index.htm
index.html
index.md
index.org
If you prefer to use a different file name, you can pass --defaultpage name.ext
when starting the application.
Everything else in that Zip file can be any file of your choice. Relative references between them will work. (If they don't, please file a bug.)
> fossil clone https://code.rosaelefanten.org/zb
> cd zb
> git clone https://github.com/dertuxmalwieder/zb
> cd zb
zb
with cargo
:> cargo build --release
Now, concatenate your zb
binary with your Zip file. Assuming your Zip file is named index.zip
:
% cat ./target/release/zb index.zip > ./zb
Now, concatenate your zb.exe
with your Zip file. Assuming your Zip file is named index.zip
:
# PowerShell
> cmd /c copy /b .\target\release\zb.exe+.\index.zip .\zb.exe
# cmd
> copy /b .\target\release\zb.exe+.\index.zip .\zb.exe
Run the concatenated zb
binary and your website will be delivered from port 8000. (You can change that: zb --port 8081
would make it run on port 8081 instead.) From now on, every time you want to update your website, just create a new Zip file and repeat the concatenation. (It should be easy to automatize that task.)
It is important to note that the file extensions for .org
, .md
and HTML files are optional, so the file stuff/demofile.md
can be reached over localhost:8000/stuff/demofile
as well.
The search order for all files is:
/[path]
/[path].md
/[path].org
/[path].htm
/[path].html
git at tuxproject dot de
) or as a GitHub Pull Request. Note that GitHub only provides a mirror, so you'd double my work if you choose the latter. :-)If you do that well (and regularly) enough, I'll probably grant you commit access to the upstream Fossil repository.
Writing this software and keeping it available is eating some of the time which most people would spend with their friends. Naturally, I absolutely accept financial compensation.
Thank you.