jacobobryant / platypub

A publishing platform built with Biff
MIT License
65 stars 13 forks source link

Make slug inferring work again #52

Closed jacobobryant closed 2 years ago

jacobobryant commented 2 years ago

I just remembered that when I overhauled the data model I never got around to making https://github.com/jacobobryant/platypub/issues/26 still work. It's more difficult now since everything related to posts must be done generically. I did include something in the config for this, but platypub doesn't actually do anything with that yet. I also am not really sure how exactly that should work. probably needs more thinking.

jeffp42ker commented 2 years ago

I did see :slugify in config.edn.

I submitted a PR that infers the slug for Posts, just because I found a place to put it that seems to work.

I see path replaces slug in the Pages fields config so pages are unaffected.

jacobobryant commented 2 years ago

From https://github.com/jacobobryant/platypub/pull/53#issuecomment-1208522826:

mm--yes, it is hacky :). Ideally we wouldn't want platypub code (i.e., anything under src/) to ever reference any specific field names like :slug or :title. For a proper solution we'd want to change the case in params->custom-fields (for reference) to a cond or something. Then we can handle "special" types, e.g. in this case if the type is a vector that starts with :slugify, like [:slugify :com.platypub.post/title], then the return value of the cond should be the value of the second keyword ((:title params)) passed through the title->slug function (maybe rename to slugify or ->slug).

If we want to add any other inferred field types later on, we can follow the same pattern.

Also I suppose we could change the default theme so it also uses [:slugify :com.platypub.post/title] for the type of :com.platypub.page/path. It should work fine as long as the theme knows to change some-path to /some-path, which I think it already does.

I'll go ahead and merge, but I'll leave the issue open and quote this there.