From c97af1ad6e4f3f2a83bd0e882f6f43c12153766c Mon Sep 17 00:00:00 2001 From: Alex Gerdes Date: Sat, 18 Mar 2017 12:48:21 +0100 Subject: [PATCH] Added substitutions to CCWF --- CCWF.hs | 2 +- CCWF/Config.hs | 4 ++++ CCWF/Impl.hs | 9 ++++++--- website.hs | 7 ++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CCWF.hs b/CCWF.hs index 29f5d0b..28442bb 100644 --- a/CCWF.hs +++ b/CCWF.hs @@ -1,7 +1,7 @@ -- | Chalmers course module CCWF ( -- * Configuring and updating pages - Website (..), Info (..), Materials (..) + Website (..), Info (..), Materials (..), Subst(..) , URL, Teacher (..), Lecture (..) -- * Building the website diff --git a/CCWF/Config.hs b/CCWF/Config.hs index cb25618..e16bb61 100644 --- a/CCWF/Config.hs +++ b/CCWF/Config.hs @@ -8,6 +8,7 @@ type URL = String data Website = Website { courseInfo :: Info , courseMaterials :: Materials + , courseSubst :: Subst } -- | Lectures, files and news items: course materials that will likely be @@ -82,6 +83,9 @@ data Info = Info , labDeadlines :: [String] } +-- | Substitutions allow you to write abbreviations for phrases you often use. +data Subst = Subst [(String, String)] + -- | Bio for the teacher responsible for the course. -- Name, phone and email are mandatory. data Teacher = Teacher diff --git a/CCWF/Impl.hs b/CCWF/Impl.hs index 75fe673..c2b2a31 100644 --- a/CCWF/Impl.hs +++ b/CCWF/Impl.hs @@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings, RecordWildCards, TupleSections #-} module CCWF.Impl where + import Hakyll import Control.Monad import Data.Char @@ -14,7 +15,7 @@ import CCWF.Config -- | Build a website from a configuration. mkWebsite :: Website -> IO () -mkWebsite (Website (Info{..}) (Materials{..})) = do +mkWebsite (Website (Info{..}) (Materials{..}) (Subst subst)) = do -- Check that all lecture files are present let files = [ "./files/" ++ file | fs <- map lectureFiles lectures @@ -76,7 +77,7 @@ mkWebsite (Website (Info{..}) (Materials{..})) = do -- Context for the page content; contains metadata set in the -- markdown file for each page, as well as some info set at the -- top of this file. - ctx = mconcat + ctx = mconcat $ [ constField "year" (show courseYear) , constField "coursename" courseName , constField "coursecode" courseCode @@ -105,7 +106,9 @@ mkWebsite (Website (Info{..}) (Materials{..})) = do else mempty , listField "latestnews" defaultContext (pure $ take 3 newsItemItems) , defaultContext - ] + ] ++ + -- Substitution context + [ constField k v | (k, v) <- subst] applyMeAsTemplate ctx ctx where newsItemItems = map (Item (fromFilePath "")) newsItems diff --git a/website.hs b/website.hs index 2ae09e3..02cbf08 100644 --- a/website.hs +++ b/website.hs @@ -125,4 +125,9 @@ info = Info ] } -main = mkWebsite (Website info materials) +subst = Subst + [ ("javalette", "[Javalette](/project#javalette)") + , ("timeedit" , "[TimeEdit](/schedule))") + ] + +main = mkWebsite (Website info materials subst)