If I'm honest I probably shouldn't have bothered writing my own static site generator (SSG) software. There are already many good options out there.
It works for me though and possibly the only major advantage of rolling your own software is you can make it do exactly what you want it to.
Read the filesystem
You need to read all the raw files that constitute your site. I do that first and build an index of them.
You'll want to add some filtering facilities to ignore certain files, such as the 'dot' files editors and operating systems place in directories.
If you're using Node then readdir or readdirSync from Node's 'fs' module are probably what you need.
Process the files
Now that you have a list of relevant files you need to do something with them. I simply use the file's extension to decide what to do with it.
If it's a '.md' then we're talking about a post or page. Each one of those contains front-matter, which is things like the post's title and date, so I trim off this front-matter and I'm left with a post in markdown. I didn't write my own markdown processor, I use one called Showdown. What you have at the end of this is your markdown converted to HTML.
Render the files
You're not just going to want to display that raw HTML to users. You'll want it formatted nicely through a template. Again, I didn't write my own templating system, I used Nunjucks. So the raw HTML gets rendered through Nunjucks, the front-matter we saved earlier gets added as titles, dates, descriptions and other metadata and we save the nicely formatted page somewhere. Borrowing from a lot of other SSGs, I write this out to a '_site' directory.
Ultimately, you'll just FTP the entire contents of the '_site' directory to your live website.
That is of course hugely simplified.
What do we do with images for example? Well we could just copy them across and that would work fine, but I wanted to do a bit more than that. I wanted to take each image file and generate various different sizes of it. For that I used Sharp. Images are then rendered via the the 'img' tag's 'srcset' attribute so that browsers serve up an appropriately sized image.
Later versions added a sort of plug-in architecture using Node events to give the plug-ins an opportunity to intervene.
I'm writing this just in case there are other buffoons out there like me.