Hosting This Site

Finding a Place

I've been thinking a bit about where/how I wanna host this site.
I don't really know much about this at all, except that I used GitHub Pages and Codeberg Pages a few times, so either of those 2 would be easiest.

GitHub is going all-in on "AI" and likely ingesting every repo they can get their hands on into whatever model they're selling at the moment.
I'd rather not support that endeavor, so...

How about Codeberg Pages?

In theory it's easy, I've used it for a Canvas API sample recently.
It needs to be a public repo and have a pages branch with a top-level index.html.
The thing is, we use a static site generator which needs a build step before we get the finished site.

Zola has instructions for deploying to Codeberg Pages using their built-in CI; however, requesting access is a manual step because they have limited resources...and to be honest, this feels a bit overkill to me. How about we do the build step locally and then push the output to a pages branch?

How?

Here's a bunch of steps we need to do:

We don't really care about history in the pages branch; it's purely for the build output and the source is versioned in the main branch, so we can overwrite pages every time we deploy without losing anything.

For the first time, let's do this manually. Later on, I'd like this to be a script I can run after I finish writing and it does all the steps to deploy the site automatically.

A Few Minutes Later...

It seems to have worked. We're live at https://carepackage17.codeberg.page/blog/!

Now let's try the deploy steps again. The pages branch already exists now, which might cause us problems when checking out, so let's delete it first to make sure there's no previous state.

A Pizza Break and Another Hour of Hacking Later

I'm ready to run a first test of the deploy shell script. Right now it looks like this:

#!/bin/bash

branch_name = $(git branch --show-current)
if [ $branch_name = "pages" ]; then
    echo "$(tput setaf 1)Deploy cannot be run from the pages branch. Switch to another branch, then try again."
    exit 1
fi

zola build

if [ $? -eq 0 ]; then
    # echo "$(tput setaf 2)success"

    # delete everything except the public directory
    find -not -path './public/*' -not -path './public' -not -path './.git' -not -path './.git/*' -not -path '.' -delete

    # copy everything out of public directory to top level
    mv public/* .

    # delete the now empty public directory
    rm -d public

    # get current short commit hash
    commit_short_hash = $(git rev-parse --short HEAD)

    # delete local pages branch (assuming it exists, will probably explode on a fresh checkout)
    git branch -d pages

    # create new local pages branch
    git switch -c pages

    # add all files and commit
    git add . && git commit -m "deploy $commit_short_hash"

    while true; do

    read -p "Force push to remote pages branch? (y/n) " yn

    case $yn in
        [yY] )
            echo "Alright, let's go:";

            # force push to pages remote branch
            git push -f -u origin pages

            break;;
        [nN] ) echo "No biggie, do it yourself then";
            exit;;
        * ) echo "I don't know what that means.";;
    esac

    done
else
    echo "$(tput setaf 1)Deploy failed ._."
fi

I haven't really written bash before, so of course it had bugs. Here's two commits that made it work for the first time:

Alright, I think that's enough tech gibberish for today.
Not a super ideal setup, but functional for now and it can be improved upon. Also, I need to test it on Windows sometime (not today, Satan).

See you next time. 🙃

Top