yesod-static support for assuming a .html ext
This commit is contained in:
parent
26a78f41ce
commit
010e9425b2
@ -34,6 +34,8 @@ module Yesod.Static
|
|||||||
-- * Smart constructor
|
-- * Smart constructor
|
||||||
, static
|
, static
|
||||||
, staticDevel
|
, staticDevel
|
||||||
|
, staticAssumeHtml
|
||||||
|
, staticAssumeHtmlDevel
|
||||||
, embed
|
, embed
|
||||||
-- * Template Haskell helpers
|
-- * Template Haskell helpers
|
||||||
, staticFiles
|
, staticFiles
|
||||||
@ -90,7 +92,9 @@ import Network.Wai.Application.Static
|
|||||||
, fromFilePath
|
, fromFilePath
|
||||||
, FilePath
|
, FilePath
|
||||||
, ETagLookup
|
, ETagLookup
|
||||||
, webAppSettingsWithLookup
|
, webAppSettingsLookupConf
|
||||||
|
, WebAppLookupConf(..)
|
||||||
|
, defaultMimeTypeLookup
|
||||||
)
|
)
|
||||||
|
|
||||||
-- | Type used for the subsite with static contents.
|
-- | Type used for the subsite with static contents.
|
||||||
@ -106,8 +110,24 @@ type StaticRoute = Route Static
|
|||||||
-- added.
|
-- added.
|
||||||
static :: Prelude.FilePath -> IO Static
|
static :: Prelude.FilePath -> IO Static
|
||||||
static dir = do
|
static dir = do
|
||||||
hashLookup <- cachedETagLookup dir
|
hashLookup <- cachedETagLookup dir
|
||||||
return $ Static $ webAppSettingsWithLookup (toFilePath dir) hashLookup
|
staticFromSettings dir False hashLookup
|
||||||
|
|
||||||
|
staticFromSettings :: Prelude.FilePath -> Bool -> ETagLookup -> IO Static
|
||||||
|
staticFromSettings dir shouldAppend hashLookup = do
|
||||||
|
return $ Static $ webAppSettingsLookupConf WebAppLookupConf {
|
||||||
|
assumeHtml = shouldAppend,
|
||||||
|
prefixDir = (toFilePath dir),
|
||||||
|
etagLookup = hashLookup,
|
||||||
|
mimeTypeLookup = defaultMimeTypeLookup
|
||||||
|
}
|
||||||
|
|
||||||
|
-- | same as static, but if there is no file extension in the request then assume html
|
||||||
|
staticAssumeHtml :: Prelude.FilePath -> IO Static
|
||||||
|
staticAssumeHtml dir = do
|
||||||
|
hashLookup <- cachedETagLookup dir
|
||||||
|
staticFromSettings dir True hashLookup
|
||||||
|
|
||||||
|
|
||||||
-- | Same as 'static', but does not assumes that the files do not
|
-- | Same as 'static', but does not assumes that the files do not
|
||||||
-- change and checks their modification time whenever a request
|
-- change and checks their modification time whenever a request
|
||||||
@ -115,7 +135,13 @@ static dir = do
|
|||||||
staticDevel :: Prelude.FilePath -> IO Static
|
staticDevel :: Prelude.FilePath -> IO Static
|
||||||
staticDevel dir = do
|
staticDevel dir = do
|
||||||
hashLookup <- cachedETagLookupDevel dir
|
hashLookup <- cachedETagLookupDevel dir
|
||||||
return $ Static $ webAppSettingsWithLookup (toFilePath dir) hashLookup
|
staticFromSettings dir False hashLookup
|
||||||
|
|
||||||
|
-- | same as staticDevel, but if there is no file extension in the request then assume html
|
||||||
|
staticAssumeHtmlDevel :: Prelude.FilePath -> IO Static
|
||||||
|
staticAssumeHtmlDevel dir = do
|
||||||
|
hashLookup <- cachedETagLookupDevel dir
|
||||||
|
staticFromSettings dir True hashLookup
|
||||||
|
|
||||||
-- | Produce a 'Static' based on embedding all of the static
|
-- | Produce a 'Static' based on embedding all of the static
|
||||||
-- files' contents in the executable at compile time.
|
-- files' contents in the executable at compile time.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user