diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-20 22:19:57 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-20 22:19:57 +0200 |
| commit | a6148fdb91c53c3d4ae217f3ce38361b04a775b9 (patch) | |
| tree | 34d4ea6fff0ceb983e3d64c8bc552be21ec01c50 /site.hs | |
| download | reploy-a6148fdb91c53c3d4ae217f3ce38361b04a775b9.tar.gz reploy-a6148fdb91c53c3d4ae217f3ce38361b04a775b9.tar.bz2 | |
site kinda works
Diffstat (limited to 'site.hs')
| -rw-r--r-- | site.hs | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -0,0 +1,57 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Hakyll + +import Control.Monad ((>=>)) +import Data.Foldable (traverse_) +import Data.Maybe (fromMaybe) +import System.FilePath ((</>), dropTrailingPathSeparator, normalise) + +import Debug.Trace + +getMount :: Metadata -> Routes +getMount = maybe idRoute constRoute . lookupString "mount" + +indexInDir :: Routes -> Routes +indexInDir = flip composeRoutes . customRoute $ (</> "index.html") . toFilePath + +extractRedirs :: Identifier -> Rules (Identifier, [Identifier]) +extractRedirs ident = do + md <- getMetadata ident + let to = fromMaybe ident $ fromFilePath <$> lookupString "mount" md + froms = + fromMaybe [] $ + map (fromFilePath . dropTrailingPathSeparator . normalise) <$> + lookupStringList "redirects" md + pure (to, froms) + +makePage :: Rules () +makePage = do + route $ indexInDir (metadataRoute getMount) + compile $ + pandocCompiler >>= loadAndApplyTemplate "templates/page.html" pageCtx >>= + loadAndApplyTemplate "templates/default.html" pageCtx >>= + relativizeUrls + +makeRedirects :: Identifier -> [Identifier] -> Rules () +makeRedirects to froms = + create froms $ do + route $ indexInDir idRoute + compile . makeItem . Redirect . ('/' :) . toFilePath $ to + +spawnRedirects :: [Identifier] -> Rules () +spawnRedirects = traverse_ (extractRedirs >=> uncurry makeRedirects) + +main :: IO () +main = + hakyll $ + {- Source the pages -} + do + match "external/**/*.md" makePage + {- Source and process the redirects -} + getMatches "external/**/*.md" >>= spawnRedirects + {- Compile the templates (no routing, cache-only) -} + match "templates/*" $ compile templateBodyCompiler + +pageCtx :: Context String +pageCtx = defaultContext |
