Add a package.json, load generator info from it instead of from settings.yml

This commit is contained in:
Danielle McLean 2017-10-05 16:19:15 +11:00
parent 353f1aa994
commit 4692e78503
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
8 changed files with 75 additions and 15 deletions

15
package.json Normal file
View 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"
}

View file

@ -20,10 +20,7 @@ import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Core.Types (Logger) import Yesod.Core.Types (Logger)
import qualified Yesod.Core.Unsafe as Unsafe import qualified Yesod.Core.Unsafe as Unsafe
import Development.GitRev (gitBranch) import Package
appVersion :: Text
appVersion = $(gitBranch)
-- | The foundation datatype for your application. This can be a good place to -- | The foundation datatype for your application. This can be a good place to
-- keep settings and values requiring initialization before your application -- keep settings and values requiring initialization before your application

21
src/Package.hs Normal file
View 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
View 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)

View file

@ -64,10 +64,6 @@ data AppSettings = AppSettings
-- ^ Google Analytics code -- ^ Google Analytics code
, appTitle :: Maybe Text , appTitle :: Maybe Text
-- ^ Site-wide title. -- ^ Site-wide title.
, appName :: Text
-- ^ Name of application used to generate site.
, appRepository :: Text
-- ^ URL of repository for application source.
, appAuthDummyLogin :: Bool , appAuthDummyLogin :: Bool
-- ^ Indicate if auth dummy login should be enabled. -- ^ Indicate if auth dummy login should be enabled.
@ -98,8 +94,6 @@ instance FromJSON AppSettings where
appAnalytics <- o .:? "analytics" appAnalytics <- o .:? "analytics"
appTitle <- o .:? "title" appTitle <- o .:? "title"
appName <- o .: "app-name"
appRepository <- o .: "repository"
-- This code enables MySQL's strict mode, without which MySQL will truncate data. -- 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 -- See https://github.com/yesodweb/persistent/wiki/Database-Configuration#strict-mode for details

5
src/Util.hs Normal file
View file

@ -0,0 +1,5 @@
module Util where
mapFirst :: (a -> a) -> [a] -> [a]
mapFirst f (x:xs) = f x : xs
mapFirst _ [] = []

View file

@ -7,7 +7,7 @@ $doctype 5
<title>#{pageTitle pc} <title>#{pageTitle pc}
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content=""> <meta name="author" content="">
<meta name="generator" content="#{appName $ appSettings master} #{appVersion}"> <meta name="generator" content="#{packageName package} #{packageVersion package}">
$maybe route <- mcurrentRoute $maybe route <- mcurrentRoute
<link rel="canonical" href=@{route}> <link rel="canonical" href=@{route}>

View file

@ -29,8 +29,9 @@
<footer> <footer>
<p> <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 <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">cc by-sa 4.0
$with Package { packageName = n, packageVersion = v, packageRepository = r } <- package
<p> <p>
powered by powered by #
<a href="#{appRepository $ appSettings master}/tree/#{appVersion}">#{appName $ appSettings master} #{appVersion} <a href="#{repositoryUrl r}/tree/#{v}">#{n} #{v}