1.0.0 • Published 3 years ago

@lukecjohnson/ssg v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
3 years ago

@lukecjohnson/ssg

A static site generator that does just enough.

Installation

$ npm install @lukecjohnson/ssg --save-dev

Directory structure

2 core directories are required:

  • posts: Should contain Markdown files for all of a site's content
  • templates: Should contain Nunjucks templates for all of a site's pages

The only required template is _post.njk, which is used to generate pages for each post.

Templating

Nunjucks is used for templating ― refer to Nunjucks' templating documentation for detailed usage instructions.

Every template's context includes posts, an array containing each post with any data provided in a post's front matter and the following default properties:

  • content: The rendered HTML body of the post
  • url: The url path for the post
  • date: The date the post was created or the custom date provided in the post's front matter
<h1>Blog</h1>
<ul>
  {% for post in posts %}
    <li><a href="{{ post.url }}">{{ post.title }}</a></li>
  {% endfor %}
</ul>

Additionally, _post.njk has direct access to the properties of an individual post:

<header>
  <h1>{{ title }}</h1>
  <time>{{ date | format('MMMM d, yyyy') }}</time>
</header>
<main>
  {{ content | safe }}
</main>

CLI

To build a site, use the base ssg command. See --help for all available options:

Usage: ssg [options]

Options:

  --output              Path to output directory (Default: ./public)

  --templates           Path to templates directory (Default: ./templates)

  --posts               Path to posts directory (Default: ./posts)

  --posts-base-url      Base URL for posts (Default: /posts)

  --build-drafts        Include posts marked as drafts

  --version             Print version