Towards Metadata-only Dependencies in Hakyll
Note: This has since been implemented and merged! 🥳
The Hakyll static side generator does presently not support depending only on the metadata of an Identifier. This is problematic as it creates a lot of unnecessary rebuilds when using this Metadata (e.g., in a sidebar) on each generated page.
Current State
Currently, according to my present understanding of it, Haskell’s dependency tracking roughly works as follows:
- Hakyll determines an initial Set of modified inputs using
resourceModified. - Based on this set, Hakyll determines out-of-date dependencies in a
Control.Monad.RWSmonad transformer. This happens inHakyll.Core.Dependencies, specifically inoutOfDateit checks for:- Entirely new inputs (e.g., new posts)
- Changed patterns (e.g., if a tag page depends on a new post)
- Identifier which are now out-of-date because a dependency changed (see
bruteForce)
Required Changes
In order to enable dependencies on the Metadata of an Identifier, we would have to:
In the
Dependenciesdata type, somehow allow users to express Metadata-only dependencies. This probably requires an API-breaking changes as to how dependencies are added for Identifiers. For example:data Dependencies = DependsOn [(DependencyKind, Identifier)] | MustRebuild deriving (Show) data DependencyKind = KindContent | KindMetadataEnable
DependencyMto access theHakyll.Core.Provider.MetadataCache. Thereby, enabling it to determine if the Metadata differs in comparison to the previous run. This is potentially challenging asnewProviderinvalidates the metadata cache based onresourceModified.Use the newly added
DependKindand theMetadataCacheto check if an Identifier only depends on the Metadata of another and that Metadata changed since the last run ofbruteForce.