added option for building with drafts

This commit is contained in:
flupe 2020-10-07 19:02:37 +02:00
parent d286f603a6
commit 6bec30c566
4 changed files with 50 additions and 9 deletions

View File

@ -1,6 +1,7 @@
{ mkDerivation, achille, aeson, base, binary, bytestring
, containers, data-default, feed, filepath, lucid, pandoc
, pandoc-types, sort, stdenv, text, time, yaml
, containers, data-default, directory, feed, filepath, lucid
, optparse-applicative, pandoc, pandoc-types, process, sort, stdenv
, text, time, yaml
}:
mkDerivation {
pname = "site";
@ -9,8 +10,9 @@ mkDerivation {
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
achille aeson base binary bytestring containers data-default feed
filepath lucid pandoc pandoc-types sort text time yaml
achille aeson base binary bytestring containers data-default
directory feed filepath lucid optparse-applicative pandoc
pandoc-types process sort text time yaml
];
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;

View File

@ -34,6 +34,9 @@ executable site
, feed
, time
, lucid
, optparse-applicative
, process
, directory
extensions: BlockArguments
, TupleSections
, OverloadedStrings

View File

@ -1,5 +1,11 @@
{-# LANGUAGE LambdaCase #-}
module Main where
import qualified System.Process as Process
import System.Directory (removePathForcibly)
import Control.Monad (void, mapM_)
import Options.Applicative
import Lucid
import Common
@ -11,9 +17,38 @@ import qualified Projects
import qualified Visual
import qualified Readings
type ShowDrafts = Bool
data Cmd
= Build ShowDrafts -- ^ Build the site
| Deploy -- ^ Deploy to the server
| Clean -- ^ Delete all artefacts
deriving (Eq, Show)
cli :: Parser Cmd
cli = subparser $
command "build" (info (Build <$> switch (long "draft" <> short 'D' <> help "Display drafts"))
(progDesc "Build the site once" ))
<> command "deploy" (info (pure Deploy) (progDesc "Server go brrr" ))
<> command "clean" (info (pure Clean) (progDesc "Delete all artefacts"))
main :: IO ()
main = achilleWith config do
main = customExecParser p opts >>= \case
Deploy -> mapM_ Process.callCommand (deployCmd config)
Clean -> removePathForcibly (outputDir config)
>> removePathForcibly (cacheFile config)
Build showDrafts ->
void $ runTask [] config (build showDrafts)
where
opts = info (cli <**> helper) $ fullDesc <> header desc
p = prefs showHelpOnEmpty
desc = "acatalepsie & co"
build :: ShowDrafts -> Task IO String
build showDrafts = do
-- static assets
match_ "assets/*" copyFile
@ -26,5 +61,6 @@ main = achilleWith config do
Visual.build
Projects.build
Posts.build
Posts.build showDrafts
Readings.build

View File

@ -49,10 +49,10 @@ buildPost = do
toDate :: UTCTime -> String
toDate = formatTime defaultTimeLocale rfc822DateFormat
build :: Task IO ()
build = do
build :: Bool -> Task IO ()
build showDrafts = do
posts <- match "posts/*" buildPost
<&> filter (not . postDraft)
<&> filter (\p -> not (postDraft p) || showDrafts)
<&> recentFirst
watch posts $ match_ "index.rst" do