I'm writing a static site builder using shake
and am trying to implement an efficient way of persisting the site's navigation (along with some metadata for each page). This is turning out to be more complex than I imagined:
- The site-metadata is a tree data-structure where each node in the tree is a permalink, along with the page's metadata, like title, short blurb, author, etc.
- This site-metadata is used by almost all pages to render a site-wide navigation (either in the header or the sidebar).
- Whenever a page is modified, its build rule modifies its own node in the site-metadata.
- The complete site-metadata is stored in a file (as opposed to individual file's for each page's metadata)
If the site-metadata is updated at the end of each page's build action, it will result in the the site-metadata being deserialised, updated, serialised, and written to disk, potentially hundreds of times (once for oeach build-rule that is executed).
Instead, I was thinking of reading the site-metadata into an IORef
at the very top, and updating the in-memory IORef at the end of each page's build-action.
However, this can lead to two problems:
- how do I make the
sitemap.xml
rule depend on thisIORef
and how do I ensure that it runs at the very end? - how do I make each page depend on this
IORef
because there is actually a cyclic-dependency here - each page, both, depends and updates the site-metadata.
If I've made this more complex that it needs to be, what is an alternate, but efficient way of implementing this?