module MathiasSM.Config (
siteConfiguration,
SiteConfig (..),
Env (..),
baseUrl,
requiredContent,
mediaDir,
projectsGroup,
postSnapshot,
writingsPattern,
pagesPattern,
postsPattern,
projectsPattern,
socialsPattern,
dataPattern,
dataSchemaPattern,
templatePattern,
contentCssPattern,
dataDir,
siteTemplate,
minimalTemplate,
pageTemplate,
postTemplate,
resolveTemplate,
socialsFile,
)
where
import Data.String (fromString)
import Hakyll (Configuration (ignoreFile), Identifier, Pattern, Snapshot, defaultConfiguration, fromFilePath, (.||.))
import MathiasSM.Yaml.Website (HighlightStyle)
import System.FilePath.Posix (takeFileName, (<.>), (</>))
data Env = Dev | Prod
deriving (Env -> Env -> Bool
(Env -> Env -> Bool) -> (Env -> Env -> Bool) -> Eq Env
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Env -> Env -> Bool
== :: Env -> Env -> Bool
$c/= :: Env -> Env -> Bool
/= :: Env -> Env -> Bool
Eq, Int -> Env -> ShowS
[Env] -> ShowS
Env -> FilePath
(Int -> Env -> ShowS)
-> (Env -> FilePath) -> ([Env] -> ShowS) -> Show Env
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Env -> ShowS
showsPrec :: Int -> Env -> ShowS
$cshow :: Env -> FilePath
show :: Env -> FilePath
$cshowList :: [Env] -> ShowS
showList :: [Env] -> ShowS
Show)
data SiteConfig = SiteConfig
{ SiteConfig -> FilePath
siteName :: String
, SiteConfig -> FilePath
siteDescription :: String
, SiteConfig -> FilePath
siteAuthor :: String
, SiteConfig -> Int
siteCopyrightYear :: Int
, SiteConfig -> FilePath
siteDomain :: String
, SiteConfig -> FilePath
twitterHandle :: String
, SiteConfig -> FilePath
mathjaxVersion :: String
, SiteConfig -> HighlightStyle
highlightStyle :: HighlightStyle
, SiteConfig -> FilePath
contentDir :: FilePath
, SiteConfig -> FilePath
assetsDir :: FilePath
, SiteConfig -> FilePath
templatesDir :: FilePath
, SiteConfig -> FilePath
contentTemplatesDir :: FilePath
, SiteConfig -> FilePath
contentCssDir :: FilePath
, SiteConfig -> [FilePath]
contentTemplateNames :: [FilePath]
, SiteConfig -> Env
siteEnv :: Env
}
siteConfiguration :: Configuration
siteConfiguration :: Configuration
siteConfiguration = Configuration
defaultConfiguration{ignoreFile = ignore}
where
ignore :: FilePath -> Bool
ignore FilePath
path = ShowS
takeFileName FilePath
path FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
/= FilePath
".well-known" Bool -> Bool -> Bool
&& Configuration -> FilePath -> Bool
ignoreFile Configuration
defaultConfiguration FilePath
path
baseUrl :: SiteConfig -> String
baseUrl :: SiteConfig -> FilePath
baseUrl SiteConfig
cfg = FilePath
"https://" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ SiteConfig -> FilePath
siteDomain SiteConfig
cfg
mediaDir :: SiteConfig -> FilePath
mediaDir :: SiteConfig -> FilePath
mediaDir SiteConfig
cfg = SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"media"
requiredContent :: SiteConfig -> [FilePath]
requiredContent :: SiteConfig -> [FilePath]
requiredContent SiteConfig
cfg = [SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"socials.yaml"]
projectsGroup :: String
projectsGroup :: FilePath
projectsGroup = FilePath
"showcase"
writingsPattern :: SiteConfig -> Pattern
writingsPattern :: SiteConfig -> Pattern
writingsPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"writings" FilePath -> ShowS
</> FilePath
"**"
pagesPattern :: SiteConfig -> String -> Pattern
pagesPattern :: SiteConfig -> FilePath -> Pattern
pagesPattern SiteConfig
cfg FilePath
name = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"writings" FilePath -> ShowS
</> FilePath
name FilePath -> ShowS
<.> FilePath
"*"
postsPattern :: SiteConfig -> String -> Pattern
postsPattern :: SiteConfig -> FilePath -> Pattern
postsPattern SiteConfig
cfg FilePath
group = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"writings" FilePath -> ShowS
</> FilePath
group FilePath -> ShowS
</> FilePath
"**"
projectsPattern :: SiteConfig -> Pattern
projectsPattern :: SiteConfig -> Pattern
projectsPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"projects" FilePath -> ShowS
</> FilePath
"*.yaml"
socialsPattern :: SiteConfig -> Pattern
socialsPattern :: SiteConfig -> Pattern
socialsPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"socials.yaml"
dataDir :: SiteConfig -> FilePath
dataDir :: SiteConfig -> FilePath
dataDir SiteConfig
cfg = SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"data"
dataPattern :: SiteConfig -> Pattern
dataPattern :: SiteConfig -> Pattern
dataPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
dataDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"**.yaml"
dataSchemaPattern :: SiteConfig -> Pattern
dataSchemaPattern :: SiteConfig -> Pattern
dataSchemaPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
dataDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"**.schema.json"
templatePattern :: SiteConfig -> Pattern
templatePattern :: SiteConfig -> Pattern
templatePattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (SiteConfig -> FilePath
templatesDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"*") Pattern -> Pattern -> Pattern
.||. FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (SiteConfig -> FilePath
contentTemplatesDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"*")
contentCssPattern :: SiteConfig -> Pattern
contentCssPattern :: SiteConfig -> Pattern
contentCssPattern SiteConfig
cfg = FilePath -> Pattern
forall a. IsString a => FilePath -> a
fromString (FilePath -> Pattern) -> FilePath -> Pattern
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentCssDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"*.css"
postSnapshot :: String -> Snapshot
postSnapshot :: ShowS
postSnapshot FilePath
group = FilePath
"published-" FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
group
socialsFile :: SiteConfig -> Identifier
socialsFile :: SiteConfig -> Identifier
socialsFile SiteConfig
cfg = FilePath -> Identifier
fromFilePath (FilePath -> Identifier) -> FilePath -> Identifier
forall a b. (a -> b) -> a -> b
$ SiteConfig -> FilePath
contentDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
"socials.yaml"
siteTemplate, minimalTemplate, pageTemplate, postTemplate :: SiteConfig -> Identifier
siteTemplate :: SiteConfig -> Identifier
siteTemplate SiteConfig
cfg = SiteConfig -> FilePath -> Identifier
resolveTemplate SiteConfig
cfg FilePath
"site.html"
minimalTemplate :: SiteConfig -> Identifier
minimalTemplate SiteConfig
cfg = SiteConfig -> FilePath -> Identifier
resolveTemplate SiteConfig
cfg FilePath
"minimal.html"
pageTemplate :: SiteConfig -> Identifier
pageTemplate SiteConfig
cfg = SiteConfig -> FilePath -> Identifier
resolveTemplate SiteConfig
cfg FilePath
"as-page.html"
postTemplate :: SiteConfig -> Identifier
postTemplate SiteConfig
cfg = SiteConfig -> FilePath -> Identifier
resolveTemplate SiteConfig
cfg FilePath
"as-post.html"
resolveTemplate :: SiteConfig -> FilePath -> Identifier
resolveTemplate :: SiteConfig -> FilePath -> Identifier
resolveTemplate SiteConfig
cfg FilePath
name
| FilePath
name FilePath -> [FilePath] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` SiteConfig -> [FilePath]
contentTemplateNames SiteConfig
cfg = FilePath -> Identifier
fromFilePath (SiteConfig -> FilePath
contentTemplatesDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
name)
| Bool
otherwise = FilePath -> Identifier
fromFilePath (SiteConfig -> FilePath
templatesDir SiteConfig
cfg FilePath -> ShowS
</> FilePath
name)