teg! - a web building block for the desperate
code: codeberg

What's teg?

teg is a small (~600 LOC) portable web "anti-framework" foundation made in AWK, compatible with pretty much all AWKs out there, so you can even use teg on Plan 9.

teg is meant to be a minimal building block for your full website; it only acts as a page generator. You can piece together teg with your own scripts and programs to, for example, make a full-on CGI system. teg can be used with a Makefile to generate a static site from a list of .teg files.

The current implementation of teg consists of several discrete parts:

Why's teg?

I wanted a simple framework for my website to not write everything in HTML by hand. Everything I looked at didn't fit me in one way or another, so I decided to just make something of my own.

This project is to not be taken seriously. Heck, all of this is a giant shitpost. I know this part is not even worth adding, but some people took this whole thing as something serious like I'm going to pitch it to a company. Sorry, no I won't.

Let's have fun and more.

Naming

teg is always typed lowercase.
teg is named as a reference to the Russian name for graffiti tags (тег, теггинг) and their crudeness, just like teg itself.

Syntax

The syntax of teg is all over the place. It is a mix of a dialect of Markdown, calls, variables and comments.

Comments

Comments are defined with two equals signs at the start of a line:
== This is a comment
   == This is NOT a comment
All comments are skipped.

Calls

Calls are defined with an exclamation mark at the start of a line:
!exec_raw echo 'Hello, World!'
If the call exists, it will be executed, and the line replaced with the call's return.
The current implemented calls are:

!var variable=value

Set variable to value
If value is not set but an equals sign exists, clear variable

!start

Declare the start of the webpage.
You can only use !inc and !var before !start

!exec_raw command

Run a command in your system's command interpreter and give its output to the Markdown processor

!exec_fmt command

Run a command and paste its output as a code block. Disables the Markdown processor for the contents of the code block

!exec_inc command

Execute a command and include its output as teg

!inc file

Include a file

!e element class options

Open an HTML tag on first call, remember the class, and close the tag on the second call for the same class
If class is "_", the HTML tag does not receive a class
The options get passed to the HTML tag like so: !e div _ style="font-size: 90%;" -> <div style="font-size: 90%;">

!eo element class options

Same as !e; just don't remember the class and don't close the element. Only use on self-closing tags!

Inline calls

The following syntax can be used to include a call or a variable without splitting a line: Here's an example of using inline calls to create a page that displays your distro name:
!var osname={!exec_raw . /etc/os-release&&echo $PRETTY_NAME||echo unknown!}
!start
My current distro is `{$osname$}`
Inline calls can be nested:
!var ls_args=-lF
!start
ls output: {!exec_fmt ls {$ls_args$}!}
... but please keep in mind that nesting can sometimes be very broken and cause unexpected issues.

Inline calls get expanded inside codeblocks, so if you want to display one, you need to escape it.
Example:
hello  {$who$} <- NO!
hello \{$who$} <- Yes!

Variables

teg has some built-in variables that you can read for information or set to change behavior:

file

File that is currently being processed

title=file

Page title

description

Page description for OpenGraph embeds

lang=en-US

Page locale

status

Return an HTTP status for use with CGI
Must be set before !start

ctype=text/html

Content type for use with CGI
Only works together with status

color_chrome

Browser style color (only for mobile)

embed_img

Add an OpenGraph image embed
Must be a link to a website

icon

Favicon

style

External CSS stylesheet to reference

style_inline

CSS stylesheet to include in HTML

script

External JS to reference

script_inline

Inline JS to include in HTML

debug=0

Enable / disable debug logging

exit_on_error=1

Abort processing and exit on error

no_br=0

Ignore line breaks for the next N lines

no_proc=0

Halt processing for the next N lines

curr_line

Current line, unprocessed

prev_line

Previous line, processed

e_nest_lvl=0

Current element nesting level

inside_pre=0

Are we inside preformatted text?

inside_codeblock=0

Are we inside a codeblock?

Markdown

teg's markdown is relatively close to the one you are familiar with, except for things like altered newline behavior, styles inside single quote code and some missing complex features like tables.

Spoilers

||[Click me]Boo!||
Click meBoo!

Modified newline behavior

Line 1
Same line

Line 2


Line 4?
formats as
Line 1 Same line
Line 2

Line 4?

Strikethrough text

~~strikethrough!~~
strikethrough!