diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-24 19:52:25 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-24 19:52:25 +0200 |
| commit | 1a24212ec42c9ae93baa13fe30000f5e47176b62 (patch) | |
| tree | 9dbb6ecb577e00940f696d8960fd525c4b0ddad3 | |
| parent | 1c4a4bc54ab8b2c7ad17e9942037a2ee8666458b (diff) | |
| download | reploy-1a24212ec42c9ae93baa13fe30000f5e47176b62.tar.gz reploy-1a24212ec42c9ae93baa13fe30000f5e47176b62.tar.bz2 | |
redirect installation
| -rw-r--r-- | site.hs | 34 |
1 files changed, 26 insertions, 8 deletions
@@ -142,20 +142,37 @@ installPage mount pi makeDirectories file TIO.writeFile file . Mu.substitute templ $ pi ^. pageMeta +{- | Install a simple redirect handler page. -} +installRedirect :: FilePath -> FilePath -> Site () +installRedirect target from = do + tname <- use redirectTemplate + templ <- use $ templates . to (M.! fromString tname) + file <- indexFilename from + checkRender file + io $ do + putStrLn $ "@@@ " ++ file ++ " -> " ++ target + makeDirectories file + TIO.writeFile file . Mu.substitute templ $ + Y.object [("target", Y.String $ T.pack target)] + +-- | Install all redirects required by one page. +installPageRedirects :: FilePath -> PageInfo -> Site () +installPageRedirects target pi = do + traverse_ + (installRedirect target . T.unpack) + (pi ^.. pageMeta . key "redirects" . values . _String) + +-- | Install all redirects required by all pages. +installRedirects :: Site () +installRedirects = + use pages >>= traverse_ (uncurry installPageRedirects) . M.assocs + {- | Install a file. Files are installed into a single shared location. That - prevents file duplication and also gives a bit of control for where the - files reside and what are their names. -} installFile :: FilePath -> Site FilePath installFile = undefined -{- | Install a simple redirect handler page. -} -installRedirect :: FilePath -> FilePath -> Site () -installRedirect = undefined - --- | Install all redirects required by pages. -installRedirects :: Site () -installRedirects = undefined - -- | Render a site for a given tag string. renderTag :: [String] -> Site () renderTag = undefined @@ -169,5 +186,6 @@ main = flip runStateT emptySiteState $ do traverse sourcePages ["external"] sourceTemplates "templates" + installRedirects use pages >>= traverse (uncurry installPage) . M.assocs get >>= io . print |
