New project: Good Things, and randomization at build time
Back before COVID-19 hit the global scene, I thought it would be pleasant to have a list of the good things in life. This list wouldn’t be an exhaustive account of all the checked boxes on Maslow’s Hierarchy of Needs, but rather would document small pleasures which evoke some kind of clear and specific emotional response. If I had The Sads, I could pull up this list and sink down into the sensory details of, say, that strong hit of pine scent you randomly get on a hiking trail.
Now that we’re all in the thick of this pandemic, this new tiny side project—Good Things—has offered me a peaceful little portal to things I miss. Your mileage may vary, but I’ve found that reading my personal list of good things can be comforting as I help protect my community by sheltering in place.
Good Things is pretty much just a one-pager static site. It’s built on top of Eleventy, with a singular data file to pull in list items, which are displayed in random order. The code is available on Github, and I hope other folks do fork this! I’d love to know what would be on your list and how else you might personalize this to suit your needs.
Aesthetically, I’ve been itching to get this evergreen shade out of my system, and I enjoy how that turned out in the dark scheme as well:
Randomization at build time
As I was putting this together, I felt it would be ideal for the list items to be displayed in random order, so that the list felt fresh each time I referred to it. I considered implementing client-side randomization, but actually, that’s kind of overkill—I’m unlikely to visit the site more than once daily, and I don’t need some button to mash on in rapid succession.
How I solved this with a static site is to randomize the list order at build time. I’ve done this using a lodash function to shuffle the array. That script will execute each time a build is triggered. The trick then is to trigger a daily build.
Interestingly, Netlify—which hosts my one-pager—doesn’t yet offer (AFAICT) an in-built solution for kicking off builds at a regular interval. They do offer build hook URLs that you can trigger via a cron job. “Scheduling Netlify deploys with GitHub Actions” provides a great walkthrough on how you can do this using Github workflows, including repo secrets to keep your key safe in a public repo. With this solution, my build now randomizes at midnight, PST!
That’s pretty much all there is to this project. Please do let me know if you end up hosting your own list, I’d love to check it out!