aboutsummaryrefslogtreecommitdiff
path: root/site.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <miroslav.kratochvil@uni.lu>2023-06-08 13:51:30 +0200
committerMirek Kratochvil <miroslav.kratochvil@uni.lu>2023-06-08 13:51:30 +0200
commit4c1f0f9a4e4ee68aab098a61d3749960f568ec7f (patch)
tree5ebcf8c0e7b5e60cfd7bac12e78fc01d175d95ef /site.hs
parentb385e1b3f7982cfc2fce28e4e60c740d39cc97f8 (diff)
downloadreploy-4c1f0f9a4e4ee68aab098a61d3749960f568ec7f.tar.gz
reploy-4c1f0f9a4e4ee68aab098a61d3749960f568ec7f.tar.bz2
install files properly
Diffstat (limited to 'site.hs')
-rw-r--r--site.hs33
1 files changed, 16 insertions, 17 deletions
diff --git a/site.hs b/site.hs
index dafe23f..affb61d 100644
--- a/site.hs
+++ b/site.hs
@@ -4,6 +4,7 @@
module Main where
import Control.Monad ((>=>), unless, when)
+import Control.Monad.Extra (whenM)
import Control.Monad.Trans.State.Lazy
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString.Lazy as B
@@ -27,6 +28,7 @@ import System.FilePath
, isAbsolute
, splitDirectories
, splitPath
+ , takeDirectory
, takeFileName
)
import qualified Text.Mustache as Mu
@@ -41,11 +43,11 @@ import Utils
-- | Load the pages from a directory and add them to `pages`.
sourcePages :: FilePath -> Site ()
-sourcePages fp = do
- links <-
- io $ filter (hasSuffix ".md" . last . splitPath) <$>
- getRecursiveContents (pure . const False) fp
- traverse_ loadPage (map (fp </>) links)
+sourcePages fp =
+ io
+ (map (fp </>) . filter (hasSuffix ".md" . last . splitPath) <$>
+ getRecursiveContents (pure . const False) fp) >>=
+ traverse_ loadPage
{- | Extract `PageInfo` about a single page and save it into `pages` in
- `SiteState`. -}
@@ -122,18 +124,17 @@ checkTarget fp = do
-- | Prepend the root path to the given link
rootUrl :: FilePath -> Site FilePath
-rootUrl = pure . ('/' :)
+rootUrl fp = (</> fp) <$> use urlBase
-- | Process a single link pointing out from a page.
-processLink :: FilePath -> String -> Site String
-processLink base l = do
+processLink :: FilePath -> FilePath -> Site String
+processLink base l =
if isAbsolute l
- then pure l -- TODO prepend the root url
- else (do io . putStrLn $ "rel:" ++ l
- pure $ '/' : (base </> l) -- TODO
- )
+ then rootUrl l
+ else installFile (base </> l) >>= rootUrl
-- | Get a mount point of the page into the correct location.
+-- (Pages are currently mounted just to the root.)
pageFilename :: FilePath -> Site FilePath
pageFilename = indexFilename
@@ -151,7 +152,8 @@ installPage mount pi = do
tname <- pageTemplate pi
templ <- use $ templates . to (M.! fromString tname)
file <- pageFilename mount
- fixedUrlDoc <- walkURLs (processLink mount) $ pi ^. pageDoc
+ fixedUrlDoc <-
+ walkURLs (processLink $ pi ^. pagePath . to takeDirectory) $ pi ^. pageDoc
checkTarget file
io $ do
putStrLn $ "P -> " ++ file
@@ -322,8 +324,5 @@ main =
sourceTemplates "templates"
use pages >>= traverse (uncurry installPage) . M.assocs
renderTags
- -- testing part begin
- installFile "external/mypage/img/awesome.png"
- -- testing part end
io $ putStrLn "OK"
- get >>= io . print
+ whenM (use dumpFinalState) $ get >>= io . print