Commit ba0c67b5 authored by Fabien Maniere's avatar Fabien Maniere

translations config and integration - with site.hs!

parent a9a41e35
......@@ -12,19 +12,18 @@ import Hakyll.Contrib.I18n
, translationContext
)
import Data.List (sortBy)
import Data.List.Split (splitOn)
import Data.Ord (comparing)
import Data.Text (pack)
import Data.Time.Clock (getCurrentTime)
import Data.Time.Format (formatTime, defaultTimeLocale)
import Network.URI (parseURI, uriAuthority, uriRegName)
import Debug.Trace (trace)
--------------------------------------------------------------------------------
main :: IO ()
main = hakyllWith config $ do
match "*/translation.yml" $
compile translationCompiler
-- Static files
match ("js/*" .||. "images/*" .||. "favicon/*" .||. "css/fonts/*") $ do
route idRoute
......@@ -34,7 +33,10 @@ main = hakyllWith config $ do
route idRoute
compile compressCssCompiler
-- Pages
-- Translations
match "*/translation.yml" $
compile translationCompiler
-- match (fromList ["about.rst", "contact.markdown"]) $ do
-- route $ setExtension "html"
-- compile $ pandocCompiler
......@@ -64,22 +66,32 @@ main = hakyllWith config $ do
-- >>= loadAndApplyTemplate "templates/default.html" archiveCtx
-- >>= relativizeUrls
match "tiles/**" $ do
-- Content
match "*/tiles/**" $ do
compile pandocCompiler
match "index.html" $ do
-- Pages
match "*/index.html" $ do
route idRoute
compile $ do
defaultTranslation <- loadBody "templates/translation.yml"
makeItem $ Redirect $ translate defaultTranslation "DEFAULT_LANGUAGE"
-- allTiles <- loadAll "*/tiles/**"
-- let tilesList = map (toFilePath . itemIdentifier) allTiles
-- trace ("Tiles items: " ++ show tilesList) $ return ()
lang <- extractLanguage <$> getUnderlying
-- trace ("Extracted language: " ++ lang) $ return ()
discoverPresentation <- loadAll "tiles/discover/presentation/*"
discoverVideos <- loadAll "tiles/discover/videos/*"
discoverPresentation <- loadAll $ fromGlob $ lang ++ "*/tiles/discover/presentation/*"
discoverVideos <- loadAll $ fromGlob $ lang ++ "/tiles/discover/videos/*"
learnFormations <- loadAll $ fromGlob $ lang ++ "/tiles/learn/formations/*"
learnDocumentation <- loadAll $ fromGlob $ lang ++ "/tiles/learn/documentation/*"
learnTools <- loadAll $ fromGlob $ lang ++ "/tiles/learn/tools/*"
learnFormations <- loadAll "tiles/learn/formations/*"
learnDocumentation <- loadAll "tiles/learn/documentation/*"
learnTools <- loadAll "tiles/learn/tools/*"
servers <- loadAll $ fromGlob $ lang ++ "/tiles/connect/*"
let discoverPresentationList = map (toFilePath . itemIdentifier) discoverPresentation
trace ("discoverPresentation items: " ++ show discoverPresentationList) $ return ()
currentYear <- unsafeCompiler getCurrentYear
let indexCtx =
......@@ -89,7 +101,9 @@ main = hakyllWith config $ do
listField "learnFormations" postCtx (return learnFormations) `mappend`
listField "learnDocumentation" postCtx (return learnDocumentation) `mappend`
listField "learnTools" postCtx (return learnTools) `mappend`
listField "servers" postCtx (return servers) `mappend`
constField "year" currentYear `mappend`
translationContext `mappend`
defaultContext
getResourceBody
......@@ -97,7 +111,15 @@ main = hakyllWith config $ do
>>= loadAndApplyTemplate "templates/default.html" indexCtx
>>= relativizeUrls
match "templates/*" $ compile templateBodyCompiler
-- Redirections
create ["index.html"] $ do
route idRoute
compile $ do
defaultTranslation <- loadBody "templates/translation.yml"
makeItem $ Redirect $ translate defaultTranslation "DEFAULT_LANGUAGE"
-- Templates
match "templates/**" $ compile templateBodyCompiler
--------------------------------------------------------------------------------
......@@ -105,6 +127,7 @@ postCtx :: Context String
postCtx =
dateField "date" "%B %e, %Y" `mappend`
domainUrlField `mappend`
translationContext `mappend`
defaultContext
domainUrlField :: Context String
......@@ -120,6 +143,15 @@ getDomainUrl url = case parseURI url >>= uriAuthority of
getCurrentYear :: IO String
getCurrentYear = formatTime defaultTimeLocale "%Y" <$> getCurrentTime
extractLanguage :: Identifier -> String
extractLanguage id =
let path = toFilePath id
segments = splitOn "/" path
langSegment = head $ filter (not . null) segments
in langSegment
config :: Configuration
config = defaultConfiguration
{ previewPort = 7000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment