0.18.1 • Published 4 months ago

mikel-press v0.18.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

mikel-press

npm version license

mikel-press is a static site generator inspired by Jekyll and built on top of mikel, a Mustache-based templating engine. It allows you to generate static websites from HTML and Markdown files using a flexible plugin system.

Installation

To install mikel-press, ensure you have Node.js installed on your system. Then, add this package as a dependency to your project using yarn:

$ yarn add --dev mikel-press

Or npm:

$ npm install --dev mikel-press

Configuration

mikel-press can be configured using a config object that accepts the following options:

FieldDescriptionDefault
sourceThe path to the directory containing the site's HTML or Markdown files."content"
destinationThe output directory where the generated static site will be saved."www"
layoutThe path to the layout file that will be used as the base template for all pages.-
pluginsA list of plugins used to extend the functionality of mikel-press.[]
*Any other properties passed in config will be available as site.* inside each page template.-

Here is an example configuration object:

const config = {
    source: "./content",
    destination: "./www",
    layout: "./layout.html",
    title: "Hello world",
    description: "My awesome site",
    plugins: [
        press.SourcePlugin(),
        press.FrontmatterPlugin(),
        press.PermalinkPlugin(),
        press.ContentPlugin(),
        press.CopyAssetsPlugin({
            patterns: [
                { from: "./static/styles.css", to: "static/" },
            ],
        }),
    ],
};

Content

Variables

Each HTML file processed by mikel-press will be handled by the mikel templating engine, that will provide the following data variables to each page:

Global variables

VariableDescription
siteContains the site information and all the additional keys provided in the configuration object.
pageSpecific information about the page that is rendered.
layoutSpecific information about the layout that is used for renderin the page.

Site variables

VariableDescription
site.dataAn object containing all data items loaded by DataPlugin.
site.pagesA list containing all pages processed by mikel-pres.
site.*All the additional configuration fields provided in the configuration.

Page variables

VariableDescription
page.pathThe path to the page. Example: about/index.html.
page.urlThe path to the page including the leading /. Example: /about/index.html.
page.attributesAn object containing all the frontmatter variables in the page processed by FrontmatterPlugin.
page.contentThe raw content of the page before begin processed by mikel.

Layout variables

VariableDescription
layout.attributesAn object containing all the frontmatter variables in the layout processed by FrontmatterPlugin.
layout.contentThe raw content of the layout.

Plugins

mikel-press relies on plugins to handle file reading, transformation, and rendering. The following plugins are built-in:

press.SourcePlugin(options)

This plugin reads content from the specified config.source directory and loads it into the system for processing.

Options:

  • options.source (string): Specifies a custom source directory. If not provided, config.source is used.
  • options.extensions (array): Defines the file extensions that should be processed. The default value is [".html", ".md", ".markdown"].

press.DataPlugin(options)

This plugin loads JSON files from the specified directory and makes them available in the site context.

Options:

  • options.source (string): Specifies a custom source directory for data files. If not provided, ./data is used.

press.FrontmatterPlugin(options)

This plugin processes frontmatter in Markdown and HTML files.

Options:

  • options.extensions (array): Defines the file extensions that should be processed. The default value is [".md", ".markdown", ".html"].
  • options.parser (function): Frontmatter parser function (e.g., JSON.parse, YAML.load).

press.PermalinkPlugin()

This plugin allows defining custom permalinks for pages.

press.MarkdownPlugin(options)

This plugin processes Markdown files and converts them to HTML.

Options:

  • options.parser (function): Markdown parser function (e.g., marked.parse).

press.ContentPlugin(options)

This plugin processes each page and saves it into config.destination. It accepts an options object, which is passed to mikel for template processing.

press.CopyAssetsPlugin(options)

This plugin copies static files from the source to the destination.

Options:

  • options.patterns (array): List of file patterns to copy. Each pattern should have from and to.

Node API

mikel-press provides an API with two main methods:

press.build(config)

Triggers the build of mikel-press with the given configuration object provided as an argument.

import press from "mikel-press";

press.build(config);

press.watch(config)

Calling the watch method triggers the build, but also watches for changes and rebuilds the site as soon as it detects a change in any of the source files.

import press from "mikel-press";

press.watch(config);

License

This project is licensed under the MIT License.

0.18.1

4 months ago

0.2.0

6 months ago

0.1.0

6 months ago

0.0.1

6 months ago