Skip to content

Commit

Permalink
embedded css stylesheet in trident
Browse files Browse the repository at this point in the history
  • Loading branch information
nevrome committed Jan 7, 2025
1 parent 8e20e8a commit f72488c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Embedded data files

- pico.classless.blue.min.css: CSS stylesheet from https://picocss.com
4 changes: 4 additions & 0 deletions data/pico.classless.blue.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions poseidon-hs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ library
exposed-modules: Poseidon.Package, Poseidon.GenotypeData, Poseidon.BibFile, Poseidon.Janno,
Poseidon.ColumnTypes, Poseidon.ColumnTypesUtils, Poseidon.MathHelpers,
Poseidon.PoseidonVersion, Poseidon.SequencingSource, Poseidon.Chronicle,
Poseidon.EntityTypes, Poseidon.ServerClient, Poseidon.ServerHTML
Poseidon.Contributor, Poseidon.Version,
Poseidon.EntityTypes, Poseidon.ServerClient, Poseidon.ServerHTML,
Poseidon.ServerStylesheet, Poseidon.Contributor, Poseidon.Version,
Poseidon.CLI.List, Poseidon.CLI.Chronicle, Poseidon.CLI.Serve,
Poseidon.CLI.Summarise, Poseidon.CLI.Validate, Poseidon.Utils,
Poseidon.CLI.Survey, Poseidon.CLI.Forge, Poseidon.CLI.Init,
Expand All @@ -34,7 +34,7 @@ library
http-conduit, conduit, http-types, zip-archive,
unordered-containers, network-uri, optparse-applicative, co-log, regex-tdfa,
scientific, country, generics-sop, containers, process, deepseq, template-haskell,
blaze-html, blaze-markup, neat-interpolation
blaze-html, blaze-markup, neat-interpolation, file-embed
default-language: Haskell2010

executable trident
Expand Down
13 changes: 9 additions & 4 deletions src/Poseidon/CLI/Serve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Poseidon.ServerClient (AddJannoColSpec (..),
import Poseidon.ServerHTML
import Poseidon.Utils (LogA, PoseidonIO, envLogAction,
logDebug, logInfo, logWithEnv)
import Poseidon.ServerStylesheet (stylesBS)

import Codec.Archive.Zip (Archive, addEntryToArchive,
emptyArchive, fromArchive,
Expand Down Expand Up @@ -55,7 +56,7 @@ import Text.ParserCombinators.ReadP (readP_to_S)
import Web.Scotty (ActionM, ScottyM, file, get,
json, middleware, notFound,
param, raise, request, rescue,
scottyApp, text)
scottyApp, text, setHeader, raw)

data ServeOptions = ServeOptions
{ cliArchiveBaseDirs :: [(String, FilePath)]
Expand Down Expand Up @@ -170,8 +171,12 @@ runServer (ServeOptions archBaseDirs maybeZipPath port ignoreChecksums certFiles
[(_, fn)] -> file fn
_ -> error "Should never happen" -- packageCollection should have been filtered to have only one version per package

-- http API
-- html API

-- css stylesheet
get "/styles.css" $ do
setHeader "Content-Type" "text/css; charset=utf-8"
raw stylesBS
-- landing page
get "/" $ do
logRequest logA
Expand Down Expand Up @@ -357,9 +362,9 @@ makeZipArchive pac =
addFN :: FilePath -> Archive -> IO Archive
addFN fn a = do
let fullFN = posPacBaseDir pac </> fn
raw <- B.readFile fullFN
rawFN <- B.readFile fullFN
modTime <- round . utcTimeToPOSIXSeconds <$> getModificationTime fullFN
let zipEntry = toEntry fn modTime raw
let zipEntry = toEntry fn modTime rawFN
return (addEntryToArchive zipEntry a)

scottyHTTPS :: MVar () -> Int -> FilePath -> [FilePath] -> FilePath -> ScottyM () -> PoseidonIO ()
Expand Down
2 changes: 1 addition & 1 deletion src/Poseidon/ServerHTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jscript = [text|
headerWithCSS :: H.Markup
headerWithCSS = H.head $ do
H.script ! A.type_ "text/javascript" $ H.text jscript
H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href "https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.blue.min.css"
H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href "/styles.css"

navBar :: H.Html
navBar = H.nav $ do
Expand Down
9 changes: 9 additions & 0 deletions src/Poseidon/ServerStylesheet.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{-# LANGUAGE TemplateHaskell #-}

module Poseidon.ServerStylesheet (stylesBS) where

import qualified Data.FileEmbed as FE
import Data.ByteString.Lazy as BL

stylesBS :: BL.ByteString
stylesBS = BL.fromStrict $(FE.embedFile "data/pico.classless.blue.min.css")

0 comments on commit f72488c

Please sign in to comment.