Add WebsiteContent #48

This commit is contained in:
Michael Snoyman 2014-12-09 14:01:38 +02:00
parent 4be4f8fafe
commit 968805f01f
7 changed files with 43 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import Control.Monad.Logger (runLoggingT, LoggingT, defaultLogStr)
import Data.BlobStore (fileStore, storeWrite, cachedS3Store) import Data.BlobStore (fileStore, storeWrite, cachedS3Store)
import Data.Hackage import Data.Hackage
import Data.Hackage.Views import Data.Hackage.Views
import Data.WebsiteContent
import Data.Slug (SnapSlug (..), safeMakeSlug, HasGenIO) import Data.Slug (SnapSlug (..), safeMakeSlug, HasGenIO)
import Data.Time (diffUTCTime) import Data.Time (diffUTCTime)
import qualified Database.Esqueleto as E import qualified Database.Esqueleto as E
@ -33,11 +34,13 @@ import Yesod.Core.Types (loggerSet, Logger (Logger))
import Yesod.Default.Config import Yesod.Default.Config
import Yesod.Default.Handlers import Yesod.Default.Handlers
import Yesod.Default.Main import Yesod.Default.Main
import Yesod.GitRepo (gitRepo)
import System.Environment (getEnvironment) import System.Environment (getEnvironment)
import Data.BlobStore (HasBlobStore (..), BlobStore) import Data.BlobStore (HasBlobStore (..), BlobStore)
import System.IO (hSetBuffering, BufferMode (LineBuffering)) import System.IO (hSetBuffering, BufferMode (LineBuffering))
import qualified Data.ByteString as S import qualified Data.ByteString as S
import qualified Data.Text as T import qualified Data.Text as T
import System.Process (rawSystem)
import qualified Echo import qualified Echo
@ -163,6 +166,17 @@ makeFoundation useEcho conf = do
(statusRef, unpacker) <- createHaddockUnpacker haddockRootDir' blobStore' (statusRef, unpacker) <- createHaddockUnpacker haddockRootDir' blobStore'
widgetCache' <- newIORef mempty widgetCache' <- newIORef mempty
when development $ void $ rawSystem "git"
[ "clone"
, "https://github.com/fpco/stackage-content.git"
]
websiteContent' <- gitRepo
(if development
then "stackage-content"
else "https://github.com/fpco/stackage-content.git")
"master"
loadWebsiteContent
let logger = Yesod.Core.Types.Logger loggerSet' getter let logger = Yesod.Core.Types.Logger loggerSet' getter
foundation = App foundation = App
{ settings = conf { settings = conf
@ -179,6 +193,7 @@ makeFoundation useEcho conf = do
, haddockUnpacker = unpacker , haddockUnpacker = unpacker
, widgetCache = widgetCache' , widgetCache = widgetCache'
, compressorStatus = statusRef , compressorStatus = statusRef
, websiteContent = websiteContent'
} }
-- Perform database migration using our application's logging settings. -- Perform database migration using our application's logging settings.

17
Data/WebsiteContent.hs Normal file
View File

@ -0,0 +1,17 @@
module Data.WebsiteContent
( WebsiteContent (..)
, loadWebsiteContent
) where
import ClassyPrelude.Yesod
import Text.Blaze.Html (preEscapedToMarkup)
data WebsiteContent = WebsiteContent
{ wcHomepage :: !Html
}
loadWebsiteContent :: FilePath -> IO WebsiteContent
loadWebsiteContent dir = do
wcHomepage <- fmap (preEscapedToMarkup :: Text -> Html)
$ readFile $ dir </> "homepage.html"
return WebsiteContent {..}

View File

