import Data.List (intercalate)
import Data.String hiding (unlines)
import Data.Text hiding (map, init, length, splitAt)
-import Data.Text.IO (putStrLn, putStr)
+import Data.Text.IO (putStrLn, putStr, writeFile)
import Data.Text.Lazy (toStrict)
import Data.Text.Template
import Data.Time.Clock.POSIX
import Lib
-import Prelude hiding (putStrLn, putStr, init, unlines)
+import Prelude hiding (putStrLn, putStr, init, unlines, writeFile)
import Prompts
import System.Directory
import System.Directory (doesFileExist)
themes <- allFilesIn $ home ++ "/.xyz/themes"
projectSpec <- initPrompt (map pack themes)
createDirectory "entries"
- writeFile "xyz.json" . encode . toJSObject $ projectSpec
+ writeFile "xyz.json" . pack . encode . toJSObject $ projectSpec
putStrLn "\n\nInitialised empty project"
build :: IO ()
homeDir <- getHomeDirectory
entrySpec <- entryPrompt
entryNum <- fmap (show . (+1) . length) $ allFilesIn "entries"
- stamp <- fmap (show . round) getPOSIXTime
+ stamp <- fmap (pack . show . round) getPOSIXTime
videoTemplate <- readFile (homeDir ++ "/.xyz/entry-video.txt") >>= return . template . fromString
normalTemplate <- readFile (homeDir ++ "/.xyz/entry.txt") >>= return . template . fromString
- --let filename = "entries/" ++ (show entryNum) ++ "-" ++ (unpack . (toLower. replace " " "-") $ pack entryName) ++ ".txt"
- case entrySpec of
- Just (title, videoSpec) -> do
- let filename = "entries/" ++ entryNum ++ "-" ++ (unpack . slugify $ title) ++ ".txt"
- case videoSpec of
- Just (videoId, videoFilename) -> putStrLn "oh jimmy"
- Nothing -> putStrLn "oh bimmy"
+ let rawEntry = case entrySpec of
+ Just (title, videoSpec) -> do
+ let baseContext = [("timestamp", stamp), ("title", title)]
+ case videoSpec of
+ Just (videoId, videoFilename) -> (title, toStrict . render videoTemplate $ context $ baseContext ++ [("videoid", videoId), ("videofilename", videoFilename)])
+ Nothing -> (title, toStrict . render normalTemplate $ context baseContext)
+ let fileName = "entries/" ++ entryNum ++ "-" ++ (unpack . slugify $ fst rawEntry) ++ ".txt"
+ writeFile fileName $ snd rawEntry
- putStrLn "lel"
- -- case video of
- -- Just (videoId, videoFilename) -> do
- -- let tmplContext = context $ [("timestamp", fromString . show $ (stamp::Integer)), ("title", pack entryName), ("videofilename", pack $ videoFilename), ("videoid", pack videoId)]
- -- let rawEntry = unpack . toStrict $ render videoTemplate tmplContext
- -- writeFile filename rawEntry
- -- callCommand $ "youtube-dl -f 'webm[height<1080]+bestaudio' \"https://www.youtube.com/watch?v=" ++ videoId ++ "\" -o 'build/videos/" ++ videoFilename ++ "'"
- -- Nothing -> do
- -- let tmplContext = context $ [("timestamp", fromString . show $ (stamp::Integer)), ("title", pack entryName)]
- -- let rawEntry = unpack . toStrict $ render normalTemplate tmplContext
- -- writeFile filename rawEntry
+ callCommand $ "nano " ++ fileName
- -- (putStrLn $ ("Created " ++ filename)) >> build
+ push <- pushPrompt
+ case push of
+ True -> do callCommand . unpack $ "git add . && git commit -m \"" +++ (fst rawEntry) +++ "\" && git push"
+ False -> return ()
- -- push <- yornPrompt "Do you want to push this entry?"
-
- -- case push of
- -- True -> do callCommand $ "git add . && git commit -m \"" ++ entryName ++ "\" && git push"
- -- False -> return ()
-
- -- putStrLn "Thanks for using xyz!"
+ putStrLn "Thanks for using xyz!"
usage :: IO ()
usage = putStr . ununlines $ [
-module Prompts (
- textPrompt,
- nonEmptyTextPrompt,
- yornPrompt,
- subPrompt,
- entryPrompt,
- initPrompt
- ) where
+module Prompts (entryPrompt, initPrompt, pushPrompt) where
import Util
import Prelude hiding (getLine, null, putStrLn, putStr, unlines)
"y" -> Right True
"n" -> Right False
_ -> Left "Please answer with y or n"
- prompt (xs +++ " (y/n):") getOneText v
+ prompt (xs +++ " (y/n): ") getOneText v
listPrompt :: Text -> [Text] -> IO Text
listPrompt xs options = do
nonEmptyTextPrompt "Enter a short description for your project: ",
listPrompt "Which theme would you like to use?" themes
]
+
+pushPrompt = yornPrompt "Do you want to push this entry?"