2022-12-16 05:11:16 +01:00
# bUwUma
2022-12-16 05:22:08 +01:00
**Bu**ild **W**ebsites **U**sing **Ma**ke
## Overview
2022-12-16 05:11:16 +01:00
`bUwUma` is a build system that uses **GNU make** and a **preprocessor** written in python to build **static** , **multilingual** websites.
This readme only documents the preprocessor.
For more information and a quickstart guide on how to use `bUwUma` , please
refer to the article [on my website ](https://quintern.xyz/en/software/buwuma.html ).
# HTML Preprocessor Documentation
2024-10-26 01:55:39 +02:00
## Markdown support
Using the `#include` command (see below) you can include markdown files, which will be automatically
converted to html using [mdtex2html ](https://pypi.org/project/mdtex2html ), which also supports converting LaTeX to MathML.
If mdtex2html is not installed `python-markdown` will be used instead.
Preprocessor commands in included markdown files will be handled as well.
2022-12-16 05:11:16 +01:00
## Syntax
### Commands
2023-09-14 16:34:05 +02:00
- All commands must be located within a html comment that starts with `<!--` and ends with `-->` .
2022-12-16 05:14:21 +01:00
- Commands start with a `#` character, the command must follow the `#` immediately.
- Everything after the command until the end of the comment or a newline character are considered the argument of the command.
```html
<!-- #command everything here is an argument -->
<!--
#command everything here is an argument
#anothercommand more arguments
#comment This will be a single line html comment after the preprocessor finishes.
-->
```
- All commands return a string, which can be empty.
- If a comment contains a command, the entire comment will replaced with the return value of the command.
2023-09-14 16:34:05 +02:00
- If there are multiple commands in a comment, it will be replaced by all the return values added together.
2022-12-16 05:14:21 +01:00
2022-12-16 05:11:16 +01:00
### Variables
2022-12-16 05:14:21 +01:00
- Variable names must only consist of these characters: `a-zA-Z0-9_`
- A variable with name `varname` can be used like this: `#$(varname)`
- A variable usage will be replaced by the value of the variable
- Any variable that has is not defined has empty string as value
2022-12-16 05:11:16 +01:00
### General
2022-12-16 05:14:21 +01:00
- Whitespaces around a token are ignored, so `<!--#include dir/file-->` is the same as `<!-- #include dir/file -->`
- If a command-comment takes up a whole line, the whole line including the newline character is replaced.
2022-12-16 05:11:16 +01:00
## Commands
### include
2023-11-18 00:19:40 +01:00
Include the content of a file (or only a specific section in that file) at the position of the command.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
`<!-- #include path/to-a-text-file.html -->`
2023-11-18 00:19:40 +01:00
`<!-- #include path/to-a-text-file.html section_name -->`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
2023-11-18 00:19:40 +01:00
A absolute or relative path to a text file [ + section name ]
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
The content of the file or `<!-- Could not include '{args}' -->` empty string if the file can not be opened.
---
2023-11-18 00:19:40 +01:00
### section
Start a section in a file. The section is only used by the `include` command to determine the start and end of a section
**Synopsis**:
`<!-- #section section_name -->`
**Argument**:
Name of the section
**Return Value**:
Empty String
---
2022-12-16 05:11:16 +01:00
### set
2022-12-16 05:14:21 +01:00
Set the value of a variable
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
Set the value of `varname` to `this is the value` :
`<!-- #set varname this is the value -->`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
Set the value of `varname` depending on the value of `othervar` :
`<!-- #set varname othervar?{*:fallback,key1:val1,key2:val2...}>`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
The first word is the name of the variable, the rest is the value or a dictionary.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
Empty string
2022-12-16 07:29:46 +01:00
2022-12-16 05:14:21 +01:00
You can make the value of `varname` dependant on the value of another variable `othervar` by using a dictionary-like syntax described above.
In this case, `varname` will take the first value from the dictionary that matches tha value of `othervar` .
`*` always everything and can be used as fallback. General wildcards like `a*` to match everything that starts with a are not supported.
Instead of commas `,` you can also use semicolons `;` as separators, but this must be consistend within the map.
2022-12-16 07:29:46 +01:00
### return
Same as `set` , but it returns the value of the variable that is being set. This is meant to use with maps, when you need a variable from a map you can 'inline' it with `return`
2022-12-16 05:11:16 +01:00
### default
2022-12-16 05:14:21 +01:00
Same as `set` , but it sets the variable's value only if it has no value yet.
2023-11-19 19:28:22 +01:00
### unset
Unset a variable
**Synopsis**:
Unset `varname` , it will no longer be defined and can therefor be set with `default` again.
`<!-- #unset varname -->`
**Argument**:
Name of the variable
**Return Value**:
Empty string
2022-12-16 05:14:21 +01:00
---
2022-12-16 05:11:16 +01:00
### comment
2022-12-16 05:14:21 +01:00
Comment the arguemnts.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
`<!-- #comment This will stay as comment in the html -->`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
Any string
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
The argument in comment tags
2022-12-16 07:29:46 +01:00
2022-12-16 05:14:21 +01:00
2022-12-16 05:11:16 +01:00
### uncomment
2022-12-16 05:14:21 +01:00
Uncomment the comment.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
`<!-- #uncomment This will not be commented -->`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
Any string
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
The argument
2022-12-16 07:29:46 +01:00
2022-12-16 05:14:21 +01:00
This can be useful when you want to look at the unprocessed html without variables or when your syntax highlighting gets confused by a variable.
---
2023-09-14 16:34:05 +02:00
### conditionals
To turn on or off entire blocks, `if` , `elif` can `else` be used.
2023-11-23 21:50:50 +01:00
These commands can not be nested.
2023-09-14 16:34:05 +02:00
Logical and `&&` and logical or `||` can be used to chain conditions.
If a condition is true, the corresponding block is included while all other blocks are deleted.
**Synopsis**
2023-09-14 16:35:08 +02:00
```
<!-- #if #$(var) == value && #$(other_var) == other_value -->
...
<!-- #elif #$(var) == value || #$(other_var) != other_value -->
...
<!-- #else -->
...
<!-- #endif -->
```
2023-09-14 16:34:05 +02:00
**Argument** Condition for `if` and `elif` , ignored for `else` and `endif`
2023-09-15 14:03:16 +02:00
2023-09-14 16:34:05 +02:00
**Return Value** Empty String
---
2022-12-16 05:11:16 +01:00
### sidenav
2022-12-16 05:14:21 +01:00
Manage the generation of a content menu which contains links to all headings in your html that have an id. The menu is called sidenav here.
An entry is a html heading with a id: `<h1 id=myheading>This heading will be linked in the sidenav</h1>`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
`<!-- #sidenav sidenav-command arguments -->`
sidenav-command must be one of the following:
2023-11-23 15:44:47 +01:00
2022-12-16 05:14:21 +01:00
#### `include`
2022-12-16 07:47:09 +01:00
Include the generated sidenav at this position. This command will always be executed last, after the whole file has been parsed.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
Ignored
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
The generated sidenav
2023-11-23 15:44:47 +01:00
2022-12-16 05:14:21 +01:00
#### `section`
2023-11-23 21:50:50 +01:00
Group all following entries in named section. `section` may not appear in conditional blocks.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
The name of the section
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**
Empty string
2023-11-23 15:44:47 +01:00
2022-12-16 05:14:21 +01:00
#### `name`
Use a custom name instead of the heading itself for the link to the next heading.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
2022-12-16 05:18:37 +01:00
The link-name of the next heading
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
2022-12-16 05:18:37 +01:00
Empty string
2022-12-16 05:14:21 +01:00
2023-11-23 15:44:47 +01:00
2022-12-16 05:14:21 +01:00
#### `custom`
Include a custom link in the sidenav.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Synopsis**:
`<!-- #sidenav custom href="my-link" name="Go to my link!" -->`
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Argument**:
Must be `href="..." name="..."` . Either single `'` or double `"` quotes are required.
2022-12-16 05:17:28 +01:00
2022-12-16 05:14:21 +01:00
**Return Value**:
Empty string
---
2023-11-23 15:44:47 +01:00
### sitemap
Used for automatically generating a `sitemap.xml` for the website.
#### `include`
Include the current page in the sitemap
**Synopsis**:
`<!-- #sitemap include -->`
`<!-- #sitemap include https://use.custom.link/for-this/site -->`
**Argument**:
Optional: Use a different link for this page
**Return Value**:
Empty string
#### `priority`
Set the `priority` field
**Synopsis**:
`<!-- #sitemap priority 0.8 -->`
**Argument**:
Float between 0.0 and 1.0
**Return Value**:
Empty string
#### `changefreq`
Set the `changefreq` field
**Synopsis**:
`<!-- #sitemap changefreq never -->`
**Argument**:
One of *always, hourly, daily, weekly, monthly, yearly, never*
**Return Value**:
Empty string
#### `lastmod`
Set the `lastmod` field
**Synopsis**:
`<!-- #sitemap lastmod 2023-12-29T14:00:05+01:00 -->`
**Argument**:
The lastmod date in w3c date format
**Return Value**:
Empty string
---
2022-12-16 05:11:16 +01:00
## Pitfalls
2023-11-23 21:50:50 +01:00
- The `include` command must not be in the last line of the file
2022-12-16 05:17:28 +01:00
- The maps in `set` must have **at least 2** options
2023-11-23 21:50:50 +01:00
- The `section` commands must not be in a conditional block
- The conditionals must not be neseted
2022-12-16 05:14:21 +01:00
- If you want to use variables in markdown, you have to escape the `#` with a backslash, so `#$(var)` becomes `\#$(var)`
2022-12-16 07:29:46 +01:00
- You can not use the `return` command from within the arguments of other commands. Commands are executed in order, so `return` will end up as argument of the first command and thus never be executed