Safe Haskell | None |
---|
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
- renderModificationTime :: String -> String -> Compiler (Page String) (Page String)
- renderModificationTimeWith :: TimeLocale -> String -> String -> Compiler (Page String) (Page String)
- copyBodyToField :: String -> Page String -> Page String
- copyBodyFromField :: String -> Page String -> Page String
- comparePagesByDate :: Page a -> Page a -> Ordering
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 published
in one of the
following formats then this function can render the date.
-
Sun, 01 Feb 2000 13:00:00 UT
(RSS date format) -
2000-02-01T13:00:00Z
(Atom date format) -
February 1, 2000 1:00 PM
(PM is usually uppercase) -
February 1, 2000
(assumes 12:00 AM for the time)
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.
renderDateField "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
.
:: String | Destination key |
-> String | Format to use on the time |
-> Compiler (Page String) (Page String) | Resulting compiler |
Set the modification time as a field in the page
Copy the body of a page to a metadata field
Copy a metadata field to the page body
comparePagesByDate :: Page a -> Page a -> OrderingSource
Compare pages by the date and time parsed as in renderDateField
,
where LT
implies earlier, and GT
implies later. For more details,
see renderDateField
.