Add a package.json, load generator info from it instead of from settings.yml
This commit is contained in:
parent
353f1aa994
commit
4692e78503
8 changed files with 75 additions and 15 deletions
15
package.json
Normal file
15
package.json
Normal file
|
@ -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 <dani@00dani.me>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/00dani/lebd/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/00dani/lebd#README"
|
||||
}
|
|
@ -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
|
||||
|
|
21
src/Package.hs
Normal file
21
src/Package.hs
Normal file
|
@ -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)
|
27
src/Package/Types.hs
Normal file
27
src/Package/Types.hs
Normal file
|
@ -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)
|
|
@ -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
|
||||
|
|
5
src/Util.hs
Normal file
5
src/Util.hs
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Util where
|
||||
|
||||
mapFirst :: (a -> a) -> [a] -> [a]
|
||||
mapFirst f (x:xs) = f x : xs
|
||||
mapFirst _ [] = []
|
|
@ -7,7 +7,7 @@ $doctype 5
|
|||
<title>#{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}>
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue