{"id":16993498,"url":"https://github.com/the-noah/static-site-generator","last_synced_at":"2025-03-22T15:31:01.799Z","repository":{"id":42852921,"uuid":"260787469","full_name":"The-Noah/static-site-generator","owner":"The-Noah","description":"Generate an optimized static website, or use at run-time with a custom server.","archived":false,"fork":false,"pushed_at":"2022-12-11T04:33:03.000Z","size":272,"stargazers_count":5,"open_issues_count":15,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T13:16:19.216Z","etag":null,"topics":["build","build-tool","builder","cli","compress","compressed","developer-tools","development","devserver","ejs","generator","javascript","json","minify","optimize","static-website-generator","typescript","web","webserver","website"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@the-noah/static-site-generator","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/The-Noah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-02T22:36:36.000Z","updated_at":"2021-09-30T18:35:42.000Z","dependencies_parsed_at":"2023-01-26T15:30:41.345Z","dependency_job_id":null,"html_url":"https://github.com/The-Noah/static-site-generator","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Noah%2Fstatic-site-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Noah%2Fstatic-site-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Noah%2Fstatic-site-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Noah%2Fstatic-site-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/The-Noah","download_url":"https://codeload.github.com/The-Noah/static-site-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244978524,"owners_count":20541866,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","build-tool","builder","cli","compress","compressed","developer-tools","development","devserver","ejs","generator","javascript","json","minify","optimize","static-website-generator","typescript","web","webserver","website"],"created_at":"2024-10-14T03:43:19.535Z","updated_at":"2025-03-22T15:31:01.184Z","avatar_url":"https://github.com/The-Noah.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Static Site Generator\n\n![CI](https://github.com/The-Noah/static-site-generator/workflows/CI/badge.svg)\n[![GitHub license](https://img.shields.io/github/license/The-Noah/static-site-generator.svg)](https://github.com/The-Noah/static-site-generator/blob/master/LICENSE)\n![GitHub package.json version](https://img.shields.io/github/package-json/v/The-Noah/static-site-generator)\n[![npm (scoped)](https://img.shields.io/npm/v/@the-noah/static-site-generator)](https://www.npmjs.com/package/@the-noah/static-site-generator)\n\nGenerate an optimized static website, or use at run-time with a custom server.\n\n\u003c/div\u003e\n\n## Table of Contents\n\n- [Static Site Generator](#static-site-generator)\n  - [Table of Contents](#table-of-contents)\n  - [Features](#features)\n- [Documentation](#documentation)\n  - [Installation](#installation)\n    - [Global](#global)\n    - [Project](#project)\n  - [Configuration (optional)](#configuration-optional)\n  - [Command-Line Interface (CLI)](#command-line-interface-cli)\n  - [Library](#library)\n    - [Importing](#importing)\n    - [`async build()`](#async-build)\n    - [`async renderPage(pagePath, data)`](#async-renderpagepagepath-data)\n    - [`async getData()`](#async-getdata)\n  - [Page Templates](#page-templates)\n  - [Understanding How Data is Collected and Used](#understanding-how-data-is-collected-and-used)\n    - [CSS \u0026 SASS](#css--sass)\n    - [JavaScript \u0026 TypeScript](#javascript--typescript)\n    - [JSON](#json)\n    - [YAML](#yaml)\n  - [Examples](#examples)\n    - [Express Server](#express-server)\n\n## Features\n\n1. Compiles and optimizes SCSS files.\n2. Optimizes JavaScript.\n3. Compiles TypeScript to JavaScript.\n4. Embed data from JSON and YAML files.\n5. HTML templates with ejs and moe.\n6. Automatically copies static files.\n7. Can be used with a custom web server.\n\n# Documentation\n\n## Installation\n\n### Global\n\nInstall with: `npm install -g @the-noah/static-site-generator`\n\n### Project\n\nInstall with `npm install -s @the-noah/static-site-generator`.\n\nAdd `static-site-generator` as a script in your `package.json` to build your website.\n\n## Configuration (optional)\n\nThe configuration file must be named `.static-site-generator.config.json` and must be in the root of your project. Configuration is available in `options`.\n\n| Property  | Type     | Default  | Description |\n| --------- | -------- | -------- | ----------- |\n| srcDir    | `string` | \"src\"    | Path to look in for files. |\n| buildDir  | `string` | \"build\"  | Path to save final files to. |\n| staticDir | `string` | \"static\" | Path in `srcDir` to look for static files. |\n| logLevel  | `number` | 0        | `0` = all, `1` = no info, `2` = no sucess, `3` = no warning, `4` = no error - each level also inherits from the last |\n| compressionLevel | Number | 2 | How much to compress files - `0` = none, `3` = max |\n\n## Command-Line Interface (CLI)\n\nRun `static-site-generator` in the root of your project to build your website.\n\n## Library\n\nstatic-site-generator can be used as a library, such as with a web server.\n\n### Importing\n\n**JavaScript**\n```javascript\nconst {staticSiteGenerator} = require(\"@the-noah/static-site-generator\");\n```\n\n**TypeScript**\n```typescript\nimport {staticSiteGenerator} from \"@the-noah/static-site-generator\";\n```\n\n### `async build()`\n\nRenders all pages in `options.srcDir` and saves them in `options.buildDir`, as well as copies all files from `options.srcDir`/`options.staticDir` to `options.buildDir`.\n\n**Returns** `Promise\u003cvoid\u003e`\n\n**Example**\n```javascript\nawait staticSiteGenerator.build();\n```\n\n### `async renderPage(pagePath, data)`\n\nRenders the page found at `pagePath` with the data `data` and returns a `Promise\u003cstring\u003e` containing the minified HTML.\n\n**Returns** `Promise\u003cstring\u003e`\n\n| Property | Type                      | Description |\n| -------- | ------------------------- | ----------- |\n| pagePath | `string`                  | Path of the page to render. |\n| data     | `Record\u003cstring, unknown\u003e` | Data used to render the page. |\n\n**Example**\n```javascript\nconst html = await staticSiteGenerator.renderPage(\"index.ejs\", {message: \"Hello, World!\"});\n```\n\n### `async getData()`\n\nReturns all data from files found in `options.srcDir`.\n\n**Returns** `Promise\u003cRecord\u003cstring, unknown\u003e\u003e`\n\n**Example**\n```javascript\nconsole.log(await staticSiteGenerator.getData());\n```\n\n## Page Templates\n\nThe following template engines are built-in.\n\n- [ejs](https://www.npmjs.com/package/ejs)\n- [moe](https://www.npmjs.com/package/@toptensoftware/moe-js)\n\nYou can easily add your own using the `addPageFile` and `addPageHandler` methods.\n\n## Understanding How Data is Collected and Used\n\nThe `getData()` function retrieves data from different files types and mashes it together.\n\n### CSS \u0026 SASS\n\n`.css` and compiled `.scss` files will be compressed and available as a string under their filename in the `css` object.\n\n**Example**\n\n`main.css` will be compressed then be available under `css.main`.\n\n`style.scss` will be compiled and compressed then available under `css.style`.\n\n```css\n/* main.css */\nh1{\n  color: red;\n}\n```\n\n```javascript\nconsole.log(data.css.main === \"h1{color:red}\"); // true\n```\n\n### JavaScript \u0026 TypeScript\n\n`.js` and compiled `.ts` files will be compressed and available as a string under their filename in the `js` object.\n\n**Example**\n\n`app.js` will be compressed then available under `js.app`.\n\n`script.ts` will be compiled and compressed then available under `js.script`.\n\n```javascript\n// app.js\nalert(\"Hello, World!\");\n```\n\n```javascript\nconsole.log(data.js.app === \"alert(\\\"Hello, World!\\\");\"); // true\n```\n\n### JSON\n\n`.json` files will be available under their filename.\n\n**Example**\n\n`blog.json` will be available under `blog`.\n\n```json\n[\n  {\n    \"title\": \"My New Blog\",\n    \"date\": \"2020-5-6\",\n    \"text\": \"This is my new blog where I talk about cats!\"\n  }\n]\n```\n\n```javascript\nconsole.log(data.blog[0].date !== \"2020-5-6\") // true\n```\n\n### YAML\n\n`.yaml` and `.yml` files will be available under their filename.\n\n**Example**\n\n`test.yml` will be available under `yml`.\n\n```yaml\nmessage: \"hello\"\n```\n\n```javascript\nconsole.log(data.test.message === \"hello\"); // true\n```\n\n## Examples\n\n### Express Server\n\n```javascript\nconst path = require(\"path\");\n\nconst {staticSiteGenerator} = require(\"@the-noah/static-site-generator\");\nconst express = require(\"express\");\n\nconst app = express();\nconst PORT = 3000;\n\napp.get(\"/\", async (req, res) =\u003e {\n  res.send(await staticSiteGenerator.renderPage(path.join(staticSiteGenerator.options.srcDir, \"index.ejs\"), await staticSiteGenerator.getData());\n});\n\napp.listen(PORT, () =\u003e console.log(`Server running at http://localhost:${PORT}`));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-noah%2Fstatic-site-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-noah%2Fstatic-site-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-noah%2Fstatic-site-generator/lists"}