expose publicFiles- no etag in the query string

this makes compilation faster for large amounts of files
This commit is contained in:
Greg Weber 2011-08-12 23:10:58 -07:00
parent 709a6892da
commit d7ff46bccd

View File

@ -34,6 +34,7 @@ module Yesod.Static
, embed , embed
-- * Template Haskell helpers -- * Template Haskell helpers
, staticFiles , staticFiles
, publicFiles
-- * Hashing -- * Hashing
, base64md5 , base64md5
) where ) where
@ -74,7 +75,7 @@ import Network.Wai.Application.Static
, staticApp , staticApp
, embeddedLookup , embeddedLookup
, toEmbedded , toEmbedded
, pathFromPieces -- , pathFromPieces
, toFilePath , toFilePath
) )
@ -82,8 +83,7 @@ newtype Static = Static StaticSettings
-- | Default value of 'Static' for a given file folder. -- | Default value of 'Static' for a given file folder.
-- --
-- Does not have index files, uses default directory listings and default mime -- Does not have index files or directory listings.
-- type list.
static :: Prelude.FilePath -> Static static :: Prelude.FilePath -> Static
static fp = static fp =
--hashes <- mkHashMap fp --hashes <- mkHashMap fp
@ -161,10 +161,11 @@ getFileListPieces = flip go id
staticFiles :: Prelude.FilePath -> Q [Dec] staticFiles :: Prelude.FilePath -> Q [Dec]
staticFiles dir = mkStaticFiles dir staticFiles dir = mkStaticFiles dir
{- -- | like staticFiles, but doesn't append an etag to the query string
-- This will compile faster, but doesn't achieve as great of caching.
-- The browser can avoid downloading the file, but it always needs to send a request with the etag value or the last-modified value to the server to see if its copy is up to dat
publicFiles :: Prelude.FilePath -> Q [Dec] publicFiles :: Prelude.FilePath -> Q [Dec]
publicFiles dir = mkStaticFiles dir PublicSite publicFiles dir = mkStaticFiles' dir "StaticRoute" False
-}
mkHashMap :: Prelude.FilePath -> IO (M.Map Prelude.FilePath S8.ByteString) mkHashMap :: Prelude.FilePath -> IO (M.Map Prelude.FilePath S8.ByteString)
mkHashMap dir = do mkHashMap dir = do
@ -208,7 +209,6 @@ mkPublicProductionEtag dir = do
return $ ETag $ \f -> return . M.lookup f $ etags return $ ETag $ \f -> return . M.lookup f $ etags
-} -}
data StaticSite = StaticSite | PublicSite
mkStaticFiles :: Prelude.FilePath -> Q [Dec] mkStaticFiles :: Prelude.FilePath -> Q [Dec]
mkStaticFiles fp = mkStaticFiles' fp "StaticRoute" True mkStaticFiles fp = mkStaticFiles' fp "StaticRoute" True
@ -227,7 +227,7 @@ mkStaticFiles' fp routeConName makeHash = do
| otherwise = '_' | otherwise = '_'
mkRoute f = do mkRoute f = do
let name' = intercalate "_" $ map (map replace') f let name' = intercalate "_" $ map (map replace') f
name = mkName $ routeName = mkName $
case () of case () of
() ()
| null name' -> error "null-named file" | null name' -> error "null-named file"
@ -243,8 +243,8 @@ mkStaticFiles' fp routeConName makeHash = do
[|[(pack $(lift hash), mempty)]|] [|[(pack $(lift hash), mempty)]|]
else return $ ListE [] else return $ ListE []
return return
[ SigD name $ ConT route [ SigD routeName $ ConT route
, FunD name , FunD routeName
[ Clause [] (NormalB $ (ConE route) `AppE` f' `AppE` qs) [] [ Clause [] (NormalB $ (ConE route) `AppE` f' `AppE` qs) []
] ]
] ]