source: project/wiki/eggref/4/hyde @ 29397

Last change on this file since 29397 was 29397, checked in by Moritz Heidkamp, 7 years ago

hyde: Fix markup of Lowdown link

File size: 16.6 KB
Line 
1[[tags: egg]]
2
3== Hyde
4
5[[toc:]]
6
7=== Description
8
9A static website compiler
10
11=== Author
12
13[[/users/moritz-heidkamp|Moritz Heidkamp]]
14
15=== Requirements
16
17
18Requires the [[environments]], [[sxml-transforms]], [[matchable]],
19[[scss]], [[filepath]], [[spiffy]], [[doctype]], [[colorize]], [[multidoc]],
20[[defstruct]], [[atom]] and [[rfc3339]] extensions.
21
22Although there is a native
23[[http://daringfireball.net/projects/markdown/|Markdown]] parser for
24Chicken these days (called [[/egg/lowdown|Lowdown]]) due to historical
25reasons you'll have to have a {{markdown}} program available in your
26{{PATH}} to use Markdown in your Hyde pages for the time
27being. Alternatively you can define a custom page translator using
28Lowdown (see [[#translators|translators]]).
29
30=== Documentation
31
32Hyde is a program for compiling static websites from a variety of
33input files. It is basically a Schemey clone of programs such as
34[[http://webby.rubyforge.org/|Webby]] and, particularly name-wise,
35[[http://jekyllrb.com/|Jekyll]]. Note that there is
36[[http://ringce.com/hyde|another project named Hyde]] which is similar
37in purpose but written in Python.
38
39Hyde can be run through the {{hyde}} executable contained in this egg.
40
41A website is, in Hyde's sense, a directory containing at least a
42{{hyde.scm}} file. This file is evaluated before any command and can
43be used to set parameters or define helper functions. It should also
44contain a directory of source files (unless the {{(source-dir)}}
45parameter points somewhere outside the current directory). Invoking
46the compilation process will recursively traverse {{(source-dir)}} and
47do one of the following things for each file it finds:
48
49* If the file's extension is unknown to Hyde, copy the file to the
50same relative path within {{(output-dir)}} unchanged.
51
52* If the file's extension is known to Hyde, translate its contents,
53possibly wrap the result in one or more layouts and write it to the
54same relative path within {{(output-dir)}}, possibly changing its
55extension.
56
57
58In the latter case, the translator used is determined by the source
59file's extension (see [[#translators|translators]] for a list of
60available translators). Before translation, the file is {{(read)}},
61i.e. the first s-expression in the file is read from it. This
62s-expression must be an alist (or a null list) holding arbitrary
63page-vars which are made available within the page's as well as the
64layouts' evaluation environment. This can be used to set a page title,
65for example. The rest of the file is considered the page's body and is
66left to be translated by the translator.
67
68Applying css to a website is done by using scss or regular css. Documentation for the syntax used in scss can be found in [[scss]].
69
70=== Example
71
72Hyde's functionality is probably best understood by an example
73session. Let's start by initializing a site:
74
75    $ mkdir cool-site
76    $ cd cool-site
77    $ hyde init
78    creating layouts
79    creating src
80    creating out
81    creating hyde.scm
82    creating layouts/default.sxml
83   
84We now have a basic site structure. The next step would probably be to
85add some pages, so let's start by creating an index page in wiki
86(i.e. svnwiki) format:
87
88    $ hyde new wiki index
89    src/index.wiki
90    $ cat src/index.wiki
91    ((title . "index"))
92   
93As you can see, Hyde created the source file and inserted the file
94name as a page-var called {{title}}, too (actually it's the other way
95around: the argument for {{hyde new}} is the title and Hyde transforms
96this into a suitable file name, i.e. it removes special chars and
97substitutes spaces with dashes). This is handy as the default layout
98uses this to fill the {{<title>}} tag in the resulting HTML document:
99
100    $ cat layouts/default.sxml
101    ()
102    `((xhtml-1.0-strict)
103      (html
104       (head
105        (title ,($ 'title)))
106       (body
107        (h1 ,($ 'title))
108        (inject ,contents))))
109
110As we learn from that example, page-vars can be referred to through
111the {{$}} function which is made available by Hyde in the environment
112which SXML (as well as SCSS and Atom) pages are evaluated in. Also
113note the {{inject}} transformation rule which allows injection of
114unescaped HTML into the document. Finally, the variable {{contents}}
115contains the translated page contents (see
116[[#available-bindings-during-page-evaluation|Available Bindings During
117Page Evaluation]]).
118
119Let's add a little content to our page and compile the site:
120
121    $ echo 'Hey, welcome to my cool site!' >> src/index.wiki
122    $ hyde
123    cleaning output directory
124    preparing compilation
125    compiling pages
126    * index.wiki -> index.html
127
128    $ cat out/index.html
129    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
130    <html>
131    <head>
132    <title>index</title></head>
133    <body>
134    <h1>index</h1>
135    <p>Hey, welcome to my cool site!</p>
136    </body></html>
137
138As you can see, Hyde renamed {{index.wiki}} to {{index.html}}. This
139can be changed through the {{default-extension}} parameter or by
140adding a page-var {{ext}} to the page:
141
142    $ cat src/index.wiki
143    ((title . "index")
144     (ext   . "xml"))
145    Hey, welcome to my cool site!
146
147    $ hyde           
148    cleaning output directory
149    preparing compilation
150    compiling pages
151    * index.wiki -> index.xml
152
153=== Available Options
154
155The {{hyde}} executable understands the following options:
156
157; {{-e HYDE_ENV_NAME}} : Sets the hyde environment to execute the command in (see [[#available-commands|Available Commands]] for which commands respect this option and [[#define-hyde-environment|define-hyde-environment]] on how to define environments).
158
159
160=== Available Commands
161
162The {{hyde}} executable understands the following commands:
163
164; {{hyde init}} : Initializes a site in the current directory.
165; {{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.
166; {{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.
167; {{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.
168; {{hyde}} : Compiles the current site. This command respects the {{-e}} option.
169
170=== Configuration Parameters
171
172The following parameters are available to configure Hyde's
173behavior. They are usually set in a site's {{hyde.scm}}.
174
175
176<parameter>(source-dir [dir])</parameter>
177
178The directory in which source pages are kept. Default: {{"src"}}
179
180
181<parameter>(layouts-dir [dir])</parameter>
182
183The directory in which layouts are kept. Default: {{"layouts"}}
184
185
186<parameter>(output-dir [dir])</parameter>
187
188The directory compilation results will be written to. Default:
189{{"out"}}
190
191
192<parameter>(default-layouts [layouts])</parameter>
193
194A list of default layouts which are applied when no other is
195specified. Default: {{'("default.sxml")}}
196
197
198<parameter>(clean-before-build [bool])</parameter>
199
200Indicates whether to purge the {{output-dir}} before compilation or
201not. Default: {{#t}}
202
203
204<parameter>(excluded-paths [regexes])</parameter>
205
206A list of regular expressions matching paths which are to be ignored
207when compiling. Default: {{`(,(irregex (seq "~" eos)))}}
208
209
210<parameter>(default-extension [extension])</parameter>
211
212The file extension to use for compiled pages which don't explicitly
213specify an extension. Default: {{"html"}}
214
215
216<parameter>(default-page-vars [page-vars])</parameter>
217
218An alist which maps either (ir)regexps or procedures to
219page-vars. Each page has its {{page-source-path}} matched against the
220(ir)regexps or is passed to the procedure. If it matches or returns
221non-{{#f}}, the respective page-vars are appended to the page's local
222page-vars, i.e. local page-vars have precedence over them.  Default: {{'()}}
223
224Example:
225
226The following {{default-page-vars}} would set the {{layouts}} page-var
227to {{("page.sxml" "default.sxml")}} for all {{.sxml}} pages with the
228relative path prefix {{pages/}} and the page-vars {{tags}} to
229{{(awful)}} for all pages containing the word "cool":
230
231<enscript language="scheme">
232(default-page-vars `(((seq bos "pages/" (+ any) ".sxml" eos)
233                      (layouts "page.sxml" "default.sxml"))
234
235                     (,(lambda (page)
236                        (irregex-search "cool" (read-page page)))
237                      (tags awful))))
238</enscript>
239
240
241<parameter>(page-eval-env [env])</parameter>
242
243The environment for evaluating SXML and SCSS files. Default:
244{{(environment-copy (interaction-environment) #t)}}
245
246
247<parameter>(translators [translators-alist])</parameter>
248
249An alist of source language translators indexed by file extensions. Default:
250
251    `(("sxml" . ,hyde#translate/sxml)
252      ("scss" . ,hyde#translate/scss)
253      ("md"   . ,hyde#translate/markdown)
254      ("wiki" . ,hyde#translate/svnwiki)
255      ("sw"   . ,hyde#translate/svnwiki))
256
257Additionally, {{("atom" . ,hyde-atom#translate/atom)}} can be made
258available by loading the {{hyde-atom}} extension from the site's
259{{hyde.scm}}.
260
261
262<parameter>(uri-path-prefix [path])</parameter>
263
264A string that is prepended to all pages' {{page-path}}. Default: {{""}}.
265
266
267<parameter>(shortcut-links [shortcuts])</parameter>
268
269An alist of shortcut names (symbols) mapping to URI templates
270containing {{format}} placeholders. These shortcuts can be used with the
271following page translators:
272
273; svnwiki : 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"}}.
274; sxml : The transformation rule {{shortcut}} can be used to expand a shortcut name into a URI, for example: {{(a (@ (href (shortcut foo "something"))))}}.
275
276This feature has been added in version 0.12.
277
278
279<parameter>(ignore-page? [predicate])</parameter>
280
281{{predicate}} is a procedure accepting a page; when it returns {{#t}}
282that page will not be compiled to an output file (it can still be
283accessed through {{pages}} though).
284
285This parameter has been added in version 0.16.
286
287
288=== Helpers
289
290These procedures and macros are mainly intended for use in the
291{{hyde.scm}} or in extension modules.
292
293
294<syntax>(define-hyde-environment name body ...)</syntax>
295
296Defines an environment {{name}}. The {{body}} expressions are only
297evaluated when {{hyde}} is executed with {{-e [name]}}. This is useful
298to set different parameters for different scenarios or deployment
299locations. If no {{-e}} option is set, the {{default}} environment is
300used. Just {{(define-hyde-environment default ...)}} to override
301it. See [[#available-commands|Available Commands]] for which commands
302respect environments.
303
304
305<syntax>(make-external-translator name)</syntax>
306
307Creates a procedure that reads from {{(current-input-port)}} and
308writes to the standard input of the program {{name}}
309linewise. Afterwards, its standard output is read back and written to
310{{(current-output-port)}}, also linewise. It can be used to create
311page translators for external programs, e.g. the markdown translator
312included in Hyde is defined like this:
313
314<enscript language="scheme">
315(define translate/markdown (make-external-translator (markdown-program)))
316(translators (cons (list "md" translate/markdown) (translators)))
317</enscript>
318
319
320<procedure>(pathify string)</procedure>
321
322Turn {{string}} into a URL friendly path name.
323
324Example:
325
326<enscript language="scheme">
327(pathify "This is \"something\" nice.") ; => "this-is-something-nice"
328</enscript>
329
330Exported since version 0.16.
331
332
333<constant>sxml-conversion-rules</constant>
334
335The set of SXML conversion rules used for translating {{sxml}} pages.
336
337Exported since version 0.15.
338
339
340=== Available Bindings During Page Evaluation
341
342In pages which are evaluated as Scheme (currently SXML, SCSS and Atom
343pages), the following bindings are available:
344
345
346<procedure>($ page-var #!optional page)</procedure>
347
348Returns the value of {{page-var}} (a symbol identifiying the page-var)
349or {{#f}} if no {{page-var}} of that name exists. By giving the
350optional {{page}} argument, refer to that page's page-vars instead of
351the current page's.
352
353
354<parameter>pages</parameter>
355
356An alist of all available pages indexed by their source file names
357relative to {{(source-dir)}}. The values are {{page}} records.
358
359This used to be a constant up until version 0.13.
360
361
362<procedure>(current-page)</procedure>
363
364Returns the current page's record.
365
366
367<procedure>(page-path #!optional (page (current-page)))</procedure>
368
369Returns the given {{page}}'s absolute URI path.
370
371
372<procedure>(page-source-path #!optional (page (current-page)))</procedure>
373
374Returns the given {{page}}'s source path relative to {{(source-dir)}}.
375
376
377<procedure>(page-vars #!optional (page (current-page)))</procedure>
378
379Returns the given {{page}}'s page-vars as an alist.
380
381
382<procedure>(page-type #!optional (page (current-page)))</procedure>
383
384Returns the given {{page}}'s type which is one of the following symbols:
385
386; dynamic : a page which is handled by one of Hyde's page translators
387; static : a page which is just copied to {{(output-dir)}}
388; directory : a directory
389
390
391<procedure>(read-page page #!rest layouts)</procedure>
392
393Returns the given {{page}}'s contents, possibly wrapped in the given
394{{layouts}}. {{page}} may be either a {{page}} record or a path
395relative to {{(source-dir)}}. This procedure is useful to create
396aggregate pages. Note that it will translate the contents of dynamic
397{{page}}s even if they have not been compiled, yet. In this case, they
398will neither be wrapped in page-specific nor the default layouts, only
399the ones given in {{layouts}}.
400
401
402<constant>contents</constant>
403
404The translated contents of the current page. Only available in layouts.
405
406=== Change Log
407
408; 0.16 : 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}}.
409; 0.15 : Add {{hyde-atom}} module for convenient generation of atom feeds from pages. Export {{sxml-conversion-rules}}
410; 0.14 : Some compatibility changes. Depend on Spiffy >= 4.9.
411; 0.13 : Update to scss 0.3. Make {{pages}} a parameter in {{page-eval-env}}.
412; 0.12 : Add {{link-shortcuts}}.
413; 0.11 : Change {{default-page-vars}} irregex keys to match against {{page-source-path}} instead of {{page-path}}. Add environments. Add {{uri-path-prefix}}.
414; 0.10 : 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}}.
415; 0.9 : 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.
416; 0.8 : 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}}.
417
418
419=== To Do
420
421* document layout nesting
422* change default extension to be an alist mapping source extensions to
423  target extensions
424
425=== License
426
427  Copyright (c) 2010-2012, Moritz Heidkamp
428  All rights reserved.
429 
430  Redistribution and use in source and binary forms, with or without
431  modification, are permitted provided that the following conditions are
432  met:
433 
434  Redistributions of source code must retain the above copyright
435  notice, this list of conditions and the following disclaimer.
436 
437  Redistributions in binary form must reproduce the above copyright
438  notice, this list of conditions and the following disclaimer in the
439  documentation and/or other materials provided with the distribution.
440 
441  Neither the name of the author nor the names of its contributors may
442  be used to endorse or promote products derived from this software
443  without specific prior written permission.
444 
445  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
446  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
447  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
448  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
449  COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
450  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
451  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
452  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
453  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
454  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
455  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
456  OF THE POSSIBILITY OF SUCH DAMAGE.
Note: See TracBrowser for help on using the repository browser.