Skip to content

Commit 0870e96

Browse files
committedAug 18, 2015
It works.
1 parent ff9046a commit 0870e96

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed
 

Diff for: ‎blog.cabal

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Library
1818
mtl,
1919
containers,
2020
text,
21-
time
21+
time,
22+
filepath
2223

2324
Hs-Source-Dirs: src
2425
GHC-Options: -Wall
@@ -32,7 +33,8 @@ Executable blog
3233
mtl,
3334
containers,
3435
text,
35-
time
36+
time,
37+
filepath
3638

3739
Hs-source-dirs: src
3840
GHC-Options: -Wall

Diff for: ‎project.nix

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
{ mkDerivation, base, containers, haskonf, mtl, stdenv, text, time
2-
, turtle
1+
{ mkDerivation, base, containers, filepath, haskonf, mtl, stdenv
2+
, text, time, turtle
33
}:
44
mkDerivation {
55
pname = "blog";
66
version = "0.0.1";
77
src = ./.;
88
isLibrary = true;
99
isExecutable = true;
10-
buildDepends = [ base containers haskonf mtl text time turtle ];
10+
buildDepends = [
11+
base containers filepath haskonf mtl text time turtle
12+
];
1113
description = "CLI to instantiate/publish hakyll posts";
1214
license = stdenv.lib.licenses.bsd2;
1315
}

Diff for: ‎src/Blog.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import Control.Monad.Reader
77
import Data.Map (Map)
88
import qualified Data.Map as M
99
import Data.Maybe (fromJust)
10-
import Data.Text (pack)
10+
import Data.Text (pack, unpack)
1111
import qualified Data.Text as T
1212
import Data.Time.Clock
1313
import Data.Time.Format
14+
import System.FilePath (takeBaseName)
1415
import Turtle hiding (f, x)
1516

1617
-- | Currently we use stringly-typed values everywhere
@@ -59,20 +60,24 @@ postR thing category = do
5960
, blog_spec = spec
6061
, pathFn = f}) <- ask
6162
let (cmd, remote, pth) = rsyncTup con
62-
liftIO $ putStrLn show (category, spec)
63+
liftIO $ putStrLn $ show (category, spec)
6364
tau <- liftIO $ getCurrentTime
6465
if knownCategory category spec
6566
then liftIO $ rsyncSend cmd thing remote $ f category thing pth tau
6667
else return $ ExitFailure 5
6768

6869
-- | Default path function (works with my blog :))
6970
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
7277

7378
-- | Prefix a filename with a default hakyll timestamp
7479
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
7681

7782
-- | Rsync a file using Turtle's ``shell`` function.
7883
rsyncSend :: Cmd -> File -> Remote -> Path -> IO ExitCode

0 commit comments

Comments
 (0)
Please sign in to comment.