Skip to content

Repository files navigation

zola-npm

npm npm GitHub release (latest SemVer)

This package provides Node.js bindings, command-line and javascript API for Zola

Compiled directly from its source code and bindings exposed via Node-API, The performance is closer to that of native/official zola binaries while having the convenience of an npm package, making deployment easier across various environments/platforms wherever Node.js is supported.

What's Zola ?

Zola is a static site generator (SSG), similar to Hugo, Pelican, and Jekyll. It is written in Rust and uses the Tera template engine, which is similar to Jinja2, Django templates, Liquid, and Twig. Content is written in CommonMark, a strongly defined, highly compatible specification of Markdown.

Links

Supported Platforms

  • win32 (x64)
  • linux (x64)
  • darwin (x64, arm64)

Usage

Add it as a dev dependency into your npm project

npm i -D zola-bin

or

npm i -g zola-bin

From CLI

Format: npx zola-bin [args]

Use the args from the official Zola's CLI.

You can also add it to scripts in the package.json file

"scripts": {
    "dev": "zola-bin serve --port 7000 --open",
    "build": "zola-bin build"
}

JavaScript API

import { build, init, check, serve } from "zola-bin";

Each of these methods are a wrapper around the CLI commands. You can refer to the JSdoc of each function or the type definitions on how to use them.

interface BuildOptions {
	baseUrl?: string;
	outputDir?: string;
	force?: boolean;
	drafts?: boolean;
	minify?: boolean;
}
export declare function build(rootDir: string, configFile?: string, options?: BuildOptions): void;

interface ServeOptions {
	interface: string;
	port: number;
	outputDir?: string;
	force: boolean;
	baseUrl?: string;
	open: boolean;
	storeHtml: boolean;
	drafts: boolean;
	fast: boolean;
	noPortAppend: boolean;
	extraWatchPaths: Array<string>;
	debounce?: number;
}
export declare function serve(rootDir: string, configFile?: string, options?: ServeOptions): void;

export declare function init(name: string): void;

interface checkOptions {
	basePath: string | undefined | null;
	baseUrl: string | undefined | null;
	drafts: boolean;
	skipExternalLinks: boolean;
}
export declare function check(rootDir: string, configFile?: string, options?: checkOptions): void;

Getting Started with Create Zola Site

With NPM installed, you can quickly setup a new Zola site with the following command:

npx create-zola-site -n {NAME}

This will create a new directory {NAME} and initializes the necessary files in it. Note that the site created using this process depends on Node.js, so you might see package.json and node_modules in the directory. This doesn't mean it any works different than actual template initialized by Zola. But This template will simplify the process of creating, building and deploying a new site.

if you already have a existing site, you can add the zola-bin NPM package to make it work same as the one created with create-zola-site.

npm init
npm i -D zola-bin

And then you can add the following script to your package.json file:

"scripts": {
    "dev": "zola-bin serve --open",
    "build": "zola-bin build",
}

FAQ

  • What is the difference between Zola and create-zola-site template ?

    • Nothing, directory structure is pretty much the same and works the same.
    • create-zola-site template creates extra files - package.json and node_modules, with zola-bin npm package as a devDependency, which builds bindings from the source code and exposes them as node.js function calls.
  • Why would I use this instead of the official one ?

    • For those who are used to NPM, this package makes it feel home
    • Easily deploy the sites since Node.js and NPM are accepted by most hosting services.

About

Node native bindings for Zola, A Static Site Generator

Topics

Resources

Contributing

Stars

10 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages