timwis / jkan

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

Support editing categories and licenses in Netlify CMS #207

Closed timwis closed 1 year ago

timwis commented 1 year ago

The current JKAN admin lets you edit categories and licenses in the UI. Both those collections are stored in a single file (_data/categories.yml and _data/licenses.yml). Netlify CMS sort of supports this through its file collections, but file collections don't seem to work with top-level lists (see netlify/netlify-cms#531).

The work-around would be to add a top-level key to both files, e.g. instead of:

- name: Budget / Finance
- name: Economy

We'd have:

items:
  - name: Budget / Finance
  - name: Economy

Which isn't too bad, but is definitely a breaking change (though we may be able to mitigate it through backwards compatibility).

licenses.yml is a bit more complex: it's currently a hash/dictionary of {<url>: <name>} which certainly won't work in Netlify CMS, and it probably makes sense to convert that to a more typical structure like the other yaml files anyway. Again a breaking change, though.

timwis commented 1 year ago

I've realised it was necessary to tackle this problem in order to even add the category and license fields to the dataset form (not just to edit categories and licenses), so I've bit the bullet and wrapped the files in an items property. An alternative would have been to split them into individual files in _categories and _licenses folders, but this seemed preferable.

Doing this breaks the existing JKAN editing UI. We could fix that, but since the plan is to remove that UI in favour of the Netlify CMS UI anyway, I haven't done so.

The only impact I could find on the end-user-facing app is the list of categories on the homepage. I've added a line for backwards compatibility there: if site.data.categories.items is nil, it reverts to site.data.categories.