Cristiano Paris
2015-08-09 12:38:49 UTC
Hi all,
I'm on my way customizing my new Hakyll-powered blog and I wanted to insert
an optional "tags" metadata entry in my posts and have them rendered
differently when tags are specified.
So, I though that the best strategy would be to check whether some
"renderedTags" field is in the context and render the tags accordingly.
Basically, in my template I have something like this:
$if(renderedTags)$
in $renderedTags$
$endif$
I came up with a function implementing a new string field which is "empty"
when no "tags" entry is specified and a string with the rendered tags when
it is. Here is the function (I omitted the uninteresting parts):
renderedTagsField :: String -> Context String
renderedTagsField key = Context $ \ k _ i ->
if k /= key then empty else do
tags <- getTags (itemIdentifier i)
renderTags $ reverse tags
where
renderTags [] = empty
renderTags [t] = return $ StringField t
...
Now, this function works but I'm not completely satisfied with it. My
initial intention was actually to leverage on some already-available
functions like "field" but this one fmaps the returned value from the
"value" function to StringFields and I don't know how to return an empty
field when no "tags" entry was specified. It would have worked if I used
the "field'" function from Hakyll.Web.Template.Context but it is not
publicly exposed (and I think for a reason).
So my question is: is there any more elegant way to implement what I'm
doing?
Thakn you.
Regards.
Cristiano
I'm on my way customizing my new Hakyll-powered blog and I wanted to insert
an optional "tags" metadata entry in my posts and have them rendered
differently when tags are specified.
So, I though that the best strategy would be to check whether some
"renderedTags" field is in the context and render the tags accordingly.
Basically, in my template I have something like this:
$if(renderedTags)$
in $renderedTags$
$endif$
I came up with a function implementing a new string field which is "empty"
when no "tags" entry is specified and a string with the rendered tags when
it is. Here is the function (I omitted the uninteresting parts):
renderedTagsField :: String -> Context String
renderedTagsField key = Context $ \ k _ i ->
if k /= key then empty else do
tags <- getTags (itemIdentifier i)
renderTags $ reverse tags
where
renderTags [] = empty
renderTags [t] = return $ StringField t
...
Now, this function works but I'm not completely satisfied with it. My
initial intention was actually to leverage on some already-available
functions like "field" but this one fmaps the returned value from the
"value" function to StringFields and I don't know how to return an empty
field when no "tags" entry was specified. It would have worked if I used
the "field'" function from Hakyll.Web.Template.Context but it is not
publicly exposed (and I think for a reason).
So my question is: is there any more elegant way to implement what I'm
doing?
Thakn you.
Regards.
Cristiano
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.