+++
title = "building a site with zola and sourcehut"
date = 2023-06-02
+++

# Introduction

The following is a small tutorial on how to build a static webpage using
<a href="https://www.getzola.org/" target="_blank">Zola</a> and 
<a href="https://builds.sr.ht/" target="_blank">Sourcehut's build service</a>.

This guide is kindof redundant since Zola's documentatioin is already very
clear, but I want to write a first post in order to test this site.

<br>

# Prerequisites

First off, download Zola using your package manager.
<a href="https://www.getzola.org/documentation/getting-started/installation/"
target="_blank">Installation instructions</a> can be found on their site.

After that, <a href="https://builds.sr.ht/"
target="_blank">create an account</a> on Sourcehut. I paid for the
"Amateur Hackers" tier as I'm just getting started with this project.

<br>

# Creating a static webpage

All commands assume you are on the root of your project.

<br>

### Zola

Once you've downloaded Zola, create an empty dir, initialize you site and
initialize a git repo:
```bash
$ mkdir www && cd www
$ zola init posixlycorrect.com
$ git init
```

Test everything is fine:
```bash
$ zola serve
```

If it is, download a theme:
```bash
$ mkdir -p themes
$ cd themes
$ git clone https://github.com/pawroman/zola-theme-terminimal.git
```

Add content to your site:
```bash
$ mkdir -p content
$ cd content
$ nvim _index.md    ## add to this whatever your theme needs in order to work
                    ## usually this is detailed on the theme's docs

$ nvim blog.mb      ## landing page for posixlycorrect.com/blog
$ mkdir blog && cd blog
$ nvim building_a_site_with_zola_and_sourcehut.md   ## your first post
$ cd ..
$ nvim about.md    ## your about page
```

Check that everything looks good:
```bash
$ zola serve
```

<br>

### Sourcehut

Your site is now ready to be published! In order to do that, commit your changes
and add a remote repo from sourcehut:
```bash
$ git add .
$ git commit
$ git remote add origin git@git.sr.ht:~fabianmv/posixlycorrect.com
```

Add a build manifest so sourcehut knows how to publish your site:
```bash
$ nvim .build.yml
```

My manifest looks like this:
```yaml
image: alpine/edge
packages:
  - hut
  - zola
oauth: pages.sr.ht/PAGES:RW
environment:
  site: posixlycorrect.com
sources:
  - https://git.sr.ht/~fabianmv/posixlycorrect.com
tasks:
  - build: |
      cd posixlycorrect.com
      mkdir -p templates
      zola build
  - package: |
      cd posixlycorrect.com
      tar -C public -cvz . > ../site.tar.gz
  - upload: |
      hut pages publish -d $site site.tar.gz
```

Add and commit your changes and push your repo:
```bash
$ git add .
$ git commit
$ git push
```

Your website now should be visible! Updating it is a matter of making changes
and pushing to your repo.

Good luck!

If you have any questions, feel free to email me.


<br>

---

Good luck!

If you have any questions, feel free to email me.
