diff --git a/package.json b/package.json new file mode 100644 index 0000000..85759c8 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "lebd", + "version": "1.1.0", + "description": "the codebase backing 00dani.me, an indieweb.org site", + "repository": { + "type": "git", + "url": "https://gitlab.com/00dani/lebd" + }, + "author": "Danielle McLean ", + "license": "MIT", + "bugs": { + "url": "https://gitlab.com/00dani/lebd/issues" + }, + "homepage": "https://gitlab.com/00dani/lebd#README" +} diff --git a/src/Foundation.hs b/src/Foundation.hs index ac5ac45..e441d28 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -20,10 +20,7 @@ import Yesod.Default.Util (addStaticContentExternal) import Yesod.Core.Types (Logger) import qualified Yesod.Core.Unsafe as Unsafe -import Development.GitRev (gitBranch) - -appVersion :: Text -appVersion = $(gitBranch) +import Package -- | The foundation datatype for your application. This can be a good place to -- keep settings and values requiring initialization before your application diff --git a/src/Package.hs b/src/Package.hs new file mode 100644 index 0000000..7276272 --- /dev/null +++ b/src/Package.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE TemplateHaskell #-} + +module Package ( Package(..) + , Repository(..) + , package + ) where + +import Data.Aeson ( eitherDecodeStrict ) +import Data.Either ( either ) +import Language.Haskell.TH.Syntax ( addDependentFile, lift, runIO ) +import Package.Types + +import qualified Data.ByteString as B + +package :: Package +package = $(do + let f = "package.json" + addDependentFile f + json <- runIO $ B.readFile f + let result = eitherDecodeStrict json :: Either String Package + either fail lift result) diff --git a/src/Package/Types.hs b/src/Package/Types.hs new file mode 100644 index 0000000..55fa5d7 --- /dev/null +++ b/src/Package/Types.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE DeriveLift #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TemplateHaskell #-} + +module Package.Types where + +import Data.Aeson +import Data.Aeson.Types ( fieldLabelModifier ) +import Data.Aeson.TH ( deriveJSON ) + +import Data.Char ( toLower ) +import Language.Haskell.TH.Syntax ( Lift ) +import Util ( mapFirst ) + +data Package = Package + { packageName :: !String + , packageVersion :: !String + , packageRepository :: !Repository + } deriving (Show, Lift) + +data Repository = Repository + { repositoryType :: !String + , repositoryUrl :: !String + } deriving (Show, Lift) + +$(deriveJSON defaultOptions { fieldLabelModifier = mapFirst toLower . drop 7 } ''Package) +$(deriveJSON defaultOptions { fieldLabelModifier = mapFirst toLower . drop 10 } ''Repository) diff --git a/src/Settings.hs b/src/Settings.hs index c127a64..e1ea0d1 100644 --- a/src/Settings.hs +++ b/src/Settings.hs @@ -64,10 +64,6 @@ data AppSettings = AppSettings -- ^ Google Analytics code , appTitle :: Maybe Text -- ^ Site-wide title. - , appName :: Text - -- ^ Name of application used to generate site. - , appRepository :: Text - -- ^ URL of repository for application source. , appAuthDummyLogin :: Bool -- ^ Indicate if auth dummy login should be enabled. @@ -98,8 +94,6 @@ instance FromJSON AppSettings where appAnalytics <- o .:? "analytics" appTitle <- o .:? "title" - appName <- o .: "app-name" - appRepository <- o .: "repository" -- This code enables MySQL's strict mode, without which MySQL will truncate data. -- See https://github.com/yesodweb/persistent/wiki/Database-Configuration#strict-mode for details diff --git a/src/Util.hs b/src/Util.hs new file mode 100644 index 0000000..bffa975 --- /dev/null +++ b/src/Util.hs @@ -0,0 +1,5 @@ +module Util where + +mapFirst :: (a -> a) -> [a] -> [a] +mapFirst f (x:xs) = f x : xs +mapFirst _ [] = [] diff --git a/templates/default-layout-wrapper.hamlet b/templates/default-layout-wrapper.hamlet index 96a0d0a..a1adfb3 100644 --- a/templates/default-layout-wrapper.hamlet +++ b/templates/default-layout-wrapper.hamlet @@ -7,7 +7,7 @@ $doctype 5 #{pageTitle pc} <meta name="description" content=""> <meta name="author" content=""> - <meta name="generator" content="#{appName $ appSettings master} #{appVersion}"> + <meta name="generator" content="#{packageName package} #{packageVersion package}"> $maybe route <- mcurrentRoute <link rel="canonical" href=@{route}> diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index a3845b3..4d9da5d 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -29,8 +29,9 @@ <footer> <p> - all content licensed under + all content licensed under # <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">cc by-sa 4.0 - <p> - powered by - <a href="#{appRepository $ appSettings master}/tree/#{appVersion}">#{appName $ appSettings master} #{appVersion} + $with Package { packageName = n, packageVersion = v, packageRepository = r } <- package + <p> + powered by # + <a href="#{repositoryUrl r}/tree/#{v}">#{n} #{v}