Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbitrary metadata, paving the way, Pt. I #242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Arbitrary metadata, paving the way, Pt. I #242

wants to merge 2 commits into from

Conversation

toothbrush
Copy link

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

#:when (member k '("Title" "Date" "Tags" "Authors"))
(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
(hasheq 'title (title->htmlstr title)
which is fed into the page's environment with some macro magic here
(define/contract (render-template dir filename dict)
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.

When `v` here contains a list (as opposed to a simple datum like a
string) it would, upon unquoting the entire expression, go from
something like `'(a b)` to `(a b)`.  This would then cause the error
that `a` is undefined or not a function or whatever, because the `let`
form tries to evaluate it.  Adding this quote in between quasi
quote-and-unquoting seems to fix the issue.
Since, for now, i'm trying to set arbitrary post metadata using tags
like `Frubbles:88` or `City:Philadelphia`, it makes my life easier to
have access to the raw tag list, instead of the one that's been
dragged through `tags->xexpr` and `xexpr->string`.
@greghendershott
Copy link
Owner

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??

@toothbrush
Copy link
Author

toothbrush commented Jan 15, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants