Mostly for internal usage
Constructors
EmptyFieldStringField Stringforall a. ListField (Context a) [Item a]
:: a typeCtrl KGHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19
Modulehakyll-4.17.0.0Haskell2010
This module provides Contexts which are used to expand expressions in templates and allow for arbitrary customisation.
Templates define a small expression DSL which consists of strings,
identifiers and function application. There is no type system, every value is
a string and on the top level they get substituted verbatim into the page.
For example, you can build a context that contains
… <> functionField "concat" (const . concat) <> …which will allow you to use the concat identifier as a function that takes
arbitrarily many strings and concatenates them to a new string:
$partial(concat("templates/categories/", category))$This will evaluate the category field in the context, then prepend the path,
and include the referenced file as a template.
Mostly for internal usage
EmptyFieldStringField Stringforall a. ListField (Context a) [Item a]The Context monoid. Please note that the order in which you compose the items is important. For example in
field "A" f1 <> field "A" f2the first context will overwrite the second. This is especially important when something is being composed with metadataField (or defaultContext). If you want your context to be overwritten by the metadata fields, compose it from the right:
metadataField <> field "date" fDate
Contravariant ContextDefined in hakyll-4.17.0.0 · Hakyll.Web.Template.ContextDecidable ContextDefined in hakyll-4.17.0.0 · Hakyll.Web.Template.ContextDivisible ContextDefined in hakyll-4.17.0.0 · Hakyll.Web.Template.ContextSemigroup (Context a)Defined in hakyll-4.17.0.0 · Hakyll.Web.Template.ContextTries to find a key in the left context, or when that fails in the right context.
Monoid (Context a)Defined in hakyll-4.17.0.0 · Hakyll.Web.Template.Contextfield Constructs a new field for a Context. If the key matches, the compiler is run and its result is substituted in the template.
If the compiler fails, the field will be considered non-existent
in an $if()$ macro or ultimately break the template application
(unless the key is found in another context when using <>).
Use empty or noResult for intentional failures of fields used in
$if()$, to distinguish them from exceptions thrown with fail.
Creates a field to use with the $if()$ template macro.
Attempting to substitute the field into the template will cause an error.
boolFieldM Creates a list field to be consumed by a $for(…)$ expression.
The compiler returns multiple items which are rendered in the loop body
with the supplied context.
Creates a list field like listField, but supplies the current page to the compiler.
Creates a variadic function field.
The function will be called with the dynamically evaluated string arguments from the template as well as the page that is currently rendered.
Transform the respective string results of all fields in a context. For example,
mapContext (++"c") (constField "x" "a" <> constField "y" "b")is equivalent to
constField "x" "ac" <> constField "y" "bc"Transform the respective string results of all fields in a context satisfying a predicate. For example,
mapContextBy (=="y") (++"c") (constField "x" "a" <> constField "y" "b")is equivalent to
constField "x" "a" <> constField "y" "bc"A context that contains (in that order)
A $body$ bodyField
Metadata fields
A $url$ urlField
A $path$ pathField
A $title$ titleField
This order means that all of the fields, except $body$,
can have their values replaced by metadata fields of the same name.
For example, a context from a file at posts/foo.markdown has a default title
foo. However, with a metadata field:
---
title: The Foo Story
---The $title$ will be replaced with The Foo Story.
Body of the item, that is, the main content of the underlying file
Map any field to its metadata value, if present
Absolute url to the resulting item. For an example item that produces a
file posts/foo.html, this field contains "posts/foo.html"
Filepath of the underlying file of the item. For an example
underlying file posts/foo.markdown, this field contains
"posts/foo.markdown"
Basename of the underlying file of the item. For an example
underlying file posts/foo.markdown, this field contains "foo"
A context that allows snippet inclusion. In processed file, use as:
...
$snippet("path/to/snippet/")$
...The contents of the included file will not be interpolated like partial
does it.
dateField When the metadata has a field called published in one of the
following formats then this function can render the date.
Mon, 06 Sep 2010 00:01:00 +0000Mon, 06 Sep 2010 00:01:00 UTCMon, 06 Sep 2010 00:01:002010-09-06T00:01:00+00002010-09-06T00:01:00Z2010-09-06T00:01:002010-09-06 00:01:00+00002010-09-06 00:01:00September 06, 2010 00:01 AMFollowing date-only formats are supported too (00:00:00 for time is
assumed)
2010-09-0606.09.2010September 06, 2010Alternatively, when the metadata has a field called path in a
folder/yyyy-mm-dd-title.extension format (the convention for pages)
and no published metadata field set, this function can render
the date. This pattern matches the file name or directory names
that begins with yyyy-mm-dd . For example:
folder/yyyy-mm-dd-titledist/main.extension .
In case of multiple matches, the rightmost one is used.
As another alternative, if none of the above matches, and the file has a
path which contains nested directories specifying a date, then that date
will be used. In other words, if the path is of the form
**/yyyymmdd/main.extension .
As above, in case of multiple matches, the rightmost one is used.
dateFieldWith :: TimeLocaleOutput time locale
-> StringDestination key
-> StringFormat to use on the date
-> Context aResulting context
This is an extended version of dateField that allows you to specify a time locale that is used for outputting the date. For more details, see dateField and formatTime.
getItemUTC :: (MonadMetadata m, MonadFail m)=> TimeLocaleOutput time locale
-> IdentifierInput page
-> m UTCTimeParsed UTCTime
Parser to try to extract and parse the time from the published
field or from the filename. See dateField for more information.
Exported for user convenience.
Get the time on which the actual file was last modified. This only works if there actually is an underlying file, of couse.
Creates a field with the last modification date of the underlying item.
modificationTimeFieldWith :: TimeLocaleTime output locale
-> StringKey
-> StringFormat
-> Context aResulting context
Creates a field with the last modification date of the underlying item in a custom localisation format (see formatTime).
Constantly reports any field as missing. Mostly for internal usage, it is the last choice in every context used in a template application.