aboutsummaryrefslogtreecommitdiff
path: root/Utils.hs
diff options
context:
space:
mode:
authorMiroslav Kratochvil <miroslav.kratochvil@uni.lu>2023-10-16 11:37:27 +0200
committerMiroslav Kratochvil <miroslav.kratochvil@uni.lu>2023-10-16 11:37:27 +0200
commitfee144a3eca7e35b998061032f87d1e053999c6d (patch)
tree4475ab5ad29f7ad4acbe875fe791ee1da68e8f5a /Utils.hs
parent4cdbf598c0e343384f8af3421d332ed15d8afe4e (diff)
parent005b69dd472811d7a8e623c3761d476b5584b92c (diff)
downloadreploy-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.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/Utils.hs b/Utils.hs
index 4426b68..9c901cc 100644
--- a/Utils.hs
+++ b/Utils.hs
@@ -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 ()