{"id":16742361,"url":"https://github.com/alexispuga/nunjucks-to-html","last_synced_at":"2025-04-10T13:32:47.354Z","repository":{"id":42696344,"uuid":"292936483","full_name":"AlexisPuga/nunjucks-to-html","owner":"AlexisPuga","description":"Parse Nunjucks templates to HTML directly from the console.","archived":false,"fork":false,"pushed_at":"2023-07-18T23:36:16.000Z","size":624,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T10:48:54.394Z","etag":null,"topics":["cli-tool","github-actions-ci","integration-testing","jest","njk-to-html","npm-package","nunjucks","nunjucks-to-html","parse-nunjucks-templates"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/AlexisPuga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-04T20:04:01.000Z","updated_at":"2022-12-06T13:59:38.000Z","dependencies_parsed_at":"2023-02-09T10:01:08.060Z","dependency_job_id":null,"html_url":"https://github.com/AlexisPuga/nunjucks-to-html","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisPuga%2Fnunjucks-to-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisPuga%2Fnunjucks-to-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisPuga%2Fnunjucks-to-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisPuga%2Fnunjucks-to-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexisPuga","download_url":"https://codeload.github.com/AlexisPuga/nunjucks-to-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248225712,"owners_count":21068078,"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":["cli-tool","github-actions-ci","integration-testing","jest","njk-to-html","npm-package","nunjucks","nunjucks-to-html","parse-nunjucks-templates"],"created_at":"2024-10-13T01:23:31.751Z","updated_at":"2025-04-10T13:32:47.324Z","avatar_url":"https://github.com/AlexisPuga.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nunjucks to HTML\n\n![Cross OS CI](https://github.com/AlexisPuga/nunjucks-to-html/workflows/Cross%20OS%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/nunjucks-to-html.svg)](https://badge.fury.io/js/nunjucks-to-html)\n\n**Parse Nunjucks templates to HTML easily. You don't need Gulp nor Grunt to do it.**\n\n*Keep your HTML clean and modularized by using a templating engine, like [Nunjucks](https://mozilla.github.io/nunjucks). Then, convert those files into HTML during your development process or even during production. This way, you can split your files, replace variables, etc... Why Nunjucks? Because it's heavily inspired by [Jinja2](https://jinja.palletsprojects.com/) but written for Javascript environments.*\n\n## Installation\n\nVia npm:\n```cli\nnpm i nunjucks-to-html\n```\n\nVia yarn:\n```cli\nyarn add nunjucks-to-html\n```\n\n## Usage\n\nUsing this tool is as simple as installing it, and executing the following:\n```cli\nnunjucks-to-html\n```\n\nHowever, it's expected to be used in your package.json (in the \"scripts\" section):\n```json\n\"scripts\": {\n  \"build\": \"npm run build:html\",\n  \"build:html\": \"nunjucks-to-html\"\n},\n\"devDependencies\": {\n  \"nunjucks-to-html\": \"*\"\n}\n```\n\nOr importing it server side using:\n```js\nconst nunjucksToHTML = require('nunjucks-to-html');\n// Or: import nunjucksToHTML from 'nunjucks-to-html';\n```\n\n## CLI usage\n\n```cli\n\nUsage: nunjucks-to-html [sources] [flags...]\n\n  --baseDir \u003cpath\u003e        Base directory for the source files. Defaults to \"\".\n  --config \u003cfilepath\u003e     Filepath to the config file. Relative to cwd. Defaults to \"nunjucks.config.js\".\n  --dest \u003cpath\u003e           Path to the destination directory. Relative to cwd. Defaults to \"public\"\n  --ext \u003cstring\u003e \t  Extension for the destination file. Defaults to .html\n  --cwd \u003cpath\u003e            The path for the current working directory. Defaults to process.cwd().\n  --flatten \u003cboolean\u003e     If present, flatten the source file name under the destination path. If absent, use the full source file name under the destination path. Defaults to false.\n\n```\n\n## CLI examples\n\nTo parse all `.njk` files and save them in `public/`:\n  ```cli\n  nunjucks-to-html\n  ```\n\nTo parse all `.njk` files in `static/` and save them in `public/`:\n  ```cli\n  nunjucks-to-html --baseDir static\n  ```\n\nTo parse `.njk` and `.html` files under the `static/` directory and save them in `public/static`:\n  ```cli\n  nunjucks-to-html static/**/*.{njk,html}\n  ```\n\nTo configure the destination path, use the `--dest` flag:\n  ```cli\n  nunjucks-to-html --dest my-destination\n  ```\n\nTo configure Nunjucks using a config. file:\n  ```cli\n  nunjucks-to-html\n  ```\n  ```js\n  // nunjucks.config.js\n  module.exports = {\n    \"options\": {\n      /**\n       * A path to the file containing data for the template.\n       * If you want to pass an object, use \"render.context\" instead.\n       */\n      \"data\": \"some/path/on/cwd.js\",\n      /**\n       * A hook that's called before calling nunjucks.render()\n       * but after nunjucks.configure().\n       *\n       * Return false to skip rendering (and writing).\n       */\n      beforeRender (nunjucksEnv, renderName, renderData) { let nunjucks = this; },\n      /**\n       * A hook that's called after calling nunjucks.render()\n       * but before writing to a file.\n       *\n       * Return false to skip writing.\n       */\n      beforeWrite (destinationFilepath, renderResult) { let nunjucks = this; }\n    },\n\n    /**\n     * The following keys are members of Nunjucks.\n     * To modify any parameter or see possible values,\n     * plese check https://mozilla.github.io/nunjucks/api.html\n     */\n\n    // Executes nunjucks.configure([path], [options]).\n    \"configure\": {\n      \"path\": undefined,\n      \"options\": {\n        \"autoescape\": true,\n        \"throwOnUndefined\": false,\n        // ...\n      }\n    },\n\n    // Executes nunjucks.render(name, [context], [callback]).\n    \"render\": {\n      \"name\": undefined, // You shouldn't change this.\n      /**\n       * An object literal containing the data for the template.\n       * If you need to load data from a file, use \"options.data\" instead.\n       * If you decide to use \"options.data\" too, this property will be assigned to it.\n       */\n      \"context\": {},\n      \"callback\": () =\u003e {} // Not modificable.\n    }\n\n  };\n  ```\n\nTo configure the name of the config file, use the `--config` flag:\n  ```cli\n  nunjucks-to-html --config njk.js\n  ```\n\nTo call multiple jobs with different options, export an array of tasks:\n  ```cli\n  nunjucks-to-html\n  ```\n  ```js\n  // nunjucks.config.js\n  module.exports = [{\n    \"configure\": {},\n    \"render\": {}\n  }, {\n    \"configure\": {},\n    \"render\": {}\n  }, /* ... */];\n  ```\n\nTo change the file extension of the destination file, use the `--ext` flag.\n  ```cli\n  nunjucks-to-html --ext .html\n  ```\n\nTo flatten the source file name under the destination path, use the `--flatten` flag.\n  ```cli\n\tnunjucks-to-html --flatten\n  ```\n\nTo change the current working directory, use the `--cwd` flag:\n  ```cli\n  nunjucks-to-html --cwd /var/www\n  ```\n\n## Nodejs usage\n\nThe following are the default/supported parameters for this module:\n\n```js\nconst nunjucksToHtml = require('nunjucks-to-html');\n\nnunjucksToHtml(['**/*.njk'], {\n  'config': 'nunjucks.config.js',\n  'dest': 'public',\n  'ext': '.html',\n  'baseDir': '',\n  'cwd': process.cwd(),\n  'flatten': false\n}).then((results) =\u003e {})\n  .catch((error) =\u003e {});\n\n// Produces the same result as calling:\n// nunjucksToHtml().then((results) =\u003e {}).catch((error) =\u003e {});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexispuga%2Fnunjucks-to-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexispuga%2Fnunjucks-to-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexispuga%2Fnunjucks-to-html/lists"}