2023-11-05 18:34:15 +08:00
|
|
|
module Main where
|
|
|
|
|
2023-11-07 08:23:04 +08:00
|
|
|
import Data.Function (on)
|
2023-11-05 18:34:15 +08:00
|
|
|
import Data.List (isPrefixOf, sortBy)
|
|
|
|
import Main.Base
|
|
|
|
import Main.Input
|
|
|
|
import Main.Output
|
|
|
|
import System.Directory (listDirectory)
|
|
|
|
import System.FilePath ((</>))
|
|
|
|
|
|
|
|
-- Parse holiday data
|
|
|
|
-- Generate ics files
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
-- read files
|
|
|
|
filesInDir <- listDirectory "./data"
|
|
|
|
let files = filter ("20" `isPrefixOf`) filesInDir
|
|
|
|
contents <- mapM (readFile . ("./data" </>)) files
|
|
|
|
|
|
|
|
-- parse data
|
2023-11-07 08:23:04 +08:00
|
|
|
let calendarYearly = zipWith parseFile files contents
|
|
|
|
debug calendarYearly
|
2023-11-05 18:34:15 +08:00
|
|
|
|
|
|
|
-- write files
|
2023-11-07 08:23:04 +08:00
|
|
|
let calendar = calendarYearly >>= join
|
|
|
|
writeFile "./docs/index.html" $ generate calendar Both
|
2023-11-05 18:34:15 +08:00
|
|
|
|
2023-11-07 08:23:04 +08:00
|
|
|
writeFile "./docs/main.ics" $ generate calendar Both
|
|
|
|
writeFile "./docs/rest.ics" $ generate calendar Rest
|
|
|
|
writeFile "./docs/work.ics" $ generate calendar Work
|
2023-11-05 18:34:15 +08:00
|
|
|
|
|
|
|
-- Log holiday data ordered by each year
|
2023-11-07 08:23:04 +08:00
|
|
|
debug :: [Yearly] -> IO ()
|
|
|
|
debug yearly =
|
|
|
|
let orderByYear = sortBy (compare `on` year) yearly
|
|
|
|
printByDate holiday = do
|
|
|
|
putStrLn $ "\nYear " ++ year holiday
|
|
|
|
mapM_ print $ sortByDate $ join holiday
|
|
|
|
in mapM_ printByDate orderByYear
|