Alternator

al·ter·na·tor: A device that converts mechanical energy to electrical energy.

A CLI tool for building static websites on your Mac. Layouts, includes, and variables in HTML, CSS, and JS. Markdown built-in. Localhost server optional.

Download v2

Getting Started

~/website % alternator --help
USAGE: alternator <source> <target> [--port <port>]

ARGUMENTS:
  <source>                Path to your source directory.
  <target>                Path to your target directory.

OPTIONS:
  -p, --port <port>       Port for the localhost server.
  --version               Show the version.
  -h, --help              Show help information.

The alternator command builds your <source> files into <target>:

~/website % alternator path/to/source path/to/target

Add a --port to make <target> available on localhost:

~/website %  alternator path/to/source path/to/target --port 8080
[watch] watching path/to/source for changes
[serve] serving path/to/target on http://localhost:8080
^c to stop

Pro Tips

Layouts

Specify a layout with the #layout metadata key.

Any file with a #content comment can be used as a layout.

Source path/to/source/index.html

---
#layout: !layout.html
---
<h1>Welcome</h1>
<p>Hello, world!</p>

Layout path/to/source/!layout.html

<!DOCTYPE html>
<html>
  <head>
    <title>Alternator</title>
  </head>
  <body>
    <!-- #content -->
  </body>
</html>

Rendered path/to/target/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Alternator</title>
  </head>
  <body>
    <h1>Welcome</h1>
    <p>Hello, world!</p>
  </body>
</html>

Pro Tips

Includes

Use an #include comment to include another file.

Source path/to/source/index.html

---
#layout: !layout.html
---
<!-- #include !header.html -->
<p>Hello, world!</p>

Include path/to/source/!header.html

<h1>Welcome</h1>

Layout path/to/source/!layout.html

<!DOCTYPE html>
<html>
  <head>
    <title>Alternator</title>
  </head>
  <body>
    <!-- #content -->
  </body>
</html>

Rendered path/to/target/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Alternator</title>
  </head>
  <body>
    <h1>Welcome</h1>
    <p>Hello, world!</p>
  </body>
</html>

Pro Tips

Variables

Define variables with @ symbols and render them in comments.

Assign values in metatdata or as #include arguments.

Source path/to/source/index.html

---
#layout: !layout.html
@siteTitle: Alternator
---
<!-- #include !header.html @pageTitle: Welcome -->
<p>Hello, world!</p>

Include path/to/source/!header.html

<h1><!-- @pageTitle --></h1>

Layout path/to/source/!layout.html

<!DOCTYPE html>
<html>
  <head>
    <title><!-- @siteTitle --></title>
  </head>
  <body>
    <!-- #content -->
  </body>
</html>

Rendered path/to/target/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Alternator</title>
  </head>
  <body>
    <h1>Welcome</h1>
    <p>Hello, world!</p>
  </body>
</html>

Pro Tips