Symlinking Jekyll data files

code • October 14, 2015

Font Library has delicious data packed into a JSON file. I’ve had an urge to see how else I can hack the file with Jekyll and tonight I was up for the challenge.

To start, the JSON file is in the root of the Jekyll site, making it a simple file without Jekyll powers. I keep it there so it’s easier to find, especially for contributors. A few times I had considered moving it to _data/ because with a Jekyll data file I can use liquid to loop and if and else the data all I want.

I also thought about duplicating the file so that I’d have the best of both worlds, but that’s hard to maintain. And then I thought about creating a symlink. I had never created one before, but thanks to the Internet I opened Terminal and entered:

\$ ln -s ../families.json \_data/families.json

And :boom: symlink! (Ok, it wasn’t that smooth. It took me a bit to figure out how to write the path. And then after I pushed, I got a build error because I originally didn’t use a relative path.)

But will it loop?

I created a file in the root families.csv and wrote:

---
{% for item in site.data.families %}
{{item.family}}
{% endfor %}

And soon I had a CSV file with a list of the font family names.

I also used “very ugly string manipulation hacks” to get a distinct list of tags and in alphabetical order. And with a few more very ugly string manipulation hacks, I got the CSV file looking exactly how I wanted:

CSV file

Since GitHub pages run in safe mode the file won’t build in production. (It’s still totally a success though.)

Keep reading code