aboutsummaryrefslogtreecommitdiff
path: root/reploy.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-07-21 20:32:51 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2023-07-21 20:40:25 +0200
commit9834ea90dd3bd9587f97235dda3c96e11444df94 (patch)
tree0c8831e931004f250d3a644b9edc42fc7e7d91e7 /reploy.hs
parent4303d67cbcbfb523852b2e38fb09c7f893c58725 (diff)
downloadreploy-9834ea90dd3bd9587f97235dda3c96e11444df94.tar.gz
reploy-9834ea90dd3bd9587f97235dda3c96e11444df94.tar.bz2
allow adding full paths to .../index.html files, fix minor extra stuff
Diffstat (limited to 'reploy.hs')
-rw-r--r--reploy.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/reploy.hs b/reploy.hs
index 0c3a645..54bfa15 100644
--- a/reploy.hs
+++ b/reploy.hs
@@ -13,7 +13,6 @@
- License for the specific language governing permissions and limitations
- under the License.
-}
-
{-# LANGUAGE OverloadedStrings #-}
-- | The main deployment script.
@@ -25,6 +24,7 @@ import Control.Monad.Trans.State.Lazy
import qualified Data.Aeson as AE
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.KeyMap as KM
+import Data.Bool (bool)
import qualified Data.ByteString.Lazy as B
import Data.Digest.Pure.SHA (sha256, showDigest)
import Data.Foldable (traverse_)
@@ -161,6 +161,12 @@ checkTarget fp = do
rootUrl :: FilePath -> Site FilePath
rootUrl fp = (</> unAbsolute fp) <$> use urlBase
+-- | Like `rootUrl` but also appends @index.html@ for systems that don't have
+-- working directory indexes.
+rootPageUrl :: FilePath -> Site FilePath
+rootPageUrl fp =
+ bool id (</> "index.html") <$> use appendUrlIndex <*> rootUrl fp
+
-- | Process a single link pointing out from a page.
processLink :: FilePath -> FilePath -> Site String
processLink base l =
@@ -168,7 +174,7 @@ processLink base l =
"#"
then pure l
else if isAbsolute l
- then rootUrl l
+ then rootPageUrl l
else installFile (base </> l) >>= rootUrl
-- | Get a mount point of the page into the correct location.
@@ -401,7 +407,7 @@ tagPath = joinPath
-- | Make a link to the tag page
tagLink :: [String] -> Site FilePath
-tagLink = rootUrl . ("tag" </>) . tagPath
+tagLink = rootPageUrl . ("tag" </>) . tagPath
-- | Fold the hierarchical tag bits to a slashed path.
listPath :: [String] -> FilePath
@@ -409,7 +415,7 @@ listPath = joinPath
-- | Make a link to the tag page
listLink :: [String] -> Site FilePath
-listLink = rootUrl . ("list" </>) . listPath
+listLink = rootPageUrl . ("list" </>) . listPath
-- | Make metadata for printing out a single hierarchical tag (all levels clickable)
makeHTagMeta :: ([String] -> Site FilePath) -> [String] -> Site Y.Value
@@ -425,7 +431,7 @@ makeHTagMeta lf tag = do
-- | Make metadata for printing out a link to a page
makePageLinkMeta :: FilePath -> Site Y.Value
makePageLinkMeta mount = do
- link <- rootUrl mount
+ link <- rootPageUrl mount
meta <- use $ pages . to (M.! mount) . pageMeta
pure $ Y.object [("href", fromString link), ("meta", meta)]
@@ -517,7 +523,7 @@ renderLists = use (ehtags . to M.keys) >>= traverse_ renderList
-- | Transform one mounted PageInfo to the base search data
mkSearchData :: FilePath -> PageInfo -> Site [Y.Value]
mkSearchData mount pi = do
- link <- rootUrl mount
+ link <- rootPageUrl mount
text <- io . runIOorExplode $ writePlain plainWriteOpts (pi ^. pageDoc)
let title = pi ^? pageMeta . key "title" . _String
-- TODO: unify retrieval of tags