Skip to content

Javarome/ssg-api

Repository files navigation

ssg-api CircleCI

TypeScript API to generate output files from input files.

It can be used to generate:

  • a static website from HTML templates (but those templates can include client-side JavaScript and CSS of course).
  • (and/or) other files such as configuration files (for instance converting an .htaccess file to a netlify.toml file)

To install ssg-api as a project dependency:

npm install --save ssg-api

Then import the required types to implement your own SSG code:

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

const config: SsgConfig = {
  getOutputPath(context: SsgContext): string {
    return path.join("out", context.file.name)
  }
};
const ssg = new Ssg(config)
  .add(firstStep)
  .add(nextStep); // Write your own SSG steps!

const context = new SsgContextImpl("fr");
try {
  const result = await ssg.start(context);
  context.log("Completed", result);
} catch (err) {
  context.error(err, context.inputFile.name, "=>", context.outputFile.name);
}

Steps can do anything. You can implement your owns, but there are predefined ones. Check the documentation for more.

About

TypeScript API to generate a static website.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published