frog icon indicating copy to clipboard operation
frog copied to clipboard

Arbitrary metadata, paving the way, Pt. I

Open toothbrush opened this issue 5 years ago • 2 comments

The context for this PR is the discussion in #214. To be clear, i don't really expect this PR to be accepted, but i would like to use it as a way to gather input on what i'm trying to do. Also, apologies for my crude hacking, my Racket is rusty and probably needs restringing.

I spent quite a while staring at the Frog code, in the hope that i could help myself. I basically want a reliable way to set a variable inside my blog post (whether it be Markdown or Scribble) and refer to it in page-template.html. I found that i could kinda sorta abuse tags like Foo:3 and regex them out in the template (at least i could use unmodified Frog), but that was really not helping me sleep at night. So i thought i'd try to allow either arbitrary fields in https://github.com/greghendershott/frog/blob/08fa3db7cf45ac648ddd194d9051268dd0601519/frog/private/posts.rkt#L137 (but that would mean probably modifying meta-data's return type.. everywhere) or alternatively take the path of least resistance and make the Racket list with tags available in the template by adding it to the dictionary here https://github.com/greghendershott/frog/blob/08fa3db7cf45ac648ddd194d9051268dd0601519/frog/private/posts.rkt#L261 which is fed into the page's environment with some macro magic here https://github.com/greghendershott/frog/blob/2bc070a60333e1316ff713f9b9b577a7c27e54b3/frog/private/template.rkt#L58 Forgive me, i know you know this, but i'm providing verbosity and links for posterity and those following along at home.

Anyway, modifying that hash turned out not to work, and after struggling on a few separate occasions and finally manually expanding the macro magic which lets the hash into the page's namespace, i saw that list values were getting turned from '(happy list) into (happy list), which of course made Racket sad in the context of:

(eval
 '(let ((boo ("flux" "flad")))
    ...)))

My commit basically puts back the magical quote to turn the value of boo back into a list. Is there a better way to do this? As best as i can tell i haven't broken anything by doing this.

toothbrush avatar Jan 09 '19 12:01 toothbrush

So it's been some years since I thought much about this code, but: I think the assumption has been that metadata values are always strings. Strings are "self-quoting". So it wasn't necessary to do what commit 47377e6 does. The commit seems innocent enough. What I don't know is the other consequences if any of allowing non-string values for metadata, generally??

greghendershott avatar Jan 14 '19 21:01 greghendershott

Yep, indeed i inferred that assumption from the way the code works. I can confirm that for the cases of strings and lists this patch works perfectly well, but indeed i'm not sure if there are weird edge-cases where i've made things break. I won't take it personally if you don't accept this patch – this is one of a long list of patches i've made to my local Frog to scratch my itches.

Thank you!

toothbrush avatar Jan 15 '19 02:01 toothbrush