mirror of
https://github.com/srid/ema.git
synced 2024-11-25 20:12:20 +03:00
Be lenient on missing staticAssets
This commit is contained in:
parent
e7bf0333da
commit
e3a05de882
@ -7,6 +7,7 @@
|
||||
- Unicode normalize slugs using NFC
|
||||
- Add `decodeSlug` and `encodeSlug`
|
||||
- Add default implementation based on Enum for `staticRoute`
|
||||
- Warn, without failing, on missing `staticAssets` during static generation
|
||||
- Helpers
|
||||
- Helpers.FileSystem
|
||||
- add `mountOnLVar`
|
||||
|
@ -6,9 +6,9 @@ module Ema.Generate where
|
||||
|
||||
import Control.Exception (throw)
|
||||
import Control.Monad.Logger
|
||||
import Ema.Class
|
||||
import Ema.Class (Ema (staticAssets, staticRoutes), MonadEma)
|
||||
import Ema.Route (routeFile)
|
||||
import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, doesFileExist)
|
||||
import System.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, doesPathExist)
|
||||
import System.FilePath (takeDirectory, (</>))
|
||||
import System.FilePattern.Directory (getDirectoryFiles)
|
||||
|
||||
@ -24,7 +24,7 @@ generate ::
|
||||
m ()
|
||||
generate dest model render = do
|
||||
unlessM (liftIO $ doesDirectoryExist dest) $ do
|
||||
error "Destination does not exist"
|
||||
error $ "Destination does not exist: " <> toText dest
|
||||
let routes = staticRoutes model
|
||||
log LevelInfo $ "Writing " <> show (length routes) <> " routes"
|
||||
forM_ routes $ \r -> do
|
||||
@ -35,7 +35,11 @@ generate dest model render = do
|
||||
createDirectoryIfMissing True (takeDirectory fp)
|
||||
writeFileLBS fp s
|
||||
forM_ (staticAssets $ Proxy @route) $ \staticPath -> do
|
||||
copyDirRecursively staticPath dest
|
||||
liftIO (doesPathExist staticPath) >>= \case
|
||||
True ->
|
||||
copyDirRecursively staticPath dest
|
||||
False ->
|
||||
log LevelWarn $ toText $ "? " <> staticPath <> " (missing)"
|
||||
|
||||
newtype StaticAssetMissing = StaticAssetMissing FilePath
|
||||
deriving (Show, Exception)
|
||||
|
Loading…
Reference in New Issue
Block a user