1 | AE86 [![http://travis-ci.org/cliffano/ae86](https://secure.travis-ci.org/cliffano/ae86.png?branch=master)](http://travis-ci.org/cliffano/ae86)
|
2 | ----
|
3 |
|
4 | AE86 is an old school static website generator written in Node.js .
|
5 |
|
6 | This is handy when you want to create a static website by specifying simple templates, along with custom variables and template functions.
|
7 | All you need to know is standard HTML, JavaScript, CSS, and a bit of simple Jazz templating, nothing fancy.
|
8 |
|
9 | Installation
|
10 | ------------
|
11 |
|
12 | npm install -g ae86
|
13 |
|
14 | Usage
|
15 | -----
|
16 |
|
17 | Create example AE86 project:
|
18 |
|
19 | ae86 init
|
20 |
|
21 | An AE86 project has the following structure:
|
22 |
|
23 | * partials/ - directory containing partial templates
|
24 | * layouts/ - directory containing layout templates
|
25 | * pages/ - directory containing page templates
|
26 | * params.js - file containing custom variables and template functions
|
27 |
|
28 | Generate website (written to out/ directory):
|
29 |
|
30 | ae86 gen
|
31 |
|
32 | Watch for changes and automatically regenerate website:
|
33 |
|
34 | ae86 watch
|
35 |
|
36 | Or, for AE86 historians, use this alias for watch:
|
37 |
|
38 | ae86 drift
|
39 |
|
40 | Remove website:
|
41 |
|
42 | ae86 clean
|
43 |
|
44 | Template & Parameters
|
45 | ---------------------
|
46 |
|
47 | AE86 uses [shinetech/jazz](https://github.com/shinetech/jazz) as its template engine, checkout Jazz documentation for further syntax documentation.
|
48 |
|
49 | __Partials__
|
50 |
|
51 | Partial templates can be used for fragments of the website, e.g. website header, footer, and navigation, which appear on multiple pages. Partial templates can be included in other templates using {include('partial.html')} template function.
|
52 |
|
53 | __Layouts__
|
54 |
|
55 | Layout templates are applied to each page. By default, all pages use layouts/default.html unless otherwise specified in params.js' sitemap. Page content is rendered in layout using {content} variable.
|
56 |
|
57 | __Pages__
|
58 |
|
59 | Each page template will be applied a layout, and evaluated into a static HTML page.
|
60 |
|
61 | __Static__
|
62 |
|
63 | Place all static files (e.g. images, scripts, styles, robots.txt) in static directory. The directory structure of static files will be kept as-is. If there's any conflict with the page templates, the page template will overwrite the static file.
|
64 |
|
65 | __Custom Variables__
|
66 |
|
67 | Website custom variables and template functions can be specified in exports.params object in params.js file:
|
68 |
|
69 | exports.params = {
|
70 | subtitle: 'Small, lightweight, since 1983.',
|
71 | team: ['Keiichi Tsuchiya', 'Mitsu Ide', 'Dori-Kin']
|
72 | }
|
73 |
|
74 | These parameters can then be used in a template file:
|
75 |
|
76 | <h2>{subtitle}</h2>
|
77 | <ul>
|
78 | {foreach person in team}
|
79 | <li>{person}</li>
|
80 | {end}
|
81 | </ul>
|
82 |
|
83 | You also need to specify the sitemap in params.js file. The key should match the page file names under the pages directory, title and layout can optionally be specified as the value. Layout value must be relative to layouts directory, e.g. layout: brochure.html uses layouts/brochure.html . If layout is not specified, then layouts/default.html will be used.
|
84 |
|
85 | exports.params = {
|
86 | sitemap: {
|
87 | 'index.html': { title: 'Home Page' },
|
88 | 'products/corolla.html': { title: 'Toyota Corolla', layout: 'brochure.html' },
|
89 | 'products/sprinter.html': { title: 'Toyota Sprinter', layout: 'brochure.html' },
|
90 | 'contact.html': { title: 'Contact Us' }
|
91 | }
|
92 | }
|
93 |
|
94 | Note that params.js is a Node.js module, so it can require other modules accordingly.
|
95 |
|
96 | __Custom Template Functions__
|
97 |
|
98 | Custom template functions can be specified in params.js :
|
99 |
|
100 | exports.params = {
|
101 | copyright: function (year, name, cb) {
|
102 | cb('Copyright © ' + year + ' ' + name + '. Some Rights Reserved.');
|
103 | }
|
104 | }
|
105 |
|
106 | Note that a custom template function must have a callback(result) as the last argument, result will then be rendered on the template.
|
107 |
|
108 | The custom copyright template function above can then be used in a template file:
|
109 |
|
110 | <div id="footer">
|
111 | {copyright('2011', 'Toyota Motor Corporation')}
|
112 | <div>
|
113 |
|
114 | __Built-in Variables & Template Functions__
|
115 |
|
116 | AE86 comes with a number of built-in variables and template functions:
|
117 |
|
118 | * include(file)
|
119 | * title()
|
120 | * date(format)
|
121 | * relative(path)
|
122 | * __genId
|
123 |
|
124 | __include(file)__
|
125 |
|
126 | This template function includes a partial template within another template. The file argument is relative to partials directory. E.g. include('header.html') includes partials/header.html file.
|
127 |
|
128 | <div id="header">
|
129 | {include('header.html')}
|
130 | </div>
|
131 |
|
132 | A partial template can also be included in another partial template.
|
133 |
|
134 | __title()__
|
135 |
|
136 | This template function displays the current page's title as configured in sitemap param in params.js file.
|
137 |
|
138 | <title>{title()}</title>
|
139 |
|
140 | __date(format)__
|
141 |
|
142 | This template function displays the current time with a specified format. Check out [felixge/node-dateformat](https://github.com/felixge/node-dateformat) README page for date format examples.
|
143 |
|
144 | <div class="date">{date('dddd dd/mm/yyyy hh:MM:ssTT')}</div>
|
145 |
|
146 | __relative(path)__
|
147 |
|
148 | This template function renders a path relative to the location of the page template.
|
149 |
|
150 | <script type="text/javascript" src="{relative('scripts/global.js')}"></script>
|
151 |
|
152 | Which will be rendered as ../scripts/global.js from templates under the subdirectories of pages directory, but it will be rendered as scripts/global.js from templates right under the pages directory.
|
153 |
|
154 | <strong>__genId</strong>
|
155 |
|
156 | This variable is an ID unique for each website generation (currently a timestamp). It's handy when you want to force the client browser to request a resource that should only be cached once for each version of the generated website, e.g. JavaScript, CSS, or image files.
|
157 |
|
158 | <script type="text/javascript" src="{relative('scripts/global.js')}?{__genId}"></script>
|