1-- | Once a target is compiled, the user usually wants to save it to the disk.
2-- This is where the 'Route' type comes in; it determines where a certain target
5-- When a route is applied (using 'runRoute'), it either returns a 'Just'
6-- 'FilePath' (meaning the target should be written to that file path), or
7-- 'Nothing' (meaning this target should not be written anywhere).
9module Hakyll.Core.Route
17import Data.Monoid (Monoid, mempty, mappend)
18import Control.Monad (mplus)
19import System.FilePath (replaceExtension)
21import Hakyll.Core.Identifier
22import Hakyll.Core.Identifier.Pattern
24-- | Type used for a route
26newtype Route = Route {unRoute :: Identifier -> Maybe FilePath}
28instance Monoid Route where
29 mempty = Route $ const Nothing
30 mappend (Route f) (Route g) = Route $ \id' -> f id' `mplus` g id'
32-- | Apply a route to an identifier
34runRoute :: Route -> Identifier -> Maybe FilePath
37-- | A route that uses the identifier as filepath. For example, the target with
38-- ID @foo\/bar@ will be written to the file @foo\/bar@.
41idRoute = Route $ Just . toFilePath
43-- | Set (or replace) the extension of a route.
47-- > runRoute (setExtension "html") "foo/bar"
51-- > Just "foo/bar.html"
55-- > runRoute (setExtension "html") "posts/the-art-of-trolling.markdown"
59-- > Just "posts/the-art-of-trolling.html"
61setExtension :: String -> Route
62setExtension exension = Route $ fmap (flip replaceExtension exension)
65-- | Modify a route: apply the route if the identifier matches the given
66-- pattern, fail otherwise.
68ifMatch :: Pattern -> Route -> Route
69ifMatch pattern (Route route) = Route $ \id' ->
70 if doesMatch pattern id' then route id'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list