mostly works
This commit is contained in:
parent
a706933d96
commit
f3be772986
49
Shakefile.hs
49
Shakefile.hs
|
@ -81,6 +81,7 @@ sortByPostDate =
|
||||||
sortBy (\b a -> compare (Down (postDate a)) (Down (postDate b)))
|
sortBy (\b a -> compare (Down (postDate a)) (Down (postDate b)))
|
||||||
|
|
||||||
|
|
||||||
|
build :: FilePath -> FilePath
|
||||||
build = (</>) siteDir
|
build = (</>) siteDir
|
||||||
|
|
||||||
buildRules :: Rules ()
|
buildRules :: Rules ()
|
||||||
|
@ -89,33 +90,43 @@ buildRules = do
|
||||||
allRule
|
allRule
|
||||||
getPost <- mkGetPost
|
getPost <- mkGetPost
|
||||||
getPosts <- mkGetPosts getPost
|
getPosts <- mkGetPosts getPost
|
||||||
let cssDeps = map (siteDir </>) <$> getDirectoryFiles "" ["src/css/*.css"]
|
let cssDeps = map (siteDir </>) <$> getDirectoryFiles "src" ["css/*.css"]
|
||||||
|
-- build "index.html" %> \out -> do
|
||||||
|
-- css <- cssDeps
|
||||||
|
-- need $ css <> ["src/index.org"]
|
||||||
|
-- bp <- getPost "src/index.org"
|
||||||
|
-- eitherHtml <- liftIO $ Pandoc.runIO $ Writers.writeHtml5String def (postBody bp)
|
||||||
|
-- case eitherHtml of
|
||||||
|
-- Left _ -> fail "BAD"
|
||||||
|
-- Right htmlFile -> writeFile' out (T.unpack htmlFile)
|
||||||
|
build "//*.html" %> \out -> do
|
||||||
|
css <- cssDeps
|
||||||
|
let srcFile = "src" </> (dropDirectory1 (replaceExtension out "org"))
|
||||||
|
liftIO $ putText $ "need: " <> (T.pack srcFile) <> " <- " <> (T.pack out)
|
||||||
|
need $ css <> [srcFile]
|
||||||
|
bp <- getPost srcFile
|
||||||
|
eitherHtml <- liftIO $ Pandoc.runIO $ Writers.writeHtml5String def (postBody bp)
|
||||||
|
case eitherHtml of
|
||||||
|
Left _ -> fail "BAD"
|
||||||
|
Right htmlFile -> writeFile' out (T.unpack htmlFile)
|
||||||
build "articles.html" %> \out -> do
|
build "articles.html" %> \out -> do
|
||||||
css <- cssDeps
|
css <- cssDeps
|
||||||
posts <- getPosts ()
|
posts <- getPosts ()
|
||||||
need $ css <> map postUrl (sortByPostDate posts)
|
need $ css <> map postUrl (sortByPostDate posts)
|
||||||
let titles = T.unpack $ T.intercalate "\n" $ map postTitle posts
|
let titles = T.unpack $ T.intercalate "\n" $ map postTitle posts
|
||||||
writeFile' out titles
|
writeFile' out titles
|
||||||
build "index.html" %> \out -> do
|
build "css/*.css" %> \out -> do
|
||||||
css <- cssDeps
|
let src = "src" </> (dropDirectory1 out)
|
||||||
need $ css <> ["src/index.org"]
|
dst = out
|
||||||
bp <- getPost "src/index.org"
|
liftIO $ putText $ T.pack $ "src:" <> src <> " => dst: " <> dst
|
||||||
eitherHtml <- liftIO $ Pandoc.runIO $ Writers.writeHtml5String def (postBody bp)
|
copyFile' src dst
|
||||||
case eitherHtml of
|
|
||||||
Left _ -> fail "BAD"
|
|
||||||
Right htmlFile -> writeFile' out (T.unpack htmlFile)
|
|
||||||
-- build "//*.html" %> \out -> do
|
|
||||||
-- css <- cssDeps
|
|
||||||
-- let orgfile = dropDirectory1 out
|
|
||||||
-- post <- getPost orgfile
|
|
||||||
build "src/css/*.css" %> \out -> copyFile' (dropDirectory1 out) out
|
|
||||||
|
|
||||||
|
|
||||||
allRule :: Rules ()
|
allRule :: Rules ()
|
||||||
allRule =
|
allRule =
|
||||||
phony "all" $
|
phony "all" $ do
|
||||||
need (map build [ "index.html"
|
allOrgFiles <- getDirectoryFiles "src" ["//*.org"]
|
||||||
, "articles.html"])
|
let allHtmlFiles = map (flip replaceExtension "html") allOrgFiles
|
||||||
|
need (map build (allHtmlFiles <> ["index.html", "articles.html"]))
|
||||||
|
|
||||||
cleanRule :: Rules ()
|
cleanRule :: Rules ()
|
||||||
cleanRule =
|
cleanRule =
|
||||||
|
@ -123,6 +134,7 @@ cleanRule =
|
||||||
putInfo "Cleaning files in _site and _optim"
|
putInfo "Cleaning files in _site and _optim"
|
||||||
forM_ [siteDir,optimDir] $ flip removeFilesAfter ["//*"]
|
forM_ [siteDir,optimDir] $ flip removeFilesAfter ["//*"]
|
||||||
|
|
||||||
|
mkGetPost :: Rules (FilePath -> Action BlogPost)
|
||||||
mkGetPost = newCache $ \path -> do
|
mkGetPost = newCache $ \path -> do
|
||||||
fileContent <- readFile' path
|
fileContent <- readFile' path
|
||||||
eitherResult <- liftIO $ Pandoc.runIO $ Readers.readOrg def (T.pack fileContent)
|
eitherResult <- liftIO $ Pandoc.runIO $ Readers.readOrg def (T.pack fileContent)
|
||||||
|
@ -130,5 +142,6 @@ mkGetPost = newCache $ \path -> do
|
||||||
Left _ -> fail "BAD"
|
Left _ -> fail "BAD"
|
||||||
Right pandoc -> getBlogpostFromMetas path pandoc
|
Right pandoc -> getBlogpostFromMetas path pandoc
|
||||||
|
|
||||||
|
mkGetPosts :: (FilePath -> Action b) -> Rules (() -> Action [b])
|
||||||
mkGetPosts getPost =
|
mkGetPosts getPost =
|
||||||
newCache $ \() -> mapM getPost =<< getDirectoryFiles "" ["src/posts//*.org"]
|
newCache $ \() -> mapM getPost =<< getDirectoryFiles "" ["src/posts//*.org"]
|
||||||
|
|
Loading…
Reference in a new issue