Provides various functions to manipulate the metadata fields of a page
- getField :: String -> Page a -> String
- getFieldMaybe :: String -> Page a -> Maybe String
- setField :: String -> String -> Page a -> Page a
- trySetField :: String -> String -> Page a -> Page a
- setFieldA :: Arrow a => String -> a x String -> a (Page b, x) (Page b)
- setFieldPage :: String -> Identifier (Page String) -> Compiler (Page a) (Page a)
- renderField :: String -> String -> (String -> String) -> Page a -> Page a
- changeField :: String -> (String -> String) -> Page a -> Page a
- copyField :: String -> String -> Page a -> Page a
- renderDateField :: String -> String -> String -> Page a -> Page a
- renderDateFieldWith :: TimeLocale -> String -> String -> String -> Page a -> Page a
- copyBodyToField :: String -> Page String -> Page String
- copyBodyFromField :: String -> Page String -> Page String
Documentation
Get a metadata field. If the field does not exist, the empty string is returned.
Get a field in a Maybe
wrapper
Version of trySetField
which overrides any previous value
Add a metadata field. If the field already exists, it is not overwritten.
:: String | Key to add the page under |
-> Identifier (Page String) | Page to add |
-> Compiler (Page a) (Page a) | Page compiler |
Set a field of a page to the contents of another page
:: String | Key of which the value should be copied |
-> String | Key the value should be copied to |
-> (String -> String) | Function to apply on the value |
-> Page a | Page on which this should be applied |
-> Page a | Resulting page |
Do something with a metadata value, but keep the old value as well. If the
key given is not present in the metadata, nothing will happen. If the source
and destination keys are the same, the value will be changed (but you should
use changeField
for this purpose).
:: String | Key to change. |
-> (String -> String) | Function to apply on the value. |
-> Page a | Page to change |
-> Page a | Resulting page |
Change a metadata value.
import Data.Char (toUpper) changeField "title" (map toUpper)
Will put the title in UPPERCASE.
:: String | Key to copy |
-> String | Destination to copy to |
-> Page a | Page on which this should be applied |
-> Page a | Resulting page |
Make a copy of a metadata field (put the value belonging to a certain key under some other key as well)
:: String | Key in which the rendered date should be placed |
-> String | Format to use on the date |
-> String | Default value, in case the date cannot be parsed |
-> Page a | Page on which this should be applied |
-> Page a | Resulting page |
When the metadata has a field called path
in a
folder/yyyy-mm-dd-title.extension
format (the convention for pages),
this function can render the date.
renderDate "date" "%B %e, %Y" "Date unknown"
Will render something like January 32, 2010
.
:: TimeLocale | Output time locale |
-> String | Destination key |
-> String | Format to use on the date |
-> String | Default value |
-> Page a | Target page |
-> Page a | Resulting page |
This is an extended version of renderDateField
that allows you to
specify a time locale that is used for outputting the date. For more
details, see renderDateField
.
Copy the body of a page to a metadata field