DEV Community

Cover image for cli-ssg 0.0.1: Node.js based static site generator
Kunwarvir
Kunwarvir

Posted on

cli-ssg 0.0.1: Node.js based static site generator

As a part of my open source journey, this week I created cli-ssg, an open source static site generator using Node.js. It is a command line tool to generate .html files from a given set of input .txt files.

Features

✅ Parse title from the input files
✅ Ability to provide a custom output directory
✅ Ability to provide stylesheet URL
✅ Recursively parses input nested directories and files
✅ Automatically generates index.html if multiple txt files are present in input directory

Installation:

npm i
npm i -g .
npm link
Enter fullscreen mode Exit fullscreen mode

Usage

cli-ssg -i "sample_file.txt"
Enter fullscreen mode Exit fullscreen mode

This processes text from sample_file.txt and generates sample_file.html

cli-ssg -i "sample_file.txt" -s "./stylesheet.css"
Enter fullscreen mode Exit fullscreen mode

Same as above, however sample_file.html now uses ./stylesheet.css

cli-ssg -i "sample_dir" -o "output_dir"
Enter fullscreen mode Exit fullscreen mode

This processes all the .txt files in sample_dir and generates .html files for each of them. It also creates an index.html with relative links to each page, storing all these files in output_dir.

Options

  -h, --help        Show help                                          [boolean]
  -v, --version     Show version number                                [boolean]
  -i, --input       Input file/folder to be processed        [string] [required]
  -o, --output      Output directory                [string] [default: "./dist"]
  -s, --stylesheet  CSS Stylesheet for the website                      [string]
Enter fullscreen mode Exit fullscreen mode

Examples

Simple Example:

cli-ssg -i ".\sample_input.txt" -o "custom_dir" -s "https://cdnjs.cloudflare.com/ajax/libs/tufte-css/1.8.0/tufte.min.css"

sample_input.txt:

Sample title                   //<---first line followed by 2 empty lines treated as title


This is the first paragraph.
                               //<--- blank spaces treated as paragraph limits
This is the second paragraph.

This is the third paragraph
Enter fullscreen mode Exit fullscreen mode

custom_dir\sample_output.html:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Sample title</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="https://cdnjs.cloudflare.com/ajax/libs/tufte-css/1.8.0/tufte.min.css" rel="stylesheet">
    </head>
    <body>
      <h1>Sample title</h1>
      <p>This is the first paragraph.</p><p>This is the second paragraph.</p>
    </body>
    </html>
Enter fullscreen mode Exit fullscreen mode

Complex Example:

Using multiple text files in the input directory, the following website was created with an auto-generated index.html having links to each individual page:

https://cli-ssg.vercel.app/

View it on GitHub:

https://github.com/dhillonks/cli-ssg

Top comments (0)