The Making of Woolridge.nl

I started working on this website as a way to keep our (Gail & I) recipes in a format that can be shared. It’ll probably become something a bit more complicated than that (and judging by the fact this isn’t a recipe - already has).

The first step was choosing a static sitee generator that I could have automatically update our recipes (kept in markdown format) to be published as a website. I had used Jekyll very briefly in the past and so wanted something that worked similarly, but was written in Python (I am trying to learn Python at the moment) - but everything I was finsing seemed too focused on blogs. After an evening of digging through a few different options I gave up and came back to Jekyll. It just seems more straightforward for what I am trying to accomplish.

From there I wrote a python script (below) to copy the recipes with some YAML front matter into the project folder for the website. This allows Jekyll to automatically turn all the recipes into HTML and build a page that links to them all.

import os
import os.path
import textwrap


def prepare_recipes():
    recipe_source = "/home/buu/Documents/temp"
    recipe_destination = "/home/buu/Documents/programming/woolridge.nl/_recipes"

    for dirpath, dir_names, file_names in os.walk(recipe_source, topdown=True):
        for file in file_names:
            old_path = os.path.join(dirpath, file)
            if " " in file:
                new_file = file.replace(" ", "_")
            relative_path = os.path.relpath(dirpath, recipe_source)
            new_path = os.path.join(recipe_destination,relative_path, new_file)
            new_path_directories = os.path.dirname(new_path)
            os.makedirs(new_path_directories, exist_ok=True)
            category = os.path.basename(dirpath)
            title = file[:-3]
            add_front_matter(old_path, new_path, title, category)

def add_front_matter (original_file: str, new_file: str, title: str, category: str):
    with open(original_file , 'r', encoding='utf-8') as original, open(new_file, 'w', encoding='utf-8') as new:
        raw_front_matter = f"""\
            ---
            layout: recipes
            title: {title}
            category: {category}
            ---
            
            """
        front_matter = textwrap.dedent(raw_front_matter)
        original_content = original.read()
        new_content = front_matter + original_content
        new.write(new_content)

if __name__ == "__main__":
    prepare_recipes()

From here I wanted to figure out a way to automate having the website published. At first I was looking to build it into the python script using the neocities API, but after a brief try it seemed overly complicated for what I wanted. Next I checked out their CLI app - it seemed a lot better! The ability to push only changes was what I was looking to do and this had it built in. While reading through something to get the CLI set up I ran into the deploy-to-neocities github action. This would build the site using Jekyll and then push it to neocities every time I pushed an update to github! Considering I was already using github as a way to move the files between computers this was a no-brainer.