acatalepsie/src/Projects.hs

63 lines
1.9 KiB
Haskell
Raw Normal View History

2020-09-25 23:45:58 +00:00
module Projects (build) where
import Data.Char (digitToInt)
import Common
import Types
import Config
import Templates
2020-09-26 23:33:50 +00:00
import Lucid
2020-09-25 23:45:58 +00:00
getKey :: String -> (Int, String)
getKey xs = getKey' 0 xs
where
getKey' :: Int -> String -> (Int, String)
getKey' k (x : xs) | x >= '0' && x <= '9' =
getKey' (k * 10 + digitToInt x) xs
getKey' k ('-' : xs) = (k, xs)
getKey' k xs = (k, xs)
buildProject :: Recipe IO a (Project, FilePath)
buildProject = do
match "*" copyFile
name <- takeBaseName <$> getCurrentDir
children <- buildChildren name
watch children $ matchFile "index.*" do
(meta, doc) <- readPandocMetadataWith ropts
renderPandocWith wopts doc <&> renderProject meta children
>>= saveFileAs (-<.> "html")
>> (meta,) <$> getCurrentDir
where
buildChildren :: String -> Recipe IO a [(String, FilePath)]
buildChildren name = match "pages/*" do
filepath <- getInput
let (key, file) = getKey $ takeFileName filepath
(TitledPage title _, doc) <- readPandocMetadataWith ropts
renderPandocWith wopts doc
2020-09-26 23:33:50 +00:00
<&> toHtmlRaw
2020-09-25 23:45:58 +00:00
<&> outerWith (def {Config.title = fromString title})
>>= saveFileAs (const $ file -<.> "html")
<&> (title,)
-- sorted = sortBy (\(_, x, _, _, _) (_, y, _, _, _) -> compare x y) children
-- match "pages/*" do
-- renderPandocWith wopts doc
-- <&> outerWith (def {title = name})
-- >>= saveFileAs (const $ file -<.> "html")
-- <&> (name,)
-- -}
build :: Task IO ()
build = do
projects <- matchDir "projects/*/" buildProject
watch projects $ match_ "./projects.rst" do
txt <- compilePandocWith def wopts
write "projects.html" $ renderProjects txt projects