Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (65 sloc) 2.529 kb
fbf5e3d @jgm Initial commit.
authored
1 {-
2 Copyright (C) 2009 John MacFarlane <jgm@berkeley.edu>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -}
18
19 module Main
20 where
21 import Paths_yst
22 import Yst.Util
23 import Yst.Config
24 import Yst.Build
25 import System.FilePath
26 import System.Environment
27 import System.Directory
28 import System.Exit
2c8eee0 @jgm Fixed to compile with GHC 6.12.
authored
29 -- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
30 -- So we use System.IO.UTF8 only if we have an earlier version
31 #if MIN_VERSION_base(4,2,0)
32 import System.IO (hPutStrLn)
33 #else
34 import Prelude hiding (readFile, putStrLn, print, writeFile)
fbf5e3d @jgm Initial commit.
authored
35 import System.IO.UTF8
2c8eee0 @jgm Fixed to compile with GHC 6.12.
authored
36 #endif
fbf5e3d @jgm Initial commit.
authored
37 import System.IO (stderr)
38 import Control.Monad
39
40 createSite :: FilePath -> IO ()
41 createSite path = do
42 existsd <- doesDirectoryExist path
43 existsf <- doesFileExist path
44 when (existsd || existsf) $ do
45 hPutStrLn stderr $ "Aborting! " ++ path ++ " already exists."
46 exitWith $ ExitFailure 5
47 demoDir <- getDataFileName "demo"
48 contents <- liftM (filter (/=".") . map (makeRelative demoDir)) $ getDirectoryContentsRecursive demoDir
49 forM_ contents $ \file -> do
50 let dest = path </> file
51 createDirectoryIfMissing True $ takeDirectory dest
52 copyFile (demoDir </> file) dest
aa58103 @jgm Put README in starter sites.
authored
53 readme <- getDataFileName "README.markdown"
54 copyFile readme (path </> "README")
fbf5e3d @jgm Initial commit.
authored
55 hPutStrLn stderr $ "Created starter site in " ++ path
56
57 usageMessage :: IO ()
58 usageMessage = hPutStrLn stderr $
59 "yst - create static website from string templates and YAML data\n" ++
60 "Usage:\n" ++
61 "yst [-f CONFIGFILE] # build website\n" ++
62 "yst create DIRECTORY # create starter site in DIRECTORY"
63
64 main :: IO ()
65 main = do
66 args <- getArgs
67 site <- case args of
68 ["-f",x] -> parseConfigFile x
69 [] -> parseConfigFile "config.yaml"
70 ["create",d] -> createSite d >> exitWith ExitSuccess
71 _ -> usageMessage >> exitWith (ExitFailure 1)
72 buildSite site
73
Something went wrong with that request. Please try again.