diff options
| author | Miroslav Kratochvil <miroslav.kratochvil@uni.lu> | 2023-10-16 11:37:27 +0200 |
|---|---|---|
| committer | Miroslav Kratochvil <miroslav.kratochvil@uni.lu> | 2023-10-16 11:37:27 +0200 |
| commit | fee144a3eca7e35b998061032f87d1e053999c6d (patch) | |
| tree | 4475ab5ad29f7ad4acbe875fe791ee1da68e8f5a /Utils.hs | |
| parent | 4cdbf598c0e343384f8af3421d332ed15d8afe4e (diff) | |
| parent | 005b69dd472811d7a8e623c3761d476b5584b92c (diff) | |
| download | reploy-fee144a3eca7e35b998061032f87d1e053999c6d.tar.gz reploy-fee144a3eca7e35b998061032f87d1e053999c6d.tar.bz2 | |
Merge branch 'mk-howtocards-fixes' into 'master'
updates required for howto-cards
See merge request lcsb/sps/reploy!5
Diffstat (limited to 'Utils.hs')
| -rw-r--r-- | Utils.hs | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -22,12 +22,13 @@ import Control.Monad.IO.Class import Data.List.Extra (stripSuffix) import Data.Maybe (isJust) import qualified Data.Text as T +import Lens.Micro.Mtl import System.Directory ( createDirectoryIfMissing , doesDirectoryExist , getDirectoryContents ) -import System.FilePath ((</>), takeDirectory) +import System.FilePath ((</>), splitDirectories, takeDirectory) import Text.Pandoc.Definition import qualified Text.Pandoc.Walk import Types @@ -116,6 +117,24 @@ getRecursiveContents ignore top = go "" else return [rel] return $ concat paths +-- | A nice tool interned from Relude. +foldMapM :: (Monoid b, Monad m, Foldable f) => (a -> m b) -> f a -> m b +foldMapM f xs = foldr step return xs mempty + where + step x r z = f x >>= \y -> r $! z `mappend` y + +-- | Source paths from a source-y directory. The paths that have to be ignored +-- by config `notSourceDirs` are omitted. +sourcePaths :: Monoid a => FilePath -> (FilePath -> Site a) -> Site a +sourcePaths fp process = do + notSource <- use notSourceDirs + let ignoreDir ds + | null ds = False + | last ds `elem` notSource = True + | otherwise = False + io (getRecursiveContents (pure . ignoreDir . splitDirectories) fp) >>= + foldMapM process + -- | Given a path to a file, try to make the path writable by making all -- directories on the path. (Interned from Hakyll.) makeDirectories :: FilePath -> IO () |
