When we last left our heros… We had taken a SQL database, converted it to JSON, split it into 885 separate JSON files, renamed and moved them based on the folder path previously assigned.
That took a while, but now we’re ready for the fun!
Convert them to MD
I already know how to do this one. Run grunt-mustache-render!
One problem. It didn’t like recursive folders. Pause for laughter. Thankfully I had done a cp
and not an mv
on my files with Mike’s script, so I just changed that to handle moving .md
files instead of .json
and it all went fine.
Turn on Hugo
I had a theme already so I copied it over and then started making my changes. I needed the layout to be a little different.
First I needed a list of all the sections and files and I needed to grab all the items that were an ‘Index’ file and format them specially:
<div id="albums"> {{ range $section, $taxonomy := .Site.Sections }}{{ range $taxonomy.Pages }}{{if eq .Type "index" }} <div class="indexalbum"> <div class="thumb"><a href="{{ .Permalink}}" title="View album: {{ replace $section "-" " " | title }}">IMAGE HERE</a></div> <div class="albumdesc"><h3><a href="{{ .Permalink}}" title="View album: {{ replace $section "-" " " | title }}">{{ replace $section "-" " " | title }}</a></h3> {{ with .Params.desc }} {{ . | safeHTML}} {{ end }}</div> <p style="clear: both; "></p> </div> {{ end }}{{ end }}{{ end }} </div>
I felt very pleased with myself at this point. Obviously I would need to replace “IMAGE HERE” with an image, but I had the basic idea down.
Inside each post, there was a shortcode mentioned before, {{< gallery >}}
, and this is where my drama started. What I wanted I thought would be (fairly) easy. Get a list of all the folders where this index.md
file was and list them similar to what I had done before. They were sub-sections (in Hugo Terms), but as it happens, Hugo doesn’t have a way to handle those! There are no templates for subsections. Now this in and of itself wasn’t a deal breaker. I could made do with that shortcode except…
Limitations
The thing I really do like about ZenPhoto is that I can drop my new media in a folder and magically knows what’s up. Add a new folder? It knows it’s there. With Hugo (or Jekyll) I found it was incredible hard to do something as ‘simple’ as getting a list of all the items in a folder. With Jekyll I’d need a plugin (which I am certainly not adverse to). Hugo has a readDir call, but it’s limited to the working directory and I wanted to read the images in a CDN folder (on the same server, but still).
Perhaps ironically, it’s easier to run a gallery with Hugo and Jekyll if you host the images off your own domain. It goes against my goal of having a self-hosted site, though. But for now, it’s not possibly to do what I wanted.
Do I feel like I wasted time?
No! In fact, I’ve learned a lot of things that tell me where the foibles are in my plans.
ustwo actually did make a React powered site and in looking at their source code I see they did it by making the site ‘all one page.’ This is something I can understand today and wrap my head around. Because the alternative would be something like this:
- Write a post
- Run a script to grab all the pages via the JSON API as individual .json files
- Run a script to convert them into .md
- Build static site (test and then deploy)
It’s not actually that horrible when I put it that way. It means everyone could write on WordPress and, when they’re ready to deploy, I just run my script, push to my dev site, validate, and push to live.
But. That loses a lot of what makes WordPress cool. Editing posts on the fly, pushing live updates, and scheduling posts all becomes a nightmare. For my Gallery idea, it means that WordPress remains a viable option except for the fact that I can’t easily move from ZenPhoto to WordPress and WordPress behaves like a blog when I don’t want it to be one.
I’m all about using WordPress for things other than blogging but the sad truth is it’s still structured like a blog. Custom Post Types are doing a great job, and a lot of what I do on my estore site is similar to how I’d want to handle a gallery. I could do posts as posts and organize them as categories, for example, and structure the whole theme to handle that…
Or I could just stay on ZenPhoto, which does all that out of the box.
And yes. That’s what I’m doing.