Use fourmolu instead of stylish-haskell
This commit is contained in:
+35
-32
@@ -13,17 +13,17 @@ import Data.Time (Day, toGregorian)
|
||||
import Network.HTTP.Media ((//), (/:))
|
||||
import Network.HTTP.Types (status200)
|
||||
import Servant
|
||||
( Accept (..)
|
||||
, Capture
|
||||
, Get
|
||||
, MimeRender (..)
|
||||
, Raw
|
||||
, Server
|
||||
, Tagged (..)
|
||||
, serve
|
||||
, (:<|>) (..)
|
||||
, (:>)
|
||||
)
|
||||
( Accept (..)
|
||||
, Capture
|
||||
, Get
|
||||
, MimeRender (..)
|
||||
, Raw
|
||||
, Server
|
||||
, Tagged (..)
|
||||
, serve
|
||||
, (:<|>) (..)
|
||||
, (:>)
|
||||
)
|
||||
import System.FilePath ((</>))
|
||||
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
|
||||
import Text.Blaze.Html5 ((!))
|
||||
@@ -48,20 +48,21 @@ main :: IO ()
|
||||
main = do
|
||||
capabilities <- getNumCapabilities
|
||||
let maxResources = capabilities
|
||||
connPool <- newPool $ defaultPoolConfig
|
||||
(unsafeConnect "host=localhost port=5433 user=yore-test dbname=yore-test")
|
||||
Opium.close
|
||||
10
|
||||
maxResources
|
||||
connPool <-
|
||||
newPool $
|
||||
defaultPoolConfig
|
||||
(unsafeConnect "host=localhost port=5433 user=yore-test dbname=yore-test")
|
||||
Opium.close
|
||||
10
|
||||
maxResources
|
||||
Warp.run 3000 $ serve (Proxy :: Proxy API) $ server connPool
|
||||
|
||||
where
|
||||
unsafeConnect s = either throwIO pure =<< Opium.connect s
|
||||
|
||||
type API
|
||||
= Get '[HTML] RootModel
|
||||
:<|> "today" :> "issue" :> Capture "issue" Int :> Get '[HTML] RootModel
|
||||
:<|> "api" :> "today" :> "issue" :> Capture "issue" Int :> "fz.pdf" :> Raw
|
||||
type API =
|
||||
Get '[HTML] RootModel
|
||||
:<|> "today" :> "issue" :> Capture "issue" Int :> Get '[HTML] RootModel
|
||||
:<|> "api" :> "today" :> "issue" :> Capture "issue" Int :> "fz.pdf" :> Raw
|
||||
|
||||
server :: Pool Opium.Connection -> Server API
|
||||
server connPool = rootR :<|> todayR :<|> apiTodayR
|
||||
@@ -82,13 +83,14 @@ server connPool = rootR :<|> todayR :<|> apiTodayR
|
||||
let fullPath = "download" </> dayFile.relative_path
|
||||
secondsUntilMidnight <- getSecondsUntilMidnight
|
||||
|
||||
respond $ responseFile
|
||||
status200
|
||||
[ ("content-type", "application/pdf")
|
||||
, ("cache-control", BS8.pack $ printf "public, max-age=%d" secondsUntilMidnight)
|
||||
]
|
||||
fullPath
|
||||
Nothing
|
||||
respond $
|
||||
responseFile
|
||||
status200
|
||||
[ ("content-type", "application/pdf")
|
||||
, ("cache-control", BS8.pack $ printf "public, max-age=%d" secondsUntilMidnight)
|
||||
]
|
||||
fullPath
|
||||
Nothing
|
||||
|
||||
data RootModel = RootModel Day DB.DayFile Int Int
|
||||
|
||||
@@ -96,7 +98,8 @@ instance MimeRender HTML RootModel where
|
||||
mimeRender _ (RootModel dateThen dayFile issue count) = renderHtml $ do
|
||||
H.docTypeHtml $ do
|
||||
H.head $ do
|
||||
H.style "body { margin: 0; font-family: Helvetica, sans-serif; } .layout { display: flex; flex-direction: column; width: 100vw; height: 100vh; } .topbar { user-select: none; text-align: center; padding: .5em; } .content { flex: 1; } iframe { border: 0; }"
|
||||
H.style
|
||||
"body { margin: 0; font-family: Helvetica, sans-serif; } .layout { display: flex; flex-direction: column; width: 100vw; height: 100vh; } .topbar { user-select: none; text-align: center; padding: .5em; } .content { flex: 1; } iframe { border: 0; }"
|
||||
H.body $ do
|
||||
H.div ! A.class_ "layout" $ do
|
||||
H.div ! A.class_ "topbar" $ do
|
||||
@@ -113,11 +116,11 @@ instance MimeRender HTML RootModel where
|
||||
|
||||
buildLink label issue'
|
||||
| issue' == 0 =
|
||||
H.a ! A.href "/" $ label
|
||||
H.a ! A.href "/" $ label
|
||||
| issue' > 0 && issue' < count =
|
||||
H.a ! A.href (H.toValue (printf "/today/issue/%d" issue' :: String)) $ label
|
||||
H.a ! A.href (H.toValue (printf "/today/issue/%d" issue' :: String)) $ label
|
||||
| otherwise =
|
||||
H.span ! A.style "color: grey;" $ label
|
||||
H.span ! A.style "color: grey;" $ label
|
||||
|
||||
-- Utils
|
||||
|
||||
|
||||
Reference in New Issue
Block a user