Merge branch 'mk-dont-source-assets' into 'master'
avoid source dirs Closes #4 See merge request R3-core/websites-dev/reploy!2
This commit is contained in:
commit
73d1920b62
|
@ -28,4 +28,4 @@ plainWriteOpts = def {writerWrapText = WrapNone}
|
||||||
|
|
||||||
-- | Default options for making tables of contents with certain depth.
|
-- | Default options for making tables of contents with certain depth.
|
||||||
tocWriteOpts :: Int -> WriterOptions
|
tocWriteOpts :: Int -> WriterOptions
|
||||||
tocWriteOpts n = def { writerTOCDepth = n}
|
tocWriteOpts n = def {writerTOCDepth = n}
|
||||||
|
|
6
Types.hs
6
Types.hs
|
@ -52,6 +52,7 @@ data SiteState =
|
||||||
, _searchDataOut :: Maybe FilePath -- ^ File to write the searchable versions of pages to (as JSON)
|
, _searchDataOut :: Maybe FilePath -- ^ File to write the searchable versions of pages to (as JSON)
|
||||||
, _assetDir :: FilePath -- ^ Directory for output
|
, _assetDir :: FilePath -- ^ Directory for output
|
||||||
, _sourceDirs :: [FilePath] -- ^ Path to page source data
|
, _sourceDirs :: [FilePath] -- ^ Path to page source data
|
||||||
|
, _notSourceDirs :: [FilePath] -- ^ Subdirectories of source dirs where pages should not be sourced
|
||||||
, _templateDir :: FilePath -- ^ Path to template directory
|
, _templateDir :: FilePath -- ^ Path to template directory
|
||||||
, _defaultTemplate :: FilePath -- ^ Name of the default template
|
, _defaultTemplate :: FilePath -- ^ Name of the default template
|
||||||
, _redirectTemplate :: FilePath -- ^ Name of the template for redirect pages
|
, _redirectTemplate :: FilePath -- ^ Name of the template for redirect pages
|
||||||
|
@ -93,6 +94,11 @@ siteOptions' = do
|
||||||
short 's' <>
|
short 's' <>
|
||||||
help
|
help
|
||||||
"Path to the directory with source data (possibly multiple paths, defaults to a single directory \"cards\")"
|
"Path to the directory with source data (possibly multiple paths, defaults to a single directory \"cards\")"
|
||||||
|
_notSourceDirs <-
|
||||||
|
fmap (maybe ["assets"] toList . nonEmpty) . many . strOption $
|
||||||
|
long "exclude-source-directory" <>
|
||||||
|
help
|
||||||
|
"Names of subdirectories of the sources that should never be used for sourcing pages (possibly multiple directory names, defaults to a single directory \"assets\")"
|
||||||
_templateDir <-
|
_templateDir <-
|
||||||
strOption $
|
strOption $
|
||||||
long "template-directory" <>
|
long "template-directory" <>
|
||||||
|
|
16
site.hs
16
site.hs
|
@ -3,7 +3,7 @@
|
||||||
-- | The main deployment script.
|
-- | The main deployment script.
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Control.Monad ((>=>), join, unless, when)
|
import Control.Monad ((>=>), filterM, join, unless, when)
|
||||||
import Control.Monad.Extra (whenM)
|
import Control.Monad.Extra (whenM)
|
||||||
import Control.Monad.Trans.State.Lazy
|
import Control.Monad.Trans.State.Lazy
|
||||||
import qualified Data.Aeson as AE
|
import qualified Data.Aeson as AE
|
||||||
|
@ -48,13 +48,19 @@ import FormatOpts
|
||||||
import Types
|
import Types
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
|
-- | Check if a given path should be sourced or not
|
||||||
|
isSourceablePath :: FilePath -> Site Bool
|
||||||
|
isSourceablePath fp = do
|
||||||
|
notSource <- use notSourceDirs
|
||||||
|
pure $ (&&) <$> hasSuffix ".md" . last <*> not . any (`elem` notSource) . init $
|
||||||
|
splitPath fp
|
||||||
|
|
||||||
-- | Load the pages from a directory and add them to `pages`.
|
-- | Load the pages from a directory and add them to `pages`.
|
||||||
sourcePages :: FilePath -> Site ()
|
sourcePages :: FilePath -> Site ()
|
||||||
sourcePages fp =
|
sourcePages fp =
|
||||||
io
|
(io $ getRecursiveContents (pure . const False) fp) >>=
|
||||||
(map (fp </>) . filter (hasSuffix ".md" . last . splitPath) <$>
|
filterM isSourceablePath >>=
|
||||||
getRecursiveContents (pure . const False) fp) >>=
|
traverse_ (loadPage . (fp </>))
|
||||||
traverse_ loadPage
|
|
||||||
|
|
||||||
{- | Extract `PageInfo` about a single page and save it into `pages` in
|
{- | Extract `PageInfo` about a single page and save it into `pages` in
|
||||||
- `SiteState`. -}
|
- `SiteState`. -}
|
||||||
|
|
Loading…
Reference in a new issue