~yoctocell/yoctocell.xyz

2a9818a569b9af0f6be070eaae0c6c9c89523508 — Xinglu Chen 1 year, 5 months ago 8697ab8
app: Add support for gemini files
1 files changed, 28 insertions(+), 3 deletions(-)

M app/Main.hs
M app/Main.hs => app/Main.hs +28 -3
@@ 2,9 2,9 @@
import           Data.Char                      ( toLower
                                                , toUpper
                                                )
import           Data.Maybe
import           Data.List                      ( isPrefixOf )
import           Data.List.Split                ( splitOn )
import           Data.Maybe
import           Data.Semigroup                 ( (<>) )
import           System.FilePath.Posix          ( (</>)
                                                , joinPath


@@ 16,9 16,9 @@ import           System.FilePath.Posix          ( (</>)
                                                )

import           Hakyll
import           Hakyll.Web.Template.Context
import           Hakyll.Core.Identifier         ( toFilePath )
import           Hakyll.Core.Item               ( Item(..) )
import           Hakyll.Web.Template.Context

config :: Configuration
config = defaultConfiguration { destinationDirectory = "public" }


@@ 26,6 26,9 @@ config = defaultConfiguration { destinationDirectory = "public" }
baseUrl :: String
baseUrl = "https://git.sr.ht/~yoctocell/yoctocell.xyz/tree/master/item/src"

geminiUrl :: String
geminiUrl = "gemini://yoctocell.xyz"

feedConfiguration :: FeedConfiguration
feedConfiguration = FeedConfiguration
  { feedTitle       = "yoctocell's blog"


@@ 38,10 41,12 @@ feedConfiguration = FeedConfiguration
context :: Context String
context = defaultContext `mappend` sourceContext

geminiContext :: Context String
geminiContext = defaultContext `mappend` geminiUrlContext

main :: IO ()
main = hakyllWith config $ do
  match "src/media/*" $ do
  match "src/media" $ do
    route srcRoute
    compile copyFileCompiler



@@ 49,6 54,20 @@ main = hakyllWith config $ do
    route srcRoute
    compile compressCssCompiler

  match "src/posts/*.gmi" $ do
    route srcRoute
    compile
      $   getResourceString
      >>= loadAndApplyTemplate "src/templates/default.gmi" context

  match "src/index.gmi" $ do
    route srcRoute
    compile $ do
      -- posts <- recentFirst =<< loadAll "src/posts/*.gmi"
      -- let geminiContext = listField "posts" geminiUrlContext (return posts) 
  
      getResourceString >>= loadAndApplyTemplate "src/templates/index.gmi" context

  match (fromList ["src/about.org", "src/contact.org"]) $ do
    route $ setExtension' "html"
    compile


@@ 132,6 151,12 @@ sourceContext = field "source" $ \i -> do
    <$> maybe empty' toUrl
    <$> getRoute id

geminiUrlContext :: Context String
geminiUrlContext = field "geminiUrl" $ \i -> do
  let id     = itemIdentifier i
      empty' = fail "No route url found for item " ++ show id
  mappend geminiUrl <$> maybe empty' toUrl <$> getRoute id

-- | From org get metadatas.
orgCompiler :: Item String -> Compiler (Item String)
orgCompiler = pure . fmap (\s -> (metadatasToStr . orgMetadatas) s ++ s)