@@ -7,10 +7,11 @@ import Control.Monad.Reader
7
7
import Data.Map (Map )
8
8
import qualified Data.Map as M
9
9
import Data.Maybe (fromJust )
10
- import Data.Text (pack )
10
+ import Data.Text (pack , unpack )
11
11
import qualified Data.Text as T
12
12
import Data.Time.Clock
13
13
import Data.Time.Format
14
+ import System.FilePath (takeBaseName )
14
15
import Turtle hiding (f , x )
15
16
16
17
-- | Currently we use stringly-typed values everywhere
@@ -59,20 +60,24 @@ postR thing category = do
59
60
, blog_spec = spec
60
61
, pathFn = f}) <- ask
61
62
let (cmd, remote, pth) = rsyncTup con
62
- liftIO $ putStrLn show (category, spec)
63
+ liftIO $ putStrLn $ show (category, spec)
63
64
tau <- liftIO $ getCurrentTime
64
65
if knownCategory category spec
65
66
then liftIO $ rsyncSend cmd thing remote $ f category thing pth tau
66
67
else return $ ExitFailure 5
67
68
68
69
-- | Default path function (works with my blog :))
69
70
defaultPathFn :: FormatTime t => BlogCat -> Path -> Path -> t -> Path
70
- defaultPathFn " draft" l r t = r <^> slash " drafts" <^> (slash $ stamp l t)
71
- defaultPathFn category l r t = r <^> slash " posts" <^> slash category <^> (slash $ stamp l t)
71
+ defaultPathFn " draft" l r t = r <^> slash " drafts" <^> (slash $ stamp (bn l) t)
72
+ defaultPathFn category l r t = r <^> slash " posts" <^> slash category <^> (slash $ stamp (bn l) t)
73
+
74
+ -- | Take basename of a filePath represented as Text
75
+ bn :: Text -> Text
76
+ bn = pack . takeBaseName . unpack
72
77
73
78
-- | Prefix a filename with a default hakyll timestamp
74
79
stamp :: FormatTime t => Text -> t -> Text
75
- stamp x tau = x <^> (pack $ formatTime defaultTimeLocale " %Y-%m-%d" tau)
80
+ stamp x tau = (pack $ formatTime defaultTimeLocale " %Y-%m-%d" tau) <^> x
76
81
77
82
-- | Rsync a file using Turtle's ``shell`` function.
78
83
rsyncSend :: Cmd -> File -> Remote -> Path -> IO ExitCode
0 commit comments