## requirements

* Docker

## up and running

### build container image

    $ make image-build

### build site

    $ make build

### start dev server

    $ make serve

Visit `localhost:8080` in web browser

## getting around

### rebuild the container image

    $ make image-rm image-build

### generate a new site file

    $ docker run --rm -w /opt/app -v $PWD:/opt/app miti.sh sitegen new

### add an index page

#### create the file

    $ docker run --rm -w /opt/app -v $PWD:/opt/app miti.sh sitegen page /opt/app index

#### add to `site.moon`

    add "index.md"

### add config for nginx

    $ mkdir logs/ conf/

    # conf/nginx.conf
    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        server {
            listen 8080;
            location / {
                default_type text/html;
            }
        }
    }

### build a single file

    $ make build file=index.html

### start a shell

    $ make shell

### start watcher

    $ docker exec -it container_name sitegen watch

### run tests

    $ make test

### lint moonscript

    $ make lint

### print out pygments styles

    $ pygmentize -S STYLE -f formatter

example:

    $ pygmentize -S default -f html

### deploy

    $ make deploy

### renew server TSL certs

SSH into server admin account and run:

    $ cd www
    $ dehydrated --config config -c

Then restart the OpenResty service:

    $ sudo service openresty restart

#### automate TSL cert renewal with cron

Open root's crontab:

    $ sudo crontab -e

Add the following line, then save and exit:

    19 4 1 * * /usr/bin/dehydrated --config /var/www/config --cron >/dev/null 2>&1 && /usr/bin/systemctl restart openresty.service

## gotchas

### What is error `cosmo failed: [string "..."]:62: cannot resume dead coroutine`?

If you call `cosmo.yield`, your function **must** return `nil`! If you forget
to return `nil`, you will see this cryptic error:

    Error: index.html -> html/index.html: cosmo failed: [string "..."]:62: cannot resume dead coroutine
    make: *** [Makefile:6: build] Error 1`

### What is error `calling 'load_cache' on bad self`?

    moon: .../local/openresty/luajit/share/lua/5.1/sitegen/common.lua:41:
    /usr/local/openresty/luajit/share/lua/5.1/sitegen/cache.lua:99: calling
    'load_cache' on bad self (table expected, got userdata) stack traceback:

Delete your `.sitegen_cache` file.

## thinking about

* use sitecache with pandoc renderer
* draft documents
* treesitter highlighting for moonscript
