summaryrefslogtreecommitdiffstats
path: root/src/MdBlocks/Repository.hs
blob: 9bacaf299ed231c899825cf777ea0d0152ebe9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# LANGUAGE OverloadedStrings #-}

module MdBlocks.Repository where

import Data.Text.IO as T
import System.Directory

import MdBlocks.Parser
import MdBlocks.Types

loadBlocks :: FilePath -> IO [Block]
loadBlocks fp = do
  txt <- T.readFile fp
  pure (parseFile fp txt)

findMarkdownFiles :: FilePath -> IO [FilePath]
findMarkdownFiles root = do
  xs <- listDirectory root
  pure
    [ root <> "/" <> x
    | x <- xs
    , takeExtension x == ".md"
    ]
  where
    takeExtension =
      reverse . takeWhile (/='.') . reverse