1--------------------------------------------------------------------------------
2-- | An identifier is a type used to uniquely identify an item. An identifier is
3-- conceptually similar to a file path. Examples of identifiers are:
5-- * @posts/foo.markdown@
10{-# LANGUAGE DeriveDataTypeable #-}
11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
12module Hakyll.Core.Identifier
21--------------------------------------------------------------------------------
22import Control.Applicative ((<$>), (<*>))
23import Control.DeepSeq (NFData (..))
24import Data.List (intercalate)
25import System.FilePath (dropTrailingPathSeparator, splitPath)
28--------------------------------------------------------------------------------
29import Data.Binary (Binary (..))
30import Data.Typeable (Typeable)
31import GHC.Exts (IsString, fromString)
34--------------------------------------------------------------------------------
35data Identifier = Identifier
36 { identifierVersion :: Maybe String
37 , identifierPath :: String
38 } deriving (Eq, Ord, Typeable)
41--------------------------------------------------------------------------------
42instance Binary Identifier where
43 put (Identifier v p) = put v >> put p
44 get = Identifier <$> get <*> get
47--------------------------------------------------------------------------------
48instance IsString Identifier where
49 fromString = fromFilePath
52--------------------------------------------------------------------------------
53instance NFData Identifier where
54 rnf (Identifier v p) = rnf v `seq` rnf p `seq` ()
57--------------------------------------------------------------------------------
58instance Show Identifier where
59 show i = case identifierVersion i of
60 Nothing -> toFilePath i
61 Just v -> toFilePath i ++ " (" ++ v ++ ")"
64--------------------------------------------------------------------------------
65-- | Parse an identifier from a string
66fromFilePath :: String -> Identifier
67fromFilePath = Identifier Nothing .
68 intercalate "/" . filter (not . null) . split'
70 split' = map dropTrailingPathSeparator . splitPath
73--------------------------------------------------------------------------------
74-- | Convert an identifier to a relative 'FilePath'
75toFilePath :: Identifier -> FilePath
76toFilePath = identifierPath
79--------------------------------------------------------------------------------
80setVersion :: Maybe String -> Identifier -> Identifier
81setVersion v i = i {identifierVersion = v}
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