From 9834ea90dd3bd9587f97235dda3c96e11444df94 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 21 Jul 2023 20:32:51 +0200 Subject: [PATCH] allow adding full paths to .../index.html files, fix minor extra stuff --- FormatOpts.hs | 1 - Types.hs | 19 ++++++++++++------- Utils.hs | 1 - reploy.hs | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/FormatOpts.hs b/FormatOpts.hs index 2b67edf..fdfea82 100644 --- a/FormatOpts.hs +++ b/FormatOpts.hs @@ -13,7 +13,6 @@ - License for the specific language governing permissions and limitations - under the License. -} - module FormatOpts where import Text.Pandoc.Extensions diff --git a/Types.hs b/Types.hs index 86969b2..bff0491 100644 --- a/Types.hs +++ b/Types.hs @@ -13,7 +13,6 @@ - License for the specific language governing permissions and limitations - under the License. -} - {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE RecordWildCards #-} @@ -76,6 +75,7 @@ data SiteState = , _listTemplate :: FilePath -- ^ Name of the template for listing pages , _timestampSuffix :: FilePath -- ^ File to search for a timestamp (e.g., if the prefix is ".ts", a timestamp for file "page.md" will be looked for in "page.md.ts"). These are best autogenerated with a script that sources the data from git or so. , _urlBase :: FilePath -- ^ "Root route" to prepend to all absolute links. + , _appendUrlIndex :: Bool -- ^ Append full @index.html@ to all page URLs , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes. } deriving (Show) @@ -141,15 +141,20 @@ siteOptions' = do long "list-template" <> help "Template for making tag-listing pages" <> value "list.html" <> showDefault - _urlBase <- - strOption $ - long "url-base" <> - short 'u' <> help "Base absolute URL" <> value "/" <> showDefault _timestampSuffix <- strOption $ long "timestamp-prefix" <> help "Timestamp file suffix for markdowns" <> value ".timestamp" <> showDefault + _urlBase <- + strOption $ + long "url-base" <> + short 'u' <> help "Base absolute URL" <> value "/" <> showDefault + _appendUrlIndex <- + switch $ + long "append-url-index" <> + help + "Append 'index.html' to all urls, negating server problems with directory index settings." _dumpFinalState <- switch $ long "dump-state" <> @@ -173,5 +178,5 @@ siteOptions = info (siteOptions' <**> helper) (fullDesc <> - progDesc "Build a R3 Cards-like site" <> - header "site - the R3 site builder") + progDesc "Build a R3 static site" <> + header "reploy - the R3 static site builder") diff --git a/Utils.hs b/Utils.hs index 293be23..cb21de1 100644 --- a/Utils.hs +++ b/Utils.hs @@ -13,7 +13,6 @@ - License for the specific language governing permissions and limitations - under the License. -} - {-# LANGUAGE OverloadedStrings #-} module Utils where 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