@ -3,6 +3,7 @@ module Foundation where
import ClassyPrelude.Yesod import ClassyPrelude.Yesod
import Data.BlobStore import Data.BlobStore
import Data.Slug (safeMakeSlug, HasGenIO (getGenIO), randomSlug, Slug, SnapSlug) import Data.Slug (safeMakeSlug, HasGenIO (getGenIO), randomSlug, Slug, SnapSlug)
import Data.WebsiteContent
import qualified Database.Persist import qualified Database.Persist
import Model import Model
import qualified Settings import qualified Settings
@ -19,6 +20,7 @@ import Yesod.Auth.GoogleEmail2
import Yesod.Core.Types (Logger, GWData) import Yesod.Core.Types (Logger, GWData)
import Yesod.Default.Config import Yesod.Default.Config
import Yesod.Default.Util (addStaticContentExternal) import Yesod.Default.Util (addStaticContentExternal)
import Yesod.GitRepo
-- | The site argument for your application. This can be a good place to -- | The site argument for your application. This can be a good place to
-- keep settings and values requiring initialization before your application -- keep settings and values requiring initialization before your application
@ -43,6 +45,7 @@ data App = App
-- unpack job. -- unpack job.
, widgetCache :: !(IORef (HashMap Text (UTCTime, GWData (Route App)))) , widgetCache :: !(IORef (HashMap Text (UTCTime, GWData (Route App))))
, compressorStatus :: !(IORef Text) , compressorStatus :: !(IORef Text)
, websiteContent :: GitRepo WebsiteContent
} }
type ForceUnpack = Bool type ForceUnpack = Bool

View File

@ -4,6 +4,7 @@ module Handler.Home where
import Data.Slug import Data.Slug
import Database.Esqueleto as E hiding (isNothing) import Database.Esqueleto as E hiding (isNothing)
import Import hiding ((=.),on,(||.),(==.)) import Import hiding ((=.),on,(||.),(==.))
import Yesod.GitRepo (grContent)
-- This is a handler function for the G request method on the HomeR -- This is a handler function for the G request method on the HomeR
-- resource pattern. All of your resource patterns are defined in -- resource pattern. All of your resource patterns are defined in
@ -16,13 +17,15 @@ getHomeR :: Handler Html
getHomeR = do getHomeR = do
windowsLatest <- linkFor "unstable-ghc78hp-inclusive" windowsLatest <- linkFor "unstable-ghc78hp-inclusive"
restLatest <- linkFor "unstable-ghc78-inclusive" restLatest <- linkFor "unstable-ghc78-inclusive"
homepage <- getYesod >>= fmap wcHomepage . liftIO . grContent . websiteContent
defaultLayout $ do defaultLayout $ do
setTitle "Stackage Server" setTitle "Stackage Server"
$(combineStylesheets 'StaticR $(combineStylesheets 'StaticR
[ css_bootstrap_modified_css [ css_bootstrap_modified_css
, css_bootstrap_responsive_modified_css , css_bootstrap_responsive_modified_css
]) ])
$(widgetFile "homepage") toWidget homepage
-- $(widgetFile "homepage")
where where
linkFor name = linkFor name =
do slug <- mkSlug name do slug <- mkSlug name

View File

@ -11,6 +11,7 @@ import Settings.StaticFiles as Import
import Types as Import import Types as Import
import Yesod.Auth as Import import Yesod.Auth as Import
import Data.Slug (mkSlug) import Data.Slug (mkSlug)
import Data.WebsiteContent as Import (WebsiteContent (..))
requireAuthIdOrToken :: Handler UserId requireAuthIdOrToken :: Handler UserId
requireAuthIdOrToken = do requireAuthIdOrToken = do

View File

@ -1,5 +1,6 @@
/static StaticR Static getStatic /static StaticR Static getStatic
/auth AuthR Auth getAuth /auth AuthR Auth getAuth
/reload WebsiteContentR GitRepo-WebsiteContent websiteContent
/favicon.ico FaviconR GET /favicon.ico FaviconR GET
/robots.txt RobotsR GET /robots.txt RobotsR GET

View File

@ -26,6 +26,7 @@ library
Data.BlobStore Data.BlobStore
Data.Hackage Data.Hackage
Data.Hackage.Views Data.Hackage.Views
Data.WebsiteContent
Types Types
Handler.Home Handler.Home
Handler.Snapshots Handler.Snapshots
@ -146,6 +147,7 @@ library
, formatting , formatting
, blaze-html , blaze-html
, haddock-library , haddock-library
, yesod-gitrepo
executable stackage-server executable stackage-server
if flag(library-only) if flag(library-only)