setting metadata for items in Hakyll

24 views
Skip to first unread message

Jonathan Dowland

unread,
Aug 23, 2019, 5:45:23 AM8/23/19
to hakyll
Hello all,

I'm a relative beginner to Hakyll, investigating whether/how I might migrate my personal blog from IkiWiki. There
are a couple of IkiWiki features I want to retain so I've been looking at writing a "bridge" to implement those features
in Hakyll. My initial experiments on that are here: <https://github.com/jmtd/hakyll-ikiwiki>

As part of this, I wish to pre-process text files that are considered by Hakyll prior to them being passed to Pandoc.
I do this and perform text substitutions fine. But I might also gather metadata from the body of text files that I would
like to "promote" up to Hakyll's Metadata data structures for the item.

Searching around I see several people trying to do this in the past. The closest to a solution I have found is this
thread "I'm hitting a wall trying to scrape context fields from a file's body":

The solution there gathers metadata from item bodies and injects them into a new Context, for template substitution.
In most cases this is probably, ultimately, what I want; but I'm not sure it is in *all* cases. There may be circumstances
where I want the Metadata for an item for other reasons than template substitution. It seems conceptually that what I
am wanting to do is to modify the Metadata for an Item and the template stuff is one of several possible "downstream"
processes from that.

the Haddock documentation for the Metadata type is quite brief and there appears to be no supported way to add to
the Metadata for an item. Is this right? Is this a feature that would be considered for the future?

Thank you (and any other comments or suggestions on my IkiWiki→Hakyll quest are gratefully received)


Best wishes


--
Jonathan Dowland

Jasper Van der Jeugt

unread,
Aug 25, 2019, 8:43:48 AM8/25/19
to hak...@googlegroups.com
Hello Jonathan,

> The solution there gathers metadata from item bodies and injects them into
> a new Context, for template substitution.
> In most cases this is probably, ultimately, what I want; but I'm not sure
> it is in *all* cases. There may be circumstances
> where I want the Metadata for an item for other reasons than template
> substitution.

Unfortunately (or fortunately), this is a bit of a conscious choice I
made when designing this part of Hakyll. Metadata is assumed to be
"very fast to read"; so it can either be obtained by peeking at a file's
header, or by looking in the separate `.metadata` file.

Injecting metadata based on a file's content would break that
assumption, since then it's necessary to parse the entire file.

What sort of metadata are you looking to extract from the existing
files?

Warm regards
Jasper
> --
> 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+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/hakyll/33001d44-c869-47ee-89ab-0e139125dae8%40googlegroups.com.

jon.d...@gmail.com

unread,
Aug 27, 2019, 6:36:51 AM8/27/19
to hakyll
Hi Jasper, thanks for the reply.


On Sunday, August 25, 2019 at 1:43:48 PM UTC+1, jaspervdj wrote:
What sort of metadata are you looking to extract from the existing
files?

It could be almost anything. IkIWiki has a scheme of "directives" in-line in content
rather than using a preamble-style metadata block. So e.g. "[[!meta title=foo]]" anywhere
in the text of a file sets the title.

Other directives might also influence metadata, e.g. "[[!tag bar]]" is probably best mapped
to a "tags": metadata key in Hakyll.

I could, I guess, do a one-time transformational pass over the source for a site and move
such things into the preamble for Hakyll. But that'd would be best done when I was certain
I was moving my site over, and I'm still in the discovery phase for that. My site (just a personal
blog) is approx 100M of content (only 1.5M of it text files, but still: 1.5M of text content) so I'm
testing the waters quite slowly and thoroughly :-)

For now I can't think of a situation where I need to influence something other than possibly
template Contexts from the inline content, so the approach I linked to works for me.



Thanks

--
Jonathan Dowland
Reply all
Reply to author
Forward
0 new messages