Skip to content
Jérôme Beau edited this page Nov 16, 2022 · 9 revisions

The Ssg execute a number of Steps, sequentially (this allows steps to rely on replacements from a previous one).

For instance:

import {SsgConfig, SsgContextImpl, Ssg, ContentStep, CopyStep} from "ssg-api"

const config: SsgConfig = {outDir: "out"}
const context = new SsgContextImpl("fr", {})

new Ssg(config)
  .add(new ContentStep(contentConfigs, outputFunc))
  .add(dir1SubdirectoriesStep)
  .add(dir2SubdirectoriesStep)
  .add(...anArrayOfSteps)
  .add(new CopyStep(copiesToDo))
  .start(context)

Predefined steps

Ready-to-use steps implementations are:

  • CopyStep copies files;
  • ContentStep perform replacements in files contents (see predefined replacements).
  • DirectoryStep completes a template based on sub-directories, sequentially (to produce a listing of them, typically).

Custom step

You can create your own steps by implementing the SsgStep interface.

A Step can do anything and return its own results (here a boolean):

class MyStep implements SsgStep {
  
  async execute(context: SsgContext): Promise<boolean> {
    context.log("Performing my step")
    return true
  }
}

but it will typically use context.inputFile and context.outFile to perform a transformation.

Clone this wiki locally