hablog 0.5.0 → 0.5.1
raw patch · 4 files changed
+48/−23 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Web.Hablog.Config: instance GHC.Read.Read Web.Hablog.Config.Config
+ Web.Hablog.Config: instance GHC.Read.Read Web.Hablog.Config.TLSConfig
+ Web.Hablog.Config: instance GHC.Read.Read Web.Hablog.Config.Theme
- Web.Hablog.Config: Theme :: AttributeValue -> AttributeValue -> Theme
+ Web.Hablog.Config: Theme :: FilePath -> FilePath -> Theme
- Web.Hablog.Config: [bgTheme] :: Theme -> AttributeValue
+ Web.Hablog.Config: [bgTheme] :: Theme -> FilePath
- Web.Hablog.Config: [codeTheme] :: Theme -> AttributeValue
+ Web.Hablog.Config: [codeTheme] :: Theme -> FilePath
- Web.Hablog.Config: defaultTheme :: Theme
+ Web.Hablog.Config: defaultTheme :: (String, Theme)
Files
- app/Main.hs +36/−9
- hablog.cabal +2/−1
- src/Web/Hablog/Config.hs +8/−11
- src/Web/Hablog/Html.hs +2/−2
app/Main.hs view
@@ -7,14 +7,15 @@ import Control.Monad (void) import Control.Concurrent (forkIO) import Data.List (intercalate)+import Data.Text.Lazy (pack, unpack) import Options.Applicative import Web.Hablog main :: IO () main = do args <- execParser paramsParserInfo- let cfg = defaultConfig { blogTheme = pTheme args }- case pCfg args of+ let cfg = pCfg args+ case pCmd args of HTTP port -> run cfg port HTTPS tlsCfg ->@@ -23,37 +24,54 @@ void $ forkIO $ run cfg port runTLS tlsCfg cfg + -------------------- -- Options Parser -------------------- data Params = Params- { pTheme :: Theme- , pCfg :: Command+ { pCfg :: Config+ , pCmd :: Command }- deriving Show+ deriving (Show, Read) data Command = HTTP Int | HTTPS TLSConfig | Both Int TLSConfig- deriving Show+ deriving (Show, Read) paramsParserInfo :: ParserInfo Params paramsParserInfo =- info (helper <*> (Params <$> fmap snd thm <*> cmd)) $+ info (helper <*> (Params <$> config <*> cmd)) $ fullDesc <> header "Hablog - A blogging System" +config :: Parser Config+config = Config+ <$> fmap pack ttl+ <*> fmap snd thm+ where+ ttl =+ strOption+ (long "title"+ <> short 't'+ <> metavar "NAME"+ <> help "Title for the blog"+ <> showDefault+ <> value (unpack defaultTitle)+ )++ thm :: Parser (String, Theme) thm = option (str >>= readTheme) (long "theme"- <> short 't'+ <> short 'T' <> metavar "THEME" <> help "Select a blog theme" <> showDefaultWith fst- <> value ("dark", darkTheme)+ <> value defaultTheme ) readTheme :: String -> ReadM (String, Theme)@@ -92,3 +110,12 @@ <$> option auto (long "tls-port" <> short 'P' <> metavar "PORT" <> help "Port for TLS" <> showDefault <> value 443) <*> strOption (long "tls-key" <> short 'k' <> metavar "KEY" <> help "Key file for for TLS") <*> strOption (long "tls-cert" <> short 'c' <> metavar "CERT" <> help "Cert file for for TLS")++fromFile :: Parser FilePath+fromFile =+ strOption+ (long "file"+ <> short 'f'+ <> metavar "FILE"+ <> help "Path to configuration file"+ )
hablog.cabal view
@@ -1,5 +1,5 @@ Name: hablog-Version: 0.5.0+Version: 0.5.1 Synopsis: A blog system Description: blog system with tags License: MIT@@ -78,6 +78,7 @@ Build-depends: base+ ,text ,optparse-applicative ,hablog
src/Web/Hablog/Config.hs view
@@ -5,23 +5,20 @@ module Web.Hablog.Config where import Data.Text.Lazy (Text)-import Text.Blaze.Internal (AttributeValue) -- | Data type to set the theme for your Hablog blog data Theme = Theme- { bgTheme :: AttributeValue -- ^ General theme for hablog. a file path for a css file- , codeTheme :: AttributeValue -- ^ Theme for code. a file path for a highlight.js css file+ { bgTheme :: FilePath -- ^ General theme for hablog. a file path for a css file+ , codeTheme :: FilePath -- ^ Theme for code. a file path for a highlight.js css file }--instance Show Theme where- show _ = "<Theme>"+ deriving (Show, Read) -- | Configuration for Hablog data Config = Config { blogTitle :: Text , blogTheme :: Theme }- deriving Show+ deriving (Show, Read) -- | Requires the needed values for runTLS data TLSConfig = TLSConfig@@ -29,13 +26,13 @@ , blogCert :: FilePath , blogKey :: FilePath }- deriving Show+ deriving (Show, Read) -- | A default configuration defaultConfig :: Config defaultConfig = Config { blogTitle = defaultTitle- , blogTheme = defaultTheme+ , blogTheme = snd defaultTheme } -- | "Hablog"@@ -51,8 +48,8 @@ defaultTLSPort = 443 -- | The default is the dark theme-defaultTheme :: Theme-defaultTheme = darkTheme+defaultTheme :: (String, Theme)+defaultTheme = ("dark", darkTheme) darkTheme :: Theme darkTheme = Theme "/static/css/dark.css" "/static/highlight/styles/hybrid.css"
src/Web/Hablog/Html.hs view
@@ -19,9 +19,9 @@ H.docTypeHtml $ do H.head $ do H.title (H.toHtml (T.concat [blogTitle cfg, " - ", title]))- H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href (bgTheme $ blogTheme cfg)+ H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href (H.stringValue . bgTheme $ blogTheme cfg) if highlight- then H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href (codeTheme $ blogTheme cfg)+ then H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href (H.stringValue . codeTheme $ blogTheme cfg) else mempty H.body $ do H.div ! A.class_ "container" $ do