diff --git a/CCWF/Impl.hs b/CCWF/Impl.hs index 769a226..75fe673 100644 --- a/CCWF/Impl.hs +++ b/CCWF/Impl.hs @@ -6,7 +6,7 @@ import Data.Char import Data.List import Data.Time import Data.Function (on) -import Data.Maybe (isJust) +import Data.Maybe (isJust, fromMaybe) import System.Directory (doesFileExist) import System.FilePath (takeBaseName) import Text.Read @@ -205,15 +205,26 @@ mkMenuCtx self = mconcat -- template (i.e. it may include substitutions), and render it as markdown -- again. Finally, apply the default template to the end result and -- relativize all URLs. +-- Pages may set a different template by setting the @template@ metadata +-- variable. applyMeAsTemplate :: Context String -> Context String -> Compiler (Item String) applyMeAsTemplate pageCtx topCtx = do + template <- getTemplate getResourceBody >>= renderPandoc >>= applyAsTemplate pageCtx >>= renderPandoc - >>= loadAndApplyTemplate "templates/default.html" topCtx + >>= loadAndApplyTemplate template topCtx >>= relativizeUrls +-- | Get the template to use for the current page. +-- If no @template@ metadata is given, @default@ is assumed. +getTemplate :: Compiler Identifier +getTemplate = do + self <- getUnderlying + mtemp <- getMetadataField self "template" + return $ fromFilePath $ "templates/" ++ (fromMaybe "default" mtemp) ++ ".html" + -- | Turn a path @p@ (stripped of prefix and extension) into @p/index.html@. mkPath :: FilePath -> FilePath mkPath "index" = "index.html" diff --git a/README.md b/README.md index da4bfb5..deec65b 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,10 @@ Pages can have the following metadata items: arbitrary (but consistent; i.e. will always be the same). If `menuorder` is either `none` or a negative number, the page will not appear in the main menu at all (but can, of course, still be linked manually). +* `template`. The name of the template to use for this page. + Templates live in the `templates` subdirectory, so if a page wants to use + `mytemplate` as its template, the file `templates/mytemplate.html` will be + loaded. ### Creating a page with a submenu @@ -149,6 +153,26 @@ Pages can have the following metadata items: See the section [creating a page](#create_page); more specifically, the discussion of the `submenu` metadata item. + + +### Creating a page with a custom template + +See the section [creating a page](#create_page); more specifically, the +discussion of the `template` metadata item. +In short: + +1. Create a new template (or copy from `default.html` and modify) in the + `templates` directory. +2. Set the `template` metadata variable to the name of your template, on all + pages that should use the custom template. + + +### Creating a page with very wide content + +Create a page as usual, but set the `template` metadata item for the page +to `wide`. This will apply the `widecontent` CSS class to +the contents of your page. + ### Creating a page with a quickref bar @@ -169,6 +193,66 @@ Anchors are inserted just like how they are inserted for use with a submenu. The file `pages/quickref.md` contains an example usage of the quickref bar. +### Including code listings in pages + +CCWF lets you include code listings with optional syntax highlighting on any +page. To include a one-line code snippet into running text, simply enclose it +in backticks: `` `print "hello"` ``. +These short snippets do not have syntax highlighting. + +To include longer code listings, you can enclose a block of code in triple +backticks, where each set of backticks reside on a new line: + +```` +``` +Beautiful listings +This one has no highlighting +It is a haiku +``` +```` + +To add syntax highlighting to a code block, include the name of the language +the code is written in right next to the opening triple backticks: + +```` +```haskell +fib :: Integer -> Integer +fib 1 = 1 +fib 2 = 1 +fib n = fib (n-1) + fib (n-2) +``` +```` + +If adding syntax highlighting to your code block doesn't change its appearance, +or has some other funny effect on the look of the page or the code block, your +language is most likely not supported. +In which case, simply leaving the language out will at least give you a +fixed-width font and a uniform look across code listings. + + +### Changing the look and feel of the entire website + +To change the global look of your site, you should preferably make changes to +the CSS files in the `css` subdirectory. +The file `css/style.css` governs most of the site's look, such as the fonts, +colors, text decorations, etc. + +For more drastic changes, such as completely changing the page structure or +adding some content to every single page, you will want to modify the default +template `templates/default.html`. +To only change the structure of *some* pages, you are better off creating a +new template, for use only on those pages. See the section +[creating a page with a custom template](#custom_template) for information +on how to do this. + +When modifying either templates or CSS styling, it is **very important** to +test your changes both using a normal-sized browser window, and with your +browser window shrunk to <800 pixels wide (or, even better, on an actual +mobile device). +Otherwise, you risk breaking your website for either mobile or non-mobile +devices. + + Troubleshooting --------------- @@ -185,4 +269,7 @@ Troubleshooting list, it is strongly recommended to use explicit HTML in your markdown pages, since the template compiler and the markdown compiler sometimes disagree on what some particular space or newline means. - See the list of assistants on `pages/about.md` + See the list of assistants on `pages/about.md`. +* If your code listings look weird, try not specifying a language. + You won't get syntax highlighting, but you'll at least get a fixed-width font + and a uniform look without messing up your page. diff --git a/pages/index.md b/pages/index.md index 3ab85ee..0d6e0e3 100644 --- a/pages/index.md +++ b/pages/index.md @@ -1,6 +1,7 @@ --- title: Home menuorder: 0 +template: wide --- Compiler Construction diff --git a/templates/wide.html b/templates/wide.html index 07588c2..8b355f1 100644 --- a/templates/wide.html +++ b/templates/wide.html @@ -5,17 +5,16 @@ - - $title$ | TDA551 $year$ + $title$ | $coursename$ $year$
$body$
Menu