Hakyll.Web.Template.Context

hakyll-4.7.5.1: A static website compiler library

Safe Haskell | None
Language | Haskell98

Hakyll.Web.Template.Context

Synopsis

- data ContextField
  - = StringField String
  - | forall a . ListField (Context a) [Item a]
- newtype Context a = Context {
  - unContext :: String -> [String] -> Item a -> Compiler ContextField
  }
- field :: String -> (Item a -> Compiler String) -> Context a
- boolField :: String -> (Item a -> Bool) -> Context a
- constField :: String -> String -> Context a
- listField :: String -> Context a -> Compiler [Item a] -> Context b
- listFieldWith :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b
- functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a
- mapContext :: (String -> String) -> Context a -> Context a
- defaultContext :: Context String
- bodyField :: String -> Context String
- metadataField :: Context a
- urlField :: String -> Context a
- pathField :: String -> Context a
- titleField :: String -> Context a
- dateField :: String -> String -> Context a
- dateFieldWith :: TimeLocale -> String -> String -> Context a
- getItemUTC :: MonadMetadata m => TimeLocale -> Identifier -> m UTCTime
- getItemModificationTime :: Identifier -> Compiler UTCTime
- modificationTimeField :: String -> String -> Context a
- modificationTimeFieldWith :: TimeLocale -> String -> String -> Context a
- teaserField :: String -> Snapshot -> Context String
- teaserFieldWithSeparator :: String -> String -> Snapshot -> Context String
- missingField :: Context a

# Documentation

data ContextField

Mostly for internal usage

Constructors

StringField String |
forall a . ListField (Context a) [Item a] |

newtype Context 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" f2

the 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

Constructors

Context |
Fields unContext :: String -> [String] -> Item a -> Compiler ContextField

Instances

Monoid (Context a) |

field

Arguments

:: String | Key
-> (Item a -> Compiler String) | Function that constructs a value based on the item
-> Context a |

Constructs a new field in the 'Context.'

boolField :: String -> (Item a -> Bool) -> Context a

Creates a `field` to use with the `$if()$` template macro.

constField :: String -> String -> Context a

Creates a `field` that does not depend on the `Item`

listField :: String -> Context a -> Compiler [Item a] -> Context b

listFieldWith :: String -> Context a -> (Item b -> Compiler [Item a]) -> Context b

functionField :: String -> ([String] -> Item a -> Compiler String) -> Context a

mapContext :: (String -> String) -> Context a -> Context a

defaultContext :: Context String

A context that contains (in that order)

1. A `$body$` field
2. Metadata fields
3. A `$url$` `urlField`
4. A `$path$` `pathField`
5. A `$title$` `titleField`

bodyField :: String -> Context String

Constructs a `field` that contains the body of the item.

metadataField :: Context a

Map any field to its metadata value, if present

urlField :: String -> Context a

Absolute url to the resulting item

pathField :: String -> Context a

Filepath of the underlying file of the item

titleField :: String -> Context a

This title `field` takes the basename of the underlying file by default

dateField

Arguments

:: String | Key in which the rendered date should be placed
-> String | Format to use on the date
-> Context a | Resulting context

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 +0000

-     Mon, 06 Sep 2010 00:01:00 UTC

-     Mon, 06 Sep 2010 00:01:00

-     2010-09-06T00:01:00+0000

-     2010-09-06T00:01:00Z

-     2010-09-06T00:01:00

-     2010-09-06 00:01:00+0000

-     2010-09-06 00:01:00

-     September 06, 2010 00:01 AM

Following date-only formats are supported too (`00:00:00` for time is assumed)

-     2010-09-06

-     September 06, 2010

Alternatively, 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.

dateFieldWith

Arguments

:: TimeLocale | Output time locale
-> String | Destination key
-> String | Format to use on the date
-> Context a | Resulting 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`.

getItemUTC

Arguments

:: MonadMetadata m |
=> TimeLocale | Output time locale
-> Identifier | Input page
-> m UTCTime | Parsed 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.

getItemModificationTime :: Identifier -> Compiler UTCTime

Get the time on which the actual file was last modified. This only works if there actually is an underlying file, of couse.

modificationTimeField

Arguments

:: String | Key
-> String | Format
-> Context a | Resuting context

modificationTimeFieldWith

Arguments

:: TimeLocale | Time output locale
-> String | Key
-> String | Format
-> Context a | Resulting context

teaserField

Arguments

:: String | Key to use
-> Snapshot | Snapshot to load
-> Context String | Resulting context

A context with "teaser" key which contain a teaser of the item. The item is loaded from the given snapshot (which should be saved in the user code before any templates are applied).

teaserFieldWithSeparator

Arguments

:: String | Separator to use
-> String | Key to use
-> Snapshot | Snapshot to load
-> Context String | Resulting context

A context with "teaser" key which contain a teaser of the item, defined as the snapshot content before the teaser separator. The item is loaded from the given snapshot (which should be saved in the user code before any templates are applied).

missingField :: Context a