Browse Source

im bad at nix

master
Thorn Avery 5 years ago
parent
commit
059d1b6934
4 changed files with 62 additions and 39 deletions
  1. +4
    -0
      ChangeLog.md
  2. +4
    -4
      default.nix
  3. +2
    -2
      rf.cabal
  4. +52
    -33
      site.hs

+ 4
- 0
ChangeLog.md View File

@@ -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?

+ 4
- 4
default.nix View File

@@ -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;


+ 2
- 2
rf.cabal View File

@@ -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

+ 52
- 33
site.hs View File

@@ -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"
}

Loading…
Cancel
Save