From 035cc1de3b9810dbb851bf41ceb872aececcda42 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 10 Oct 2017 00:19:23 +1100 Subject: [PATCH] Make generated CSS files group-readable so that nginx can actually serve them without me manually chmodding --- package.yaml | 1 + src/Foundation.hs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/package.yaml b/package.yaml index ed8552f..d156a65 100644 --- a/package.yaml +++ b/package.yaml @@ -53,6 +53,7 @@ dependencies: - foreign-store >=0.2 && <0.3 - slug >=0.1 && <0.2 - split >=0.2 && <0.3 +- unix >=2.7 && <2.8 - yesod-auth-hashdb >=1.6.2 && <1.7 - yesod-newsfeed >=1.6 && <1.7 - yesod-sitemap >=1.4 && <1.5 diff --git a/src/Foundation.hs b/src/Foundation.hs index 57f0883..ed59f27 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -25,7 +25,9 @@ import Entry.Kind ( EntryKind, allEntryKinds, pluralise ) import Data.Aeson ( encode, object ) import qualified Text.Blaze.Internal as B +import qualified Data.Text as T import qualified Data.Text.Lazy.Encoding as E +import qualified System.Posix.Files as F -- | The foundation datatype for your application. This can be a good place to -- keep settings and values requiring initialization before your application @@ -130,7 +132,7 @@ instance Yesod App where addStaticContent ext mime content = do master <- getYesod let staticDir = appStaticDir $ appSettings master - addStaticContentExternal + external <- addStaticContentExternal minifym genFileName staticDir @@ -138,6 +140,13 @@ instance Yesod App where ext mime content + case external of + (Just (Right (StaticR (StaticRoute filePath _), _))) -> liftIO $ do + let staticPath = ((staticDir ++ "/") ++) . T.unpack . T.intercalate "/" $ filePath + mode <- F.fileMode <$> F.getFileStatus staticPath + F.setFileMode staticPath $ mode `F.unionFileModes` F.groupReadMode + _ -> return () + return external where -- Generate a unique filename based on the content itself genFileName lbs = "autogen-" ++ base64md5 lbs