- Zig 89.5%
- HTML 6.6%
- Makefile 3.5%
- CSS 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .gitignore | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
Zettp
Zettp is a zig written http server that eliminates all javascript bloat from webservers.
Zig version: 0.16.0
Why?
I don't particularly like javascript/typescript stacks and I was in need of a fun side project :) I also do think that running the entire modern internet on top of nodejs servers wastes an enormous amount of resources.
Usage
To add a new site to the zettp, create two files in the src/html/ folder.
- page.html
- page.zig
or if you dont need templating, you can just add sites to src/html/public to serve them statically.
The page.zig file will include some boilerplate, data members for the file and what html file to read.
A great example on how to construct a page, can be found from src/html/index.zig and src/html/index.html
After that, you need to add a route to your src/html/server.zig In there you also
handle configuration of the server.
main.zig and actions.zig are just wiring and helper functions. Though you can change the
memory allocator from main.zig.
Any static files should be placed in src/html/public for example, your favicon, or stylesheet files.
Static Site Generation
For static site generator, you can use zettp-kani, a static site generator made with C
https://codeberg.org/Katacc/zettp-kani
There is make step for it :)
Compiling and running
To compile the software, change the flags and options in Makefile to match what you want, and run:
make clean
make build
make run
# or cr for clean build run
make cr
Features
Of course normal html and css stuff works. But in addition Zettp provides you a templating engine. You can do 'directives' inside your html code. For example if you have a list of people in index.zig
names: []const []const u8 = &.{"Katacc", "Meow", "Nya"},
you can use the names variable in your html file.
To check if names is not empty and then iterate over names and print each name
<button>Click here if cool</button>
%%
if (names) {
for (names) |name| {
<p>${name}</p>
}
} else {
<p>No people :(</p>
}
%%
<p>meow!</p>
Added the button and p meow in the example to show how the inlining works.
Why makefile instead of zig build tools?
Well, I don't like the zig build tools.