timwis / jkan

A lightweight, backend-free open data portal, powered by Jekyll
https://jkan.io
MIT License
219 stars 309 forks source link

Get github-metadata gem working on Netlify #227

Closed timwis closed 1 year ago

timwis commented 1 year ago

We use the github-metadata gem to provide a few things to Jekyll like the repository name (used by Netlify CMS config) and the 'Edit on GitHub' links. We may be able to get it working on Netlify; alternatively, we'll have to remove the dependency on the gem.

Detected issues:

Ideas so far:

timwis commented 1 year ago

I've written a Netlify Build plugin (https://github.com/timwis/jkan/commit/98a812b0c020e09882f3f07f3e03bbb9b89e499d) to generate a _config_override.yml file, but issue 1 and 4 above still remain for some reason. I'll see if I can reproduce them locally by setting JEKYLL_ENV=production on my laptop's build.

timwis commented 1 year ago

Okay, I've dug in a lot deeper to the github-metadata gem, and I think I understand what's behind the two main issues:

Very nearly there!

timwis commented 1 year ago

All right, I've reported the branch issue on the github-metadata repo, and implemented a workaround: the Netlify Build Plugin now saves the name of the branch being deployed to site.branch. When we configure the Editor UI in /editor/index.html, it now says branch: {{ site.branch | default: site.github.source.branch }}, using the value from the config if it's available, and defaulting back to whatever's generated by the github-metadata gem.

So, just to recap, we've essentially made the github-metadata gem "get out of the way" when deploying to Netlify. We do this by generating a supplemental _config.ci.yml file during the build process — but only in a Netlify build (via a Netlify build plugin). Jekyll loads this _config.ci.yml first, then loads the normal _config.yml, so an admin can override anything that's generated, if they prefer.

I think once we switch the GitHub Pages approach to using Actions, we should explore moving away from the github-metadata gem (because we can have the Action generate a _config.ci.yml file as well).