Skip to content
javarome edited this page May 21, 2024 · 9 revisions

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

Example of predefined steps are:

Such steps can be added to a Ssg instance, before asking it to start performing them. For instance:

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

const config: SsgConfig = {
  getOutputPath(context: SsgContext): string {
    return path.join("out", context.file.name)
  }
}
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)

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.file to perform a transformation.

Clone this wiki locally