feat: localize personalization
This puts all of the hakyll personalization configuration in a single place near the top of `ssg/src/Main.hs`
This commit is contained in:
parent
f4783a39c8
commit
489b648b4d
1 changed files with 37 additions and 25 deletions
|
@ -19,17 +19,33 @@ import Text.Pandoc
|
||||||
)
|
)
|
||||||
import Text.Pandoc.Highlighting (Style, breezeDark, styleToCss)
|
import Text.Pandoc.Highlighting (Style, breezeDark, styleToCss)
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- PERSONALIZATION
|
||||||
|
|
||||||
|
mySiteName :: String
|
||||||
|
mySiteName = "My Site Name"
|
||||||
|
|
||||||
|
mySiteRoot :: String
|
||||||
|
mySiteRoot = "https://my-site.com"
|
||||||
|
|
||||||
|
myFeedTitle :: String
|
||||||
|
myFeedTitle = "My Site"
|
||||||
|
|
||||||
|
myFeedDescription :: String
|
||||||
|
myFeedDescription = "My Site Description"
|
||||||
|
|
||||||
|
myFeedAuthorName :: String
|
||||||
|
myFeedAuthorName = "My Name"
|
||||||
|
|
||||||
|
myFeedAuthorEmail :: String
|
||||||
|
myFeedAuthorEmail = "me@myemail.com"
|
||||||
|
|
||||||
|
myFeedRoot :: String
|
||||||
|
myFeedRoot = mySiteRoot
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- CONFIG
|
-- CONFIG
|
||||||
|
|
||||||
root :: String
|
|
||||||
root =
|
|
||||||
"https://my-site.com"
|
|
||||||
|
|
||||||
siteName :: String
|
|
||||||
siteName =
|
|
||||||
"My Site Name"
|
|
||||||
|
|
||||||
-- Default configuration: https://github.com/jaspervdj/hakyll/blob/cd74877d41f41c4fba27768f84255e797748a31a/lib/Hakyll/Core/Configuration.hs#L101-L125
|
-- Default configuration: https://github.com/jaspervdj/hakyll/blob/cd74877d41f41c4fba27768f84255e797748a31a/lib/Hakyll/Core/Configuration.hs#L101-L125
|
||||||
config :: Configuration
|
config :: Configuration
|
||||||
config =
|
config =
|
||||||
|
@ -91,8 +107,8 @@ main = hakyllWith config $ do
|
||||||
|
|
||||||
let indexCtx =
|
let indexCtx =
|
||||||
listField "posts" postCtx (return posts)
|
listField "posts" postCtx (return posts)
|
||||||
<> constField "root" root
|
<> constField "root" mySiteRoot
|
||||||
<> constField "siteName" siteName
|
<> constField "siteName" mySiteName
|
||||||
<> defaultContext
|
<> defaultContext
|
||||||
|
|
||||||
getResourceBody
|
getResourceBody
|
||||||
|
@ -109,8 +125,8 @@ main = hakyllWith config $ do
|
||||||
|
|
||||||
let pages = posts
|
let pages = posts
|
||||||
sitemapCtx =
|
sitemapCtx =
|
||||||
constField "root" root
|
constField "root" mySiteRoot
|
||||||
<> constField "siteName" siteName
|
<> constField "siteName" mySiteName
|
||||||
<> listField "pages" postCtx (return pages)
|
<> listField "pages" postCtx (return pages)
|
||||||
|
|
||||||
makeItem ("" :: String)
|
makeItem ("" :: String)
|
||||||
|
@ -128,7 +144,6 @@ main = hakyllWith config $ do
|
||||||
route idRoute
|
route idRoute
|
||||||
compile (makeStyle pandocHighlightStyle)
|
compile (makeStyle pandocHighlightStyle)
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- COMPILER HELPERS
|
-- COMPILER HELPERS
|
||||||
|
|
||||||
|
@ -147,8 +162,8 @@ feedCtx =
|
||||||
|
|
||||||
postCtx :: Context String
|
postCtx :: Context String
|
||||||
postCtx =
|
postCtx =
|
||||||
constField "root" root
|
constField "root" mySiteRoot
|
||||||
<> constField "siteName" siteName
|
<> constField "siteName" mySiteName
|
||||||
<> dateField "date" "%Y-%m-%d"
|
<> dateField "date" "%Y-%m-%d"
|
||||||
<> defaultContext
|
<> defaultContext
|
||||||
|
|
||||||
|
@ -210,6 +225,7 @@ pandocHighlightStyle :: Style
|
||||||
pandocHighlightStyle =
|
pandocHighlightStyle =
|
||||||
breezeDark -- https://hackage.haskell.org/package/pandoc/docs/Text-Pandoc-Highlighting.html
|
breezeDark -- https://hackage.haskell.org/package/pandoc/docs/Text-Pandoc-Highlighting.html
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
-- FEEDS
|
-- FEEDS
|
||||||
|
|
||||||
type FeedRenderer =
|
type FeedRenderer =
|
||||||
|
@ -227,23 +243,19 @@ feedCompiler renderer =
|
||||||
feedConfiguration :: FeedConfiguration
|
feedConfiguration :: FeedConfiguration
|
||||||
feedConfiguration =
|
feedConfiguration =
|
||||||
FeedConfiguration
|
FeedConfiguration
|
||||||
{ feedTitle = "My Site"
|
{ feedTitle = myFeedTitle
|
||||||
, feedDescription = "My Site Description"
|
, feedDescription = myFeedDescription
|
||||||
, feedAuthorName = "My Name"
|
, feedAuthorName = myFeedAuthorName
|
||||||
, feedAuthorEmail = "me@myemail.com"
|
, feedAuthorEmail = myFeedAuthorEmail
|
||||||
, feedRoot = root
|
, feedRoot = myFeedRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- CUSTOM ROUTE
|
-- CUSTOM ROUTE
|
||||||
|
|
||||||
getTitleFromMeta :: Metadata -> String
|
|
||||||
getTitleFromMeta =
|
|
||||||
fromMaybe "no title" . lookupString "title"
|
|
||||||
|
|
||||||
fileNameFromTitle :: Metadata -> FilePath
|
fileNameFromTitle :: Metadata -> FilePath
|
||||||
fileNameFromTitle =
|
fileNameFromTitle =
|
||||||
T.unpack . (`T.append` ".html") . Slugger.toSlug . T.pack . getTitleFromMeta
|
T.unpack . (`T.append` ".html") . Slugger.toSlug . T.pack . safeTitle
|
||||||
|
|
||||||
titleRoute :: Metadata -> Routes
|
titleRoute :: Metadata -> Routes
|
||||||
titleRoute =
|
titleRoute =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue