Publishing

The finished website is the public/ folder. Publishing means copying it to a web server. Any server that can serve files will do: no database, no PHP, nothing to update.

Build # ↑

$ siv build

Only changed files are written. Files siv didn't make are removed from public/, so it always matches your project. If there is an error, nothing is written, and public/ keeps the last working version.

--strict    stop with an error code if there are warnings
--drafts    include pages with draft = true

Copy it to the server # ↑

The project's Makefile publishes with rsync:

$ make publish

The first time, edit the Makefile: delete the @echo line, remove the # in front of the rsync line, and change the server's address:

rsync -a --chmod=D755,F644 --exclude=/.well-known/acme-challenge/ public/ tero@example.com:/home/tero/publicsite/

Try it first with --dry-run added: rsync lists what it would send, without sending anything.

  • -a keeps the times of the files. siv gives each file the time of its newest source, so rsync sends only the files that really changed.
  • --chmod=D755,F644 lets the web server read the files. Without it, a server may answer "403 Forbidden".

make publish never deletes anything on the server: addresses are forever. make cleanup deletes only old copies of converted images.

A safer server # ↑

Make a separate user on the server for publishing, and let it only copy files to the web folder. In that user's ~/.ssh/authorized_keys:

command="rrsync /home/tero/publicsite/",restrict ssh-ed25519 AAAA...

Server settings # ↑

The 404 page, content/404/index.md, is published as /404/index.html. Tell the server to show it for missing pages. In nginx:

error_page 404 /404/index.html;

In Apache: ErrorDocument 404 /404/index.html.

A page you moved has an alias: Moving a page. A server redirect (301) is faster, and set in the server's configuration.

Keeping an old site # ↑

Moving from an old site? Put its files in oldpublic/. siv copies them into the new site, so every old address keeps working. A new page with the same address as an old file replaces it, with a warning.

Moving from Hugo: siv import hugo DIR makes a siv project of a Hugo site, with the old addresses kept as aliases. Details: siv help import and siv help oldpublic.

Next: Checks and explanations