# csg csg is the "complicated (static) site generator". It's a somewhat simple static site generator, written in bash, with many "poweruser" features thanks to [awk](TODO). The overall design is heavily inspired by [Roman Zolotarev](https://romanzolotarev.com/)'s [ssg](https://romanzolotarev.com/ssg.html), however the codebase is completely different, with the added bonus of: - arbitrary file modifications via awk - git-based "created" and "edited" timestamps - support for (multiple) description and title meta tags - support for custom title format ## How to use Your content is inside a "source" folder, while the resulting website files will be put in a "destination" folder. Webpages are written in Markdown, which is then transformed into HTML with the proper edits, and finally `_header.html` and `_footer.html` are stitched on top and bottom. Everything else is taken as-is. Additional features are available with [awk](TODO). By default, the title, description and word count are taken from every Markdown file. The title and description will be put in place of `[TITLE]` and `[DESCRIPTION]` inside `_header.html`. You can also create/use your own awk scripts for further page modification (all three values will also be available inside those scripts). *Note:* if you don't want the additional features, just use [ssg](https://romanzolotarev.com/ssh.html) ### Writing your own scripts There are some things you must consider while creating an awk script: 1. It will be ran on the generated HTML pages 2. It's name **must** start with a capital letter - You can also create so-called "libraries", mainly awk scripts with only function definitions - libraries **must** start with a `#` character in their name, and are included with every script 3. The current line **mustn't** be printed (unless you want to add a line to the file) - With awk we can modify only certain lines, but the easiest way to get the whole file with the modified lines, is to just print every line. Such a rule is "appended" to the end of your script. - Do modifications to `$0` instead of `print (fancy expression)` - If you don't want to print a line, do `$0 = 0` 4. Every script **must** begin with a `# regex` line - For optimisation purposes, a script is ran only on the files which match the given regular expression - The regex is on the whole path, so you could make changes (for example) to specific pages or all pages inside folders - The regular expression is fed to `find -regex`, so for exact support view `find`'s documentation 5. Script variables **mustn't** collide and you **mustn't** use `exit` or `nextfile` - Also for optimisation purposes, scripts with the same regex are combined into one 6. Inside your scripts you'll have the `title`, `description`, `words`, `created` and `edited` variables available The last two will be dates in the format "%d %B %Y", and are only available if your website uses git. ### Generate website with the script csg comes with a help message, which contains everything you might want to know for running the script: ``` Usage: csg [-h | -? | --help] csg [] Options: -h, -?, --help Print this help message (also available when given no arguments) Arguments: Folder which contains source files Folder in which the generated site will be put Format string for page title Accepts any text or HTML, & is replaced with contents title (first h1 header). Optional, folder which contains awk script for editing of generated webpages. Variables (you can predefine): CSG_TIMESTAMP_FILE File path for git-based timestamps (when git exists) Default: "./timestamps.txt" Disable: "" CSG_TMP_DIR Directory to put temporary files Default: "/tmp" CSG_AWK awk executable and flags Default: searches for gawk CSG_MD_TO_HTML Program to convert Markdown to HTML and it'\''s flags Default: searches for lowdown Dependencies (required): bash, printf, find, cpio csg - complicated (static) site generator Created by Syndamia, https://gitlab.com/Syndamia/csg ``` ### Demo This repository comes with a small demo setup. To test it out, run: ```bash ./csg ./demo/src ./demo/website '& - Demo' ./demo/awk-edits ``` You will find your website, ready to be served, inside `./demo/website`. ## Future features 1. I would love to make it POSIX compatible, however this will require a good amount of work and will introduce inefficiencies, so for now it's left for the future 2. Right now the whole website is regenerated every time, it's important to add a system for updating only the currently changed pages. I'm not entirely sure how to do that, since we remove the source Markdown after it is converted to HTML, current thinking leads me to a file containing lines of "filepath hash", but we'll see.