From 9834ea90dd3bd9587f97235dda3c96e11444df94 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 21 Jul 2023 20:32:51 +0200 Subject: allow adding full paths to .../index.html files, fix minor extra stuff --- reploy.hs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'reploy.hs') 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 -- cgit v1.2.3