1.16.10 • Published 8 months ago

ssg-api v1.16.10

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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);
}

Data types

Steps

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

Files

classDiagram
    namespace fileutil {
        class FileContents {
            name: string
            lastModified: Date
            contents: string
            encoding: BufferEncoding
            write(): Promise<void>
            read(fileName, declaredEncoding)$: FileContents
            readOrNew(fileName, declaredEncoding)$: FileContents
            getLang(filePath)$: FileContentsLang
            getContents(fileName, declaredEncoding)$
        }
        class FileContentsLang {
            lang: string | undefined
            variants: string[]
        }
    }
    FileContents --> FileContentsLang: lang
    namespace ssg-api {
        class HtmlFileContents {
            lang
            title: string
            contents: string
            document: Document
            read(fileName): HtmlFileContents
            serialize(): string
            create(FileContents)$: HtmlFileContents
            getMeta(name, document)$: string[]
            getLink(rek, document)$: Link[]
        }
        class HtmlMeta {
            url?: string
            author: string[]
            copyright?: string
            description?: string
            generator?: string
        }
        class HtmlLinks {
        }
        class Link {
            type: LinkType;
            text: string;
            url: string;
        }
    }
    HtmlFileContents --> HtmlMeta: meta
    HtmlFileContents --> HtmlLinks: links
    HtmlLinks --> Link: start?
    HtmlLinks --> Link: contents?
    HtmlLinks --> Link: prev?
    HtmlLinks --> Link: next?
    FileContents <|-- HtmlFileContents
1.16.10

8 months ago

1.16.7

8 months ago

1.16.6

8 months ago

1.16.5

8 months ago

1.16.8

8 months ago

1.16.4

9 months ago

1.14.1

10 months ago

1.16.3

9 months ago

1.16.2

9 months ago

1.16.1

10 months ago

1.16.0

10 months ago

1.15.0

10 months ago

1.10.5

1 year ago

1.14.0

10 months ago

1.10.4

1 year ago

1.10.3

1 year ago

1.12.0

12 months ago

1.10.8

1 year ago

1.10.7

1 year ago

1.10.6

1 year ago

1.11.0

1 year ago

1.13.2

11 months ago

1.13.1

11 months ago

1.13.0

11 months ago

1.13.6

10 months ago

1.13.5

10 months ago

1.13.4

10 months ago

1.13.3

11 months ago

1.9.1

1 year ago

1.13.7

10 months ago

1.10.1

1 year ago

1.10.0

1 year ago

1.8.0

1 year ago

1.7.7

1 year ago

1.7.6

1 year ago

1.9.0

1 year ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.5

2 years ago

1.6.0

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

3 years ago

1.2.13

3 years ago

1.2.12

3 years ago

1.2.11

3 years ago

1.2.10

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago