diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-25 00:42:26 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-25 00:42:26 +0200 |
| commit | 919e953d2035836cf537beb31610e7b2edce8833 (patch) | |
| tree | 407e7fc427bfe8b0c6b0526eba0436afe76194ca /site.hs | |
| parent | 32e050bac753687b801a40c91e398a0132ccffbc (diff) | |
| download | reploy-919e953d2035836cf537beb31610e7b2edce8833.tar.gz reploy-919e953d2035836cf537beb31610e7b2edce8833.tar.bz2 | |
link modification works
Diffstat (limited to 'site.hs')
| -rw-r--r-- | site.hs | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -22,7 +22,7 @@ import Hakyll.Core.Util.File (getRecursiveContents, makeDirectories) import Lens.Micro import Lens.Micro.Aeson import Lens.Micro.Mtl -import System.FilePath ((</>), splitDirectories, splitPath, takeFileName) +import System.FilePath ((</>), splitDirectories, splitPath, takeFileName, isAbsolute) import qualified Text.Mustache as Mu import Text.Pandoc.Class (runIOorExplode) import Text.Pandoc.Readers.Markdown (readMarkdown) @@ -106,22 +106,34 @@ checkTarget fp = do then error $ "colliding renders for page: " ++ fp else targets %= S.insert fp +-- | Process a single link pointing out from a page. +processLink :: FilePath -> String -> Site String +processLink base l = do + io $ putStrLn l + if isAbsolute l + then + pure l + else (do + io $ putStrLn "rel" + pure $ '/':(base</>l)) -- TODO + -- | Render a page using the current template. installPage :: FilePath -> PageInfo -> Site () installPage mount pi - {- find the correct template and metadata -} = do tname <- pageTemplate pi templ <- use $ templates . to (M.! fromString tname) file <- indexFilename mount + fixedUrlDoc <- walkURLs (processLink mount) $ pi ^. pageDoc checkTarget file io $ do putStrLn $ "P -> " ++ file makeDirectories file - body <- runIOorExplode $ writeHtml5String htmlWriteOpts (pi ^. pageDoc) + body <- runIOorExplode $ writeHtml5String htmlWriteOpts fixedUrlDoc let Y.Object meta' = pi ^. pageMeta meta = Y.Object $ KM.insert "body" (Y.String body) meta' TIO.writeFile file $ Mu.substitute templ meta + installPageRedirects mount pi {- | Install a simple redirect handler page. -} installRedirect :: FilePath -> FilePath -> Site () @@ -143,11 +155,6 @@ installPageRedirects target pi = do (installRedirect target) (pi ^.. pageMeta . key "redirects" . values . _String . to T.unpack) --- | Install all redirects required by all pages. -installRedirects :: Site () -installRedirects = - use pages >>= traverse_ (uncurry installPageRedirects) . M.assocs - -- | Find the path to the file of a given hash dataFilename :: String -> FilePath -> Site (FilePath, FilePath) dataFilename hash basename = do @@ -184,7 +191,7 @@ installAsset :: FilePath -> Site () installAsset fp = do od <- use outputDir ad <- use assetDir - let [src,dst] = map (</> fp) [ad,od] + let [src, dst] = map (</> fp) [ad, od] checkTarget dst io $ do putStrLn $ "A -> " ++ src ++ " -> " ++ dst @@ -226,7 +233,6 @@ main = sourceTags sourceTemplates "templates" use pages >>= traverse (uncurry installPage) . M.assocs - installRedirects installFile "external/mypage/img/awesome.png" io $ putStrLn "OK" get >>= io . print |
