<commit_before>--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import           Data.Monoid (mappend)
import           Hakyll
import qualified Text.Pandoc.Options as Pandoc.Options


--------------------------------------------------------------------------------
config :: Configuration
config = defaultConfiguration
        {   deployCommand = "src/deploy.sh"}

pandocWriterOptions :: Pandoc.Options.WriterOptions
pandocWriterOptions = defaultHakyllWriterOptions
                        { Pandoc.Options.writerHtml5 = True
                        , Pandoc.Options.writerHtmlQTags = True
                        --, Pandoc.Options.writerNumberSections = True
                        --, Pandoc.Options.writerNumberOffset = [1]
                        , Pandoc.Options.writerSectionDivs = True
                        , Pandoc.Options.writerTableOfContents = True
                    }

--------------------------------------------------------------------------------
main :: IO ()
main = hakyllWith config $ do

    match "templates/*" $ compile templateCompiler


    -- compile CV:
    match (fromList ["content/cv.md"]) $ do
        route   $ setExtension "" `composeRoutes` gsubRoute "content/" (const "")
        compile $ pandocCompilerWith defaultHakyllReaderOptions pandocWriterOptions
            >>= loadAndApplyTemplate "templates/generic.html" defaultContext
            >>= loadAndApplyTemplate "templates/base.html" defaultContext
            >>= relativizeUrls


    -- compile posts:
    match "content/posts/*" $ do
        route $ setExtension "" `composeRoutes` gsubRoute "content/" (const "")
        compile $ pandocCompilerWith defaultHakyllReaderOptions pandocWriterOptions
            >>= loadAndApplyTemplate "templates/post.html"    postCtx
            >>= loadAndApplyTemplate "templates/base.html" postCtx
            >>= relativizeUrls


    -- build index page:
    match "content/index.html" $ do
        route (gsubRoute "content/" (const ""))
        compile $ do
            let indexCtx = field "posts" (\_ -> postList recentFirst)
            getResourceBody
                >>= applyAsTemplate indexCtx
                >>= loadAndApplyTemplate "templates/base.html" postCtx
                >>= relativizeUrls


    -- copy other site content:
    match "content/**" $ do
        route (gsubRoute "content/" (const ""))
        compile copyFileCompiler


    -- compile SCSS:
    match "src/scss/main.scss" $do
        route   $ constRoute "stylesheet.css"
        compile $ getResourceString
            >>= withItemBody (unixFilter "sass" ["-s",
                                                 "--scss",
                                                 "--compass",
                                                 "--style", "compressed",
                                                 "--load-path", "src/scss"])
            >>= return . fmap compressCss


--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
    dateField "date" "%B %e, %Y" `mappend`
    defaultContext


--------------------------------------------------------------------------------
postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
postList sortFilter = do
    posts   <- sortFilter =<< loadAll "content/posts/*"
    itemTpl <- loadBody "templates/post-list-item.html"
    list    <- applyTemplateList itemTpl postCtx posts
    return list<commit_msg>Include everything under posts directory as a post.<commit_after>--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
import           Data.Monoid (mappend)
import           Hakyll
import qualified Text.Pandoc.Options as Pandoc.Options


--------------------------------------------------------------------------------
config :: Configuration
config = defaultConfiguration
        {   deployCommand = "src/deploy.sh"}

pandocWriterOptions :: Pandoc.Options.WriterOptions
pandocWriterOptions = defaultHakyllWriterOptions
                        { Pandoc.Options.writerHtml5 = True
                        , Pandoc.Options.writerHtmlQTags = True
                        --, Pandoc.Options.writerNumberSections = True
                        --, Pandoc.Options.writerNumberOffset = [1]
                        , Pandoc.Options.writerSectionDivs = True
                        , Pandoc.Options.writerTableOfContents = True
                    }

postsDirectory = "content/posts/**"
--------------------------------------------------------------------------------
main :: IO ()
main = hakyllWith config $ do

    match "templates/*" $ compile templateCompiler


    -- compile CV:
    match (fromList ["content/cv.md"]) $ do
        route   $ setExtension "" `composeRoutes` gsubRoute "content/" (const "")
        compile $ pandocCompilerWith defaultHakyllReaderOptions pandocWriterOptions
            >>= loadAndApplyTemplate "templates/generic.html" defaultContext
            >>= loadAndApplyTemplate "templates/base.html" defaultContext
            >>= relativizeUrls


    -- compile posts:
    match postsDirectory $ do
        route $ setExtension "" `composeRoutes` gsubRoute "content/" (const "")
        compile $ pandocCompilerWith defaultHakyllReaderOptions pandocWriterOptions
            >>= loadAndApplyTemplate "templates/post.html"    postCtx
            >>= loadAndApplyTemplate "templates/base.html" postCtx
            >>= relativizeUrls


    -- build index page:
    match "content/index.html" $ do
        route (gsubRoute "content/" (const ""))
        compile $ do
            let indexCtx = field "posts" (\_ -> postList recentFirst)
            getResourceBody
                >>= applyAsTemplate indexCtx
                >>= loadAndApplyTemplate "templates/base.html" postCtx
                >>= relativizeUrls


    -- copy other site content:
    match "content/**" $ do
        route (gsubRoute "content/" (const ""))
        compile copyFileCompiler


    -- compile SCSS:
    match "src/scss/main.scss" $do
        route   $ constRoute "stylesheet.css"
        compile $ getResourceString
            >>= withItemBody (unixFilter "sass" ["-s",
                                                 "--scss",
                                                 "--compass",
                                                 "--style", "compressed",
                                                 "--load-path", "src/scss"])
            >>= return . fmap compressCss


--------------------------------------------------------------------------------
postCtx :: Context String
postCtx =
    dateField "date" "%B %e, %Y" `mappend`
    defaultContext


--------------------------------------------------------------------------------
postList :: ([Item String] -> Compiler [Item String]) -> Compiler String
postList sortFilter = do
    posts   <- sortFilter =<< loadAll postsDirectory
    itemTpl <- loadBody "templates/post-list-item.html"
    list    <- applyTemplateList itemTpl postCtx posts
    return list
{'fraction_non_alphanumeric': 0.2004498172617374, 'fraction_numerical': 0.000562271577171774, 'mean_word_length': 1.3843833780160857, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5341027', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1591, 'n_words': 382}