0.0.4 • Published 3 years ago

ssg-ts v0.0.4

Weekly downloads
-
License
none
Repository
-
Last release
3 years ago

ssg-ts

A static site generator using arbitrary Typescript files as templates. Expects a folder of Typescript files which default export strings, writes those strings to the output directory (preserving filenames + folder structure).

Goes nicely with typelating.

Installation

npm install ssg-ts

Usage

ssg [options] <src>

Arguments

  • src - The source path containing input templates

Options

FlagDescription
-V, --versionOutput the version number
-o, --outDir <path>Output directory (default: "./out")
-c, --cleanDelete existing output directory (default: false)
-s, --static <path>A source path containing static files that should be copied into the output
-h, --helpDisplay help (this)

Given the following file structure:

pages/
├─ about.html.ts
├─ blog/
│  ├─ 2021-01-01.html.ts
├─ complex_styles.css.ts
├─ index.html.ts
public/
├─ basic_styles.css

Then running

ssg --static public --outDir output pages

Will produce:

output/
├─ about.html
├─ blog/
│  ├─ 2021-01-01.html
├─ complex_styles.css
├─ index.html
├─ basic_styles.css

That is:

  • Any foo.ext.ts files will be executed as Typescript, and their default export will be written to foo.ext in the output directory, matching the folder structure from the input.
  • HTML, CSS and JS files (by extension) will also be run through js-beautify.
  • Any Typescript files not exporting a string will produce a warning and be skipped.
  • All files from the static directory are copied directly into the output directory (preserving folder structure).

Why?

Why not just use HTML?

I wanted templates, particularly layouts, partials, reusable components, etc.

Why not other SSG?

I don't want the vast majority of their features, and in exchange I have to jump through hoops to lay things out how they expect. If you need something more robust than this, then Eleventy looks good, and supports templates in JS (and TS, with some fiddling).

I did that fiddling and got it working, but realised I was fighting the system when the bits I actually wanted were pretty trivial (have a look for yourself, the source code for ssg-ts is <100 lines of TS).