You are looking at historical revision 27269 of this page. It may differ significantly from its current revision.
A static website compiler
Since there is no native Markdown parser available in Chicken at the moment, you'll also have to have a markdown program available in your PATH to use Markdown in your pages.
Hyde is a program for compiling static websites from a variety of input files. It is basically a Schemey clone of programs such as Webby and, particularly name-wise, Jekyll. Note that there is another project named Hyde which is similar in purpose but written in Python.
Hyde can be run through the hyde executable contained in this egg.
A website is, in Hyde's sense, a directory containing at least a hyde.scm file. This file is evaluated before any command and can be used to set parameters or define helper functions. It should also contain a directory of source files (unless the (source-dir) parameter points somewhere outside the current directory). Invoking the compilation process will recursively traverse (source-dir) and do one of the following things for each file it finds:
- If the file's extension is unknown to Hyde, copy the file to the same relative path within (output-dir) unchanged.
- If the file's extension is known to Hyde, translate its contents, possibly wrap the result in one or more layouts and write it to the same relative path within (output-dir), possibly changing its extension.
In the latter case, the translator used is determined by the source file's extension (see translators for a list of available translators). Before translation, the file is (read), i.e. the first s-expression in the file is read from it. This s-expression must be an alist (or a null list) holding arbitrary page-vars which are made available within the page's as well as the layouts' evaluation environment. This can be used to set a page title, for example. The rest of the file is considered the page's body and is left to be translated by the translator.
Applying css to a website is done by using scss or regular css. Documentation for the syntax used in scss can be found in scss.
Hyde's functionality is probably best understood by an example session. Let's start by initializing a site:
$ mkdir cool-site $ cd cool-site $ hyde init creating layouts creating src creating out creating hyde.scm creating layouts/default.sxml
We now have a basic site structure. The next step would probably be to add some pages, so let's start by creating an index page in wiki (i.e. svnwiki) format:
$ hyde new wiki index src/index.wiki $ cat src/index.wiki ((title . "index"))
As you can see, Hyde created the source file and inserted the file name as a page-var called title, too (actually it's the other way around: the argument for hyde new is the title and Hyde transforms this into a suitable file name, i.e. it removes special chars and substitutes spaces with dashes). This is handy as the default layout uses this to fill the <title> tag in the resulting HTML document:
$ cat layouts/default.sxml () `((xhtml-1.0-strict) (html (head (title ,($ 'title))) (body (h1 ,($ 'title)) (inject ,contents))))
As we learn from that example, page-vars can be referred to through the $ function which is made available by Hyde in the environment which SXML (as well as SCSS and Atom) pages are evaluated in. Also note the inject transformation rule which allows injection of unescaped HTML into the document. Finally, the variable contents contains the translated page contents (see Available Bindings During Page Evaluation).
Let's add a little content to our page and compile the site:
$ echo 'Hey, welcome to my cool site!' >> src/index.wiki $ hyde cleaning output directory preparing compilation compiling pages * index.wiki -> index.html
$ cat out/index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>index</title></head> <body> <h1>index</h1> <p>Hey, welcome to my cool site!</p> </body></html>
As you can see, Hyde renamed index.wiki to index.html. This can be changed through the default-extension parameter or by adding a page-var ext to the page:
$ cat src/index.wiki ((title . "index") (ext . "xml")) Hey, welcome to my cool site!
$ hyde cleaning output directory preparing compilation compiling pages * index.wiki -> index.xml
The hyde executable understands the following options:
- -e HYDE_ENV_NAME
- Sets the hyde environment to execute the command in (see Available Commands for which commands respect this option and define-hyde-environment on how to define environments).
The hyde executable understands the following commands:
- hyde init
- Initializes a site in the current directory.
- hyde new <page-type> [<title> ...]
- Creates a new page with the given page type and title. The page's filename will be inferred from the given title by downcasing it and replacing spaces with dashes.
- hyde serve
- Serves the current site with spiffy, (re-)compiling the requested page on each request (useful for development). This command respects the -e option.
- hyde build [<prefix> ...]
- Builds the current site. If prefixes are given then only paths having those prefixes will be built. This command respects the -e option.
- Compiles the current site. This command respects the -e option.
The following parameters are available to configure Hyde's behavior. They are usually set in a site's hyde.scm.[parameter] (source-dir [dir])
The directory in which source pages are kept. Default: "src"[parameter] (layouts-dir [dir])
The directory in which layouts are kept. Default: "layouts"[parameter] (output-dir [dir])
The directory compilation results will be written to. Default: "out"[parameter] (default-layouts [layouts])
A list of default layouts which are applied when no other is specified. Default: '("default.sxml")[parameter] (clean-before-build [bool])
Indicates whether to purge the output-dir before compilation or not. Default: #t[parameter] (excluded-paths [regexes])
A list of regular expressions matching paths which are to be ignored when compiling. Default: `(,(irregex (seq "~" eos)))[parameter] (default-extension [extension])
The file extension to use for compiled pages which don't explicitly specify an extension. Default: "html"[parameter] (default-page-vars [page-vars])
An alist which maps either (ir)regexps or procedures to page-vars. Each page has its page-source-path matched against the (ir)regexps or is passed to the procedure. If it matches or returns non-#f, the respective page-vars are appended to the page's local page-vars, i.e. local page-vars have precedence over them. Default: '()
The following default-page-vars would set the layouts page-var to ("page.sxml" "default.sxml") for all .sxml pages with the relative path prefix pages/ and the page-vars tags to (awful) for all pages containing the word "cool":
(default-page-vars `(((seq bos "pages/" (+ any) ".sxml" eos) (layouts "page.sxml" "default.sxml")) (,(lambda (page) (irregex-search "cool" (read-page page))) (tags awful))))[parameter] (page-eval-env [env])
The environment for evaluating SXML and SCSS files. Default: (environment-copy (interaction-environment) #t)[parameter] (translators [translators-alist])
An alist of source language translators indexed by file extensions. Default:
`(("sxml" . ,hyde#translate/sxml) ("scss" . ,hyde#translate/scss) ("md" . ,hyde#translate/markdown) ("wiki" . ,hyde#translate/svnwiki) ("sw" . ,hyde#translate/svnwiki))
Additionally, ("atom" . ,hyde-atom#translate/atom) can be made available by loading the hyde-atom extension from the site's hyde.scm.[parameter] (uri-path-prefix [path])
A string that is prepended to all pages' page-path. Default: "".[parameter] (shortcut-links [shortcuts])
An alist of shortcut names (symbols) mapping to URI templates containing format placeholders. These shortcuts can be used with the following page translators:
- The [[link]] syntax is extended to allow shortcuts to be used by prefixing the path with the shortcut name and a colon, for example: [[foo:something]] will use the foo shortcut and substitute the first placeholder with "something".
- The transformation rule shortcut can be used to expand a shortcut name into a URI, for example: (a (@ (href (shortcut foo "something")))).
This feature has been added in version 0.12.[parameter] (ignore-page? [predicate])
predicate is a procedure accepting a page; when it returns #t that page will not be compiled to an output file (it can still be accessed through pages though).
This parameter has been added in version 0.16.
These procedures and macros are mainly intended for use in the hyde.scm or in extension modules.[syntax] (define-hyde-environment name body ...)
Defines an environment name. The body expressions are only evaluated when hyde is executed with -e [name]. This is useful to set different parameters for different scenarios or deployment locations. If no -e option is set, the default environment is used. Just (define-hyde-environment default ...) to override it. See Available Commands for which commands respect environments.[syntax] (make-external-translator name)
Creates a procedure that reads from (current-input-port) and writes to the standard input of the program name linewise. Afterwards, its standard output is read back and written to (current-output-port), also linewise. It can be used to create page translators for external programs, e.g. the markdown translator included in Hyde is defined like this:
(define translate/markdown (make-external-translator (markdown-program))) (translators (cons (list "md" translate/markdown) (translators)))[procedure] (pathify string)
Turn string into a URL friendly path name.
(pathify "This is \"something\" nice.") ; => "this-is-something-nice"
Exported since version 0.16.[constant] sxml-conversion-rules
The set of SXML conversion rules used for translating sxml pages.
Exported since version 0.15.
Available Bindings During Page Evaluation
In pages which are evaluated as Scheme (currently SXML, SCSS and Atom pages), the following bindings are available:[procedure] ($ page-var #!optional page)
Returns the value of page-var (a symbol identifiying the page-var) or #f if no page-var of that name exists. By giving the optional page argument, refer to that page's page-vars instead of the current page's.[parameter] pages
An alist of all available pages indexed by their source file names relative to (source-dir). The values are page records.
This used to be a constant up until version 0.13.[procedure] (current-page)
Returns the current page's record.[procedure] (page-path #!optional (page (current-page)))
Returns the given page's absolute URI path.[procedure] (page-source-path #!optional (page (current-page)))
Returns the given page's source path relative to (source-dir).[procedure] (page-vars #!optional (page (current-page)))
Returns the given page's page-vars as an alist.[procedure] (page-type #!optional (page (current-page)))
Returns the given page's type which is one of the following symbols:
- a page which is handled by one of Hyde's page translators
- a page which is just copied to (output-dir)
- a directory
Returns the given page's contents, possibly wrapped in the given layouts. page may be either a page record or a path relative to (source-dir). This procedure is useful to create aggregate pages. Note that it will translate the contents of dynamic pages even if they have not been compiled, yet. In this case, they will neither be wrapped in page-specific nor the default layouts, only the ones given in layouts.[constant] contents
The translated contents of the current page. Only available in layouts.
- Add hyde build command. Allow link-shortcuts to be procedures. Extract pathify. Use big-chicken module environment when possible. Fix issue in hyde serve with trailing slashes on paths (thanks John J Foerch for the patch). Add ignore-page?. Fix escaping issue in colorize-code (thanks Peter Bex for the patch). Add a link with relation alternate to the atom feed emitted by hyde-atom.
- Add hyde-atom module for convenient generation of atom feeds from pages. Export sxml-conversion-rules
- Some compatibility changes. Depend on Spiffy >= 4.9.
- Update to scss 0.3. Make pages a parameter in page-eval-env.
- Add link-shortcuts.
- Change default-page-vars irregex keys to match against page-source-path instead of page-path. Add environments. Add uri-path-prefix.
- Add colorize support to svnwiki pages. Implement more powerful default-page-vars. Add make-external-translator (thanks to Christian Kellermann for the patch). Only recompile requested pages instead of the whole site with hyde serve.
- Print usage for unknown commands (thanks to Christian Kellermann). Add current-page binding and make it the default argument for all page record field accessors.
- Add svnwiki and atom page translators. Make pages a proper type. Allow creation of aggregate pages through read-page. Drop sxml-shortcuts from sxml-conversion-rules.
- document layout nesting
- change default extension to be an alist mapping source extensions to target extensions
Copyright (c) 2010-2012, Moritz Heidkamp All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.