Sitebuilding

(A fairly small example of a static site generation, ugh, ""pipeline."" Half "this is, in general, my overall approach." And hopefully half "if you wanna run your own code for this kind of thing, it doesn't have to be an entire and massive thing.")

My static site generator is likely to be a few Lua files that I tinker with. I have them committed in whichever repo I want to be a website. (I like having them there instead of somewhere else. Like they're part of the site, and nearby if I want to change something, not off in some "library" or something.)

Will use the markdowny language from the previous post as an example, along with a build.lua file. build.lua asks the OS if there any .txt files lying around and makes an HTML file for each:

local mark = require("smolmark")

local function writehtmlfile(txtpath)
  local htmlpath = txtpath:sub(1, -5) .. ".html"
  local fin = io.open(txtpath)
  local lines = fin:lines()
  local fout = io.open(htmlpath, "w")
  local parse = mark.parse(lines)
  local firsthtml, title = parse()
  fout:write([[<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>]])
    fout:write(mark.escape(title.text or "untitled"))
    fout:write([[</title>
  </head>
  <body>]])
  fout:write(firsthtml)
  for html, _ in parse do
    fout:write(html)
  end
  fout:write([[</body>
</html>]])
  assert(fout:close())
  assert(fin:close())
end

local windows = package.config:sub(1, 1) == "\\"
local cmd = [[powershell.exe "gci -Recurse -Filter '*.txt' | rvpa -Relative"]]
local lunix = [[find . -name \*.txt -print]]
local command = windows and cmd or lunix
local pipe = io.popen(command)
local str = pipe:read()
while str do
  writehtmlfile(str)
  str = pipe:read()
end
assert(pipe:close())
build.lua

So, I have that, smolmark.lua (mostly the code from that previous post, with some adjustments), and some text files in my repo, in a folder called "site." I run lua5.4 build.lua there and it builds the site.

GitHub Pages

I've used GitHub Pages before. Previously I've mostly just clicked some buttons on the website to activate it and then let it upload whichever files are in my repo/some folder. I think maybe that was the way it was done earlier? These days, when enabling Pages, I can choose between "Deploy from a branch" and "GitHub Actions." "Deploy from a branch" is the "Classic Pages Experience," so maybe I used to do things like that because that was the way things were done. Not sure.

So not sure about olden days, but these days there are various GitHub Actions stuff you can use for different static site generators. GitHub Actions and its YAML are not the kind of things I really want to learn a lot about, but blep. It doesn't take that much figuring stuff out to run my Lua code and GitHub Pages the results.

Anyway so this workflow for deploying static content to GitHub Pages does most of the stuff I need. I suspect you can "instantiate" a workflow using a template like that or something, but I've just copied it to .github/workflows/main.yml in my repo. And:

My build step installs Lua and runs build.lua:

      - name: Build
        run: |
          sudo apt-get install -y lua5.4
          cd site
          lua5.4 build.lua

So now it runs the code and uploads the Pages whenever I push something. Also I don't need to commit the generated HTML files. And all the code is there: The only thing I need for building it locally is a Lua. Seems okay or nice or something.