hakyll-3.1.2.0: A simple static site generator library.

Hakyll.Core.Identifier.Pattern

Description

Module providing pattern matching and capturing on Identifiers. Patterns come in two kinds:

  • Simple glob patterns, like foo/*;
  • Custom, arbitrary predicates of the type Identifier -> Bool.

They both have advantages and disadvantages. By default, globs are used, unless you construct your Pattern using the predicate function.

A very simple pattern could be, for example, foo/bar. This pattern will only match the exact foo/bar identifier.

To match more than one identifier, there are different captures that one can use:

  • *: matches at most one element of an identifier;
  • **: matches one or more elements of an identifier.

Some examples:

  • foo/* will match foo/bar and foo/foo, but not foo/bar/qux;
  • ** will match any identifier;
  • foo/** will match foo/bar and foo/bar/qux, but not bar/foo;
  • foo/*.html will match all HTML files in the foo/ directory.

The capture function allows the user to get access to the elements captured by the capture elements in the pattern.

Synopsis

Documentation

data Pattern Source

Type that allows matching on identifiers

parseGlob :: String -> PatternSource

Parse a pattern from a string

predicate :: (Identifier -> Bool) -> PatternSource

Create a Pattern from an arbitrary predicate

Example:

 predicate (\i -> matches "foo/*" i && not (matches "foo/bar" i))

regex :: String -> PatternSource

Create a Pattern from a regex

Example:

 regex "^foo/[^x]*$

inGroup :: Maybe String -> PatternSource

Create a Pattern which matches if the identifier is in a certain group (or in no group)

matches :: Pattern -> Identifier -> BoolSource

Check if an identifier matches a pattern

filterMatches :: Pattern -> [Identifier] -> [Identifier]Source

Given a list of identifiers, retain only those who match the given pattern

capture :: Pattern -> Identifier -> Maybe [String]Source

Match a glob against a pattern, generating a list of captures

fromCapture :: Pattern -> String -> IdentifierSource

Create an identifier from a pattern by filling in the captures with a given string

Example:

 fromCapture (parseGlob "tags/*") "foo"

Result:

 "tags/foo"

fromCaptures :: Pattern -> [String] -> IdentifierSource

Create an identifier from a pattern by filling in the captures with the given list of strings