by Dave Herman <dherman at ccs dot neu dot edu>
This library provides a simple abstraction for building static web content that can be rapidly developed and tested, and then exported to raw HTML.
|(require (planet dherman/static-page:1:0))|
This package is intended to ease the development of web sites that contain only static pages. This is useful for generating sites with multiple pages that share common structure. In this case, while the full power of dynamic servlets may not be necessary, the benefits of building templates and abstractions are still important.
Moreover, PLT Scheme and the PLT Web Server are fantastic for rapidly developing and debugging a web site – X-expressions, quasiquote and unquote, and of course data and functional abstraction are all simple and powerful tools for building web pages. Even better, with serve/servlet it’s easy to test a web site from within DrScheme with a push of the Run button.
This library provides the last piece: converting that dynamically generated servlet into a static collection of HTML files.
Consider a simple example of a static web site with three pages:
|`(html (head (title "My Web Site"))|
|(body (p "Check out my "|
|(a ([href ,(embed-url cv)]) "CV.")))))))|
|`(html (head (title "My CV"))|
|(body (p (a ([href ,(embed-url index)]) "Dave Herman"))|
|,@(for/list ([job job-history])|
|(define (job->xexpr job) ...)|
Notice how the pages are created with instead of as explicit functions from request? to response/c. Pages built with can behave like procedures that call send/suspend/dispatch, so we can actually treat this web site as a servlet and test it in DrScheme:
But we can extract the HTML source of the site and save it to disk as well:
|(define my-site ( index))|
|( my-site #:root (build-path 'same "saved"))|
|( path build-response) →|
|path : string?|
|build-response : (( -> string?) -> (or/c response/full? xexpr?))|
Constructs a static page structure. The path is the address by which other pages in the site can link to this page. The build-response procedure generates a response, similar to regular servlets. Note, however, that incremental responses are unsupported. The argument to build-response is a procedure that produces the address of static pages in the site.
|( x) → boolean?|
|x : any|
Determines whether x is a static page.
|( page) → string?|
Returns the local address of page.
|( front-page) →|
Builds all pages in a site, recursively following all local links and adding the generated pages to the site.
|( x) → boolean?|
|x : any|
Determines whether x is a site.
|root : path-string? = (current-directory)|
Saves all the pages in site to the filesystem, based in the root directory. The optional exists-flag determines the behavior of call-with-output-file* in case any of the files already exist.