Items for files that do not exist

12 views
Skip to first unread message

Artem Shinkarov

unread,
Feb 18, 2023, 2:04:58 AM2/18/23
to hakyll
Dear hakyll group

I am running into a little bit of a problem, and I would like to ask
use your collective wisdom.

I want to use a latex bibliography file to generate a list of my
publications.  I can parse the file, turn each publication into
a Context, and then apply some templates to generate the code.
Roughly this looks like so:

```
bibRule :: Bib -> Rules ()
bibRule b@(Bib ty name its) =
  create [fromFilePath $ "pubs/" <> name <> ".html"] $ do
    route idRoute
    compile $ do
      makeItem "" >>= loadAndApplyTemplate "templates/pub.html" (bibToContext b)
```
and then in the main I just do:

```
forM_ bibs bibRule
```

This works fine, except when I run `./site watch` it does not pickup
changes in the bib file (any ideas how to fix this?).

However, a more annoying problem is that when I am creating a list
of publications, I want to create a context that roughly looks like
this:

```
[
  "pub1": [("key","val"),("key1", "val1")],
  "pub2": [("key","val"),("key1", "val1")],
   ...
]
```

so that I could feed it into `$for` template.  The problem is that
lists in contexts internally store a list of `Item`-s, and so then
each item is looked-up, and the actual matching happens.  But I don't
have an `Item` for the publication, as it is not coming from a file.
It doesn't have a filepath, as it is purely virtual.

Is there a way to pre-generate a constant list that I could feed into
the `$for` template without creating actual files on the filesystem?

You can find the code that I have so far here:
https://gitlab.sac-home.org/tema/artem-blog



Cheers,
Artem

Artem Shinkarov

unread,
Feb 19, 2023, 8:41:21 PM2/19/23
to hakyll
Ok, I think I solved both of my problems after searching and trying things out.

Just in case anybody else runs into the same questions, here are a few useful links.

1) A way to organise parsing from bib file into templates: https://github.com/jaspervdj/hakyll-bibtex
The code needs some adjustments, but generally it is more or less working.
The key idea there is to derive Binary and Typable instances for the data that represents bib items, and then you can turn a bib into a proper Context.

2) How to make a static listField out of a bunch of items: https://beerendlauwers.be/posts/2015-08-17-hacking-on-hakyll-pt-2.html
In essence the key thing is to use sequence and itemBody when constructing the context of the listField.
See the link for more details.


Cheers,
Artem
Reply all
Reply to author
Forward
0 new messages