| 1 |
{-# LANGUAGE TemplateHaskell #-} |
| 2 |
module Hledger.Web.Settings.StaticFiles where |
| 3 |
|
| 4 |
import System.IO (stdout, hFlush) |
| 5 |
import Yesod.Static (Static, embed, publicFiles, staticDevel) |
| 6 |
|
| 7 |
import Hledger.Web.Settings (staticDir, development) |
| 8 |
|
| 9 |
-- | use this to create your static file serving site |
| 10 |
-- staticSite :: IO Static.Static |
| 11 |
-- staticSite = if development then Static.staticDevel staticDir |
| 12 |
-- else Static.static staticDir |
| 13 |
-- |
| 14 |
-- | This generates easy references to files in the static directory at compile time, |
| 15 |
-- giving you compile-time verification that referenced files exist. |
| 16 |
-- Warning: any files added to your static directory during run-time can't be |
| 17 |
-- accessed this way. You'll have to use their FilePath or URL to access them. |
| 18 |
-- $(staticFiles Settings.staticDir) |
| 19 |
|
| 20 |
|
| 21 |
staticSite :: IO Static |
| 22 |
staticSite = |
| 23 |
if development |
| 24 |
then (do |
| 25 |
putStrLn ("Running in dev mode, will read static files from " ++ staticDir ++ "/") >> hFlush stdout |
| 26 |
staticDevel staticDir) |
| 27 |
else (do |
| 28 |
-- putStrLn "Using built-in web files" >> hFlush stdout |
| 29 |
return $(embed staticDir)) |
| 30 |
|
| 31 |
$(publicFiles staticDir) |