6 HTML snippets
(require "snippets-html.rkt") |
Each “snippet” module provides all (well most of) the document- and article-level blocks of structural markup necessary for a particular target output format; this one is for HTML. The idea is that any block of markup that might be reused across more than one template should be a function.
The functions in the snippets modules follow two conventions in this project:
Functions that return strings of HTML have the prefix html$-.
Such functions do not do any parsing or destructuring of complex objects; every separate piece that will be inserted into the template is passed in as a separate argument. This makes it harder to change the scope of what a snippet does, but makes things faster since all the parsing can happen in one place, before the snippet functions are called.
6.1 Using pollen/mode
It’s worth looking at the source for this file to see how pollen/mode can be used to make it easy to write “mini-template” functions:
#lang pollen/mode racket/base (define (html$-my-article title body-tx) ◊string-append{ <p><b>◊|title|</b><p> ◊(->html body-tx) })
6.2 HTML Snippet functions
procedure
(html$-page-head [title close-head?]) → non-empty-string?
title : (or/c string? #f) = #f close-head? : boolean? = #t
If title is a string it will be used inside the <title> tag.
If you want to include additional stuff inside the <head>, you can set close-head? to #f to prevent it from including the closing </head> tag (you’ll have to add it yourself).
procedure
(html$-page-body-open [body-class]) → non-empty-string?
body-class : string? = ""
If body-class is a non-empty string, its contents will be included in the class attribute of the <body> tag.
procedure
procedure
(html$-article-open pagenode title-specified-in-doc? title pubdate) → non-empty-string? pagenode : pagenode? title-specified-in-doc? : boolean? title : txexpr? pubdate : string?
The title-specified-in-doc? form changes the HTML markup structure used.
procedure
(html$-article-close footertext) → non-empty-string?
footertext : string?
procedure
(html$-article-listing-short pagenode pubdate title) → non-empty-string? pagenode : pagenode? pubdate : string? title : string?
procedure
procedure
procedure
(html$-note-contents disposition-mark elems) → non-empty-string? disposition-mark : string? elems : (listof xexpr?)
procedure
(html$-note-listing-full pagenode note-id title-html-flow date contents [ author author-url]) → non-empty-string? pagenode : pagenode? note-id : string? title-html-flow : string? date : string? contents : string? author : string? = (default-authorname) author-url : string? = ""
procedure
(html$-note-in-article id date contents author author-url) → non-empty-string? id : string? date : string? contents : string? author : string? author-url : string?
procedure
(html$-notes-section note-htmls) → non-empty-string?
note-htmls : string?
procedure
(html$-paginate-navlinks current-page pagecount basename) → string? current-page : exact-positive-integer? pagecount : exact-positive-integer? basename : string?
The links are enclosed within <li> tags. It’s up to the calling site to provide the enclosing <ul> tag (in case any custom styling or IDs need to be applied).