diff --git a/ChangeLog.md b/ChangeLog.md index ebe4bbb..d426cc1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -15,3 +15,7 @@ ## 0.1.2.0 -- 2018-08-23 * oh fuark i forgot to change the version. added robots.txt, favicons + +## 0.1.2.1 -- 2018-08-25 + +* cleaned up and commented. you happy now? diff --git a/default.nix b/default.nix index c7b4414..5407511 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,14 @@ -{ mkDerivation, base, filepath, hakyll, hakyll-favicon, imagemagick +{ mkDerivation, base, binary, filepath, hakyll, hakyll-favicon, imagemagick , stdenv }: mkDerivation { pname = "rf"; - version = "0.1.2.0"; + version = "0.1.2.1"; src = ./.; isLibrary = false; isExecutable = true; - executableHaskellDepends = [ base filepath hakyll hakyll-favicon ]; - executableSystemDepends = [ imagemagick ]; + executableHaskellDepends = [ base binary filepath hakyll hakyll-favicon ]; + librarySystemDepends = [ imagemagick ]; homepage = "regularflolloping.com"; description = "tA's blog"; license = stdenv.lib.licenses.bsd3; diff --git a/rf.cabal b/rf.cabal index 771f208..67c9feb 100644 --- a/rf.cabal +++ b/rf.cabal @@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: rf -version: 0.1.2.0 +version: 0.1.2.1 synopsis: tA's blog -- description: homepage: regularflolloping.com @@ -25,5 +25,5 @@ executable site , filepath , hakyll-favicon -- hs-source-dirs: - extra-libraries: imagemagick + -- extra-libraries: imagemagick default-language: Haskell2010 diff --git a/site.hs b/site.hs index beb8872..2e34fdc 100644 --- a/site.hs +++ b/site.hs @@ -2,6 +2,7 @@ import Data.Monoid ((<>)) import Data.List (sortBy,isSuffixOf) +import Data.Typeable import GHC.IO.Encoding import Hakyll import Hakyll.Favicon (faviconsRules, faviconsField) @@ -9,22 +10,25 @@ import System.FilePath.Posix (takeBaseName,takeDirectory,()) main :: IO () main = do + + -- Set the encoding so w3c doesnt complain setLocaleEncoding utf8 hakyll $ do + + -- Generate the favicons faviconsRules "icons/favicon.svg" - match (fromList ["humans.txt", "robots.txt"]) $ do + -- Straight copying of files + match (fromList ["humans.txt", "robots.txt", "fonts/*"]) $ do route idRoute compile copyFileCompiler + -- CSS needs to be compiled and minified match "css/*" $ do route idRoute compile compressCssCompiler - match "fonts/*" $ do - route idRoute - compile copyFileCompiler - + -- Load pages that need to be formatted match (fromList ["about.md", "contact.md"]) $ do route $ cleanRoute compile $ pandocCompiler @@ -32,6 +36,19 @@ main = do >>= relativizeUrls >>= cleanIndexUrls + -- Render Atom + Rss feeds + create ["atom.xml"] $ do + route idRoute + (compileFeed renderAtom) + + create ["rss.xml"] $ do + route idRoute + (compileFeed renderRss) + + -- Compile the templates + match "templates/*" $ compile templateBodyCompiler + + -- Compile the archive page and post list match "archive.md" $ do route $ cleanRoute compile $ pandocCompiler @@ -50,6 +67,7 @@ main = do >>= relativizeUrls >>= cleanIndexUrls + -- Compile posts + save snapshots for the web feeds match "posts/*" $ do route $ cleanRoute compile $ pandocCompiler @@ -60,6 +78,7 @@ main = do >>= cleanIndexUrls >>= cleanIndexHtmls + -- Compile and load posts match "index.html" $ do route idRoute compile $ do @@ -73,34 +92,43 @@ main = do >>= cleanIndexUrls >>= cleanIndexHtmls - match "templates/*" $ compile templateBodyCompiler - - create ["atom.xml"] $ do - route idRoute - compile $ do - let feedCtx = postCtx <> - bodyField "description" - posts <- fmap (take 10) . recentFirst - =<< loadAllSnapshots "posts/*" "content" - renderAtom feedConfig feedCtx posts - - create ["rss.xml"] $ do - route idRoute - compile $ do - let feedCtx = postCtx <> - bodyField "description" - posts <- fmap (take 10) . recentFirst - =<< loadAllSnapshots "posts/*" "content" - renderRss feedConfig feedCtx posts +-- Agnememnon the Fuck-Upperer - Conquerer of Small Type Declarations +compileFeed :: + (FeedConfiguration + -> Context String + -> [Item String] + -> Compiler (Item String) + ) -> Rules () +-- For those left alive, this abstracts out creating +-- Atom and RSS feeds +compileFeed f = compile $ do + let feedCtx = postCtx <> + bodyField "description" + posts <- fmap (take 10) . recentFirst + =<< loadAllSnapshots "posts/*" "content" + f feedConfig feedCtx posts + +-- The configuration for our Atom/RSS feeds +feedConfig :: FeedConfiguration +feedConfig = FeedConfiguration { + feedTitle = "Regular Flolloping" + , feedDescription = "tA's Blog" + , feedAuthorName = "Shaun Kerr" + , feedAuthorEmail = "s@p7.co.nz" + , feedRoot = "https://regularflolloping.com" + } +-- Our default context for pages ctx :: Context String ctx = defaultContext <> faviconsField +-- Default context for posts postCtx :: Context String postCtx = (dateField "date" "%B %e, %Y") <> ctx +-- Functions to convert pages to /name/index.html cleanRoute :: Routes cleanRoute = customRoute createIndexRoute where @@ -122,12 +150,3 @@ cleanIndex url | idx `isSuffixOf` url = take (length url - length idx) url | otherwise = url where idx = "index.html" - -feedConfig :: FeedConfiguration -feedConfig = FeedConfiguration { - feedTitle = "Regular Flolloping" - , feedDescription = "tA's Blog" - , feedAuthorName = "Shaun Kerr" - , feedAuthorEmail = "s@p7.co.nz" - , feedRoot = "https://regularflolloping.com" - }