-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
321 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.stack-work/ | ||
*~ | ||
*~ | ||
.shake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,104 @@ | ||
{-# language OverloadedStrings #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main where | ||
|
||
import SitePipe | ||
import Prelude hiding (length) | ||
import qualified Prelude as P | ||
import Control.Lens | ||
import Control.Monad | ||
import Data.Aeson as A | ||
import Data.Aeson.Lens | ||
import Development.Shake | ||
import Development.Shake.Classes | ||
import Development.Shake.Forward | ||
import Development.Shake.FilePath | ||
import GHC.Generics (Generic) | ||
import Slick | ||
import qualified Data.Text as T | ||
|
||
outputFolder :: FilePath | ||
outputFolder = "docs/" | ||
|
||
-- | Data for the index page | ||
data IndexInfo = | ||
IndexInfo | ||
{ episodes :: [Episode] | ||
} deriving (Generic, Show, FromJSON, ToJSON) | ||
|
||
data Episode = Episode | ||
{ guest :: String | ||
, date :: String | ||
, length :: String | ||
, url :: String | ||
, topics :: [String] | ||
, episodeId :: String | ||
} deriving (Generic, Eq, Ord, Show, FromJSON, ToJSON, Binary) | ||
|
||
|
||
buildIndex :: [Episode] -> Action () | ||
buildIndex posts' = do | ||
indexT <- compileTemplate' "site/templates/index.html" | ||
let indexInfo = IndexInfo {episodes = reverse posts'} | ||
indexHTML = T.unpack $ substitute indexT (toJSON indexInfo) | ||
writeFile' (outputFolder </> "index.html") indexHTML | ||
|
||
buildEpisodes :: Action [Episode] | ||
buildEpisodes = do | ||
pPaths <- getDirectoryFiles "." ["site/episodes//*.md"] | ||
forP pPaths buildEpisode | ||
|
||
|
||
getEpisodeId :: FilePath -> Int | ||
getEpisodeId = read . take 3 . drop (P.length @[] "site/episodes/") | ||
|
||
|
||
buildEpisode :: FilePath -> Action Episode | ||
buildEpisode srcPath = cacheAction ("build" :: T.Text, srcPath) $ do | ||
liftIO . putStrLn $ "Rebuilding episode: " <> srcPath | ||
postContent <- readFile' srcPath | ||
postData <- markdownToHTML . T.pack $ postContent | ||
|
||
let epId = getEpisodeId srcPath | ||
postUrl = T.pack . dropDirectory1 $ srcPath -<.> "html" | ||
withPostUrl = _Object . at "url" ?~ String postUrl | ||
|
||
fullPostData | ||
= withPostUrl | ||
$ postData | ||
& _Object . at "episodeId" ?~ String (T.pack $ show epId) | ||
|
||
template <- compileTemplate' "site/templates/episode.html" | ||
writeFile' (outputFolder </> T.unpack postUrl) | ||
. T.unpack | ||
$ substitute template fullPostData | ||
convert fullPostData | ||
|
||
-- | Copy all static files from the listed folders to their destination | ||
copyStaticFiles :: Action () | ||
copyStaticFiles = do | ||
filepaths <- getDirectoryFiles "./site/" ["images//*", "css//*", "js//*"] | ||
void $ forP filepaths $ \filepath -> | ||
copyFileChanged ("site" </> filepath) (outputFolder </> filepath) | ||
|
||
-- | Specific build rules for the Shake system | ||
-- defines workflow to build the website | ||
buildRules :: Action () | ||
buildRules = do | ||
allPosts <- buildEpisodes | ||
buildIndex allPosts | ||
copyStaticFiles | ||
|
||
-- | Kick it all off | ||
main :: IO () | ||
main = site $ do | ||
-- Load all the posts from site/posts/ | ||
posts <- resourceLoader markdownReader ["episodes/*.md"] | ||
|
||
-- Build up a context for our index page | ||
let indexContext :: Value | ||
indexContext = object [ "posts" .= posts | ||
-- The url is where the index page will be written to | ||
, "url" .= ("/index.html" :: String) | ||
] | ||
|
||
-- write out index page and posts via templates | ||
writeTemplate "templates/index.html" [indexContext] | ||
writeTemplate "templates/episode.html" posts | ||
main = do | ||
let shOpts = | ||
forwardOptions $ shakeOptions | ||
{ shakeVerbosity = Chatty | ||
, shakeLintInside = ["./site/"] | ||
, shakeVersion = "3" | ||
} | ||
shakeArgsForward shOpts buildRules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Solomon Bothwell -- Cofree Coffee Cast</title> | ||
</head> | ||
<body> | ||
<article> | ||
<h1>Solomon Bothwell</h1> | ||
|
||
</article> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Cofree Coffee Cast</title> | ||
</head> | ||
<body> | ||
<h1>Episodes</h1> | ||
<ul> | ||
<li><a href="episodes/002-solomon-bothwell.html">2 - Solomon Bothwell (2022-01-30)</a></li> | ||
<li><a href="episodes/001-jonathan-lorimer.html">1 - Jonathan Lorimer (2022-01-15)</a></li> | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,3 @@ extra-deps: | |
- sitepipe-0.4.0.1 | ||
- MissingH-1.4.3.0 | ||
|
||
|