Feature Idea: Arbitrary Post meta-data
LeifAndersen opened this issue · 5 comments
Right now a post can have metadata for Title
, Date
, Tags
, and Authors
. This is sufficient for most cases, but sometimes you want additional information in each post.
For example, lets say I wanted to enable comments, but I didn't like using disqus. I could follow this tutorial (http://hydroecology.net/using-github-to-host-blog-comments/), to use github issues to host comments for me. Unfortunately, there isn't a direct mapping from a github issue to the post itself, and so would need to be denoted for every post.
Right now, there is no good way to do that when using markdown, meaning I'd have to write all of my posts with scribble. I mean, you 'could' make a tag for the issue number, and parse that out, but that seems a bit...clunky. Instead, it might make sense to have extra meta-data be available to the post-template.html
and page-template.html
files, so that they can be used in formatting the page.
The bit of code is here:
(define h
(for/fold ([h (hash)])
([s (string-split plain-text "\n")])
(match s
[(pregexp "^ *(.+?): *(.*?) *$" (list _ k v))
#:when (member k '("Title" "Date" "Tags" "Authors"))
(hash-set h k v)]
[s (warn s) h])))
in posts.rkt
. It seems like it would theoretically be as easy as just adding all meta-data info to the hash table, rather than just Title
, Date`, etc.
That's a good idea.
The only downside that occurs to me would be the disappearance of warn
. That is, today you get a helpful warning if you (say) accidentally type Author:
instead of Authors:
.
p.s. I don't understand this part:
Right now, there is no good way to do that when using markdown, meaning I'd have to write all of my posts with scribble.
What would be the good way, how would you do it in Scribble?
The only downside that occurs to me would be the disappearance of warn.
True. Although perhaps that could be configured in the blog's frog.rkt config file? Perhaps something like enabled meta-tags
?
What would be the good way, how would you do it in Scribble?
Okay, so probably not the best way in the world. And I'd have to double check how frog renders scribble files, but what I was thinking was having the template post.html file use a parameter defined in a different racket file, and having the blog post setting that parameter.
I always have a mixed feeling about these metadata. As I use only Scribble (never use Markdown), I would prefer to have something like Pollen's define-meta
(https://docs.racket-lang.org/pollen/Core.html?q=define-meta#%28form._%28%28lib._pollen%2Fcore..rkt%29._define-meta%29%29) instead of an ad-hoc parsing. For example, (define-meta k v)
for Frog could translate into the following XML:
<frog-metadata>
<key>k</key>
<value>v</value>
</frog-metadata>
and then you can simply search over the xexpr for frog-metadata
instead of using an ad-hoc parsing and cleansing.
I have been playing with Frog the last few days, and i, too, would love this sort of feature. Unfortunately my Racket-fu is super rusty (much embarrassment) and so i've kinda been struggling with trying a few things:
- trying to actually get an HTML comment into the final outputted page so i can regex it out of
@|content|
(i know i know, that's awful) – i haven't managed with Markdown or Scribble posts to get an actual HTML comment in there. I've tried splicing in!HTML-COMMENT
but haven't managed, tried using@(make-comment ..)
but that seems to require.. context? And of course simply putting<!-- MyKey: Val -->
into Markdown or Scribble renders to<!-- ...
which isn't what i want. - trying to define a variable (with
make-parameter
ordefine
or justset!
) inside the post source file, which the template can read - Leif's suggestion of adding a new metadata type in
posts.rkt
although admittedly i haven't tried that because .. i believe it should be doable without modifying Frog?
Anyway, apologies for the helplessness, i'm going to continue poking about and see if i can make something work. Just consider this a "thank you" for making Frog and a +1 on the feature request? 😅