{"id":13493751,"url":"https://github.com/mohitsinghs/njk","last_synced_at":"2025-09-29T08:31:19.049Z","repository":{"id":22350991,"uuid":"95630971","full_name":"mohitsinghs/njk","owner":"mohitsinghs","description":"Render nunjucks templates with markdown and front-matter","archived":true,"fork":false,"pushed_at":"2023-07-07T10:21:41.000Z","size":828,"stargazers_count":18,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-16T22:28:27.576Z","etag":null,"topics":["cli","frontmatter","html","markdown","njk","nunjucks","template","zero-configuration"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/njk","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/mohitsinghs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-06-28T05:13:53.000Z","updated_at":"2024-04-24T21:09:53.000Z","dependencies_parsed_at":"2024-01-16T12:27:51.502Z","dependency_job_id":"0931ea0f-47d7-4fca-ab7b-57283ef2f5dc","html_url":"https://github.com/mohitsinghs/njk","commit_stats":{"total_commits":231,"total_committers":6,"mean_commits":38.5,"dds":"0.48051948051948057","last_synced_commit":"4989534433a02e358190499d133ef0786c766a72"},"previous_names":["njk-cli/njk","mohitsinghs/njk"],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohitsinghs%2Fnjk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohitsinghs%2Fnjk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohitsinghs%2Fnjk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohitsinghs%2Fnjk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohitsinghs","download_url":"https://codeload.github.com/mohitsinghs/njk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234604462,"owners_count":18859164,"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","frontmatter","html","markdown","njk","nunjucks","template","zero-configuration"],"created_at":"2024-07-31T19:01:18.454Z","updated_at":"2025-09-29T08:31:13.745Z","avatar_url":"https://github.com/mohitsinghs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003enjk\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/mohitsinghs/njk/main.yml?style=flat-square\u0026logo=github\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/njk\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/njk.svg?style=flat-square\u0026logo=npm\" alt=\"npm version\"\u003e\u003c/a\u003e\n  \u003cimg alt=\"node-current\" src=\"https://img.shields.io/node/v/njk?style=flat-square\u0026logo=nodedotjs\"\u003e\n  \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/mohitsinghs/njk?style=flat-square\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eRender nunjucks templates with markdown and front-matter\u003c/b\u003e\u003cbr/\u003e\n  \u003csub\u003egenerate ( and minify ) html based on nunjucks templates, markdown, front-matter and json/yml data\u003c/sub\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n## About\n\n**njk is no longer maintained**. It was created in 2017 as a command line tool to help me migrate from Jekyll.\nIt served it's purpose well for me, but since then, I've migrated almost all of my sites to use other\ntools. And for all those repositories using it as a library along with nunjucks and express, 🫡\n\n## Install\n\nInstall with [npm](https://npm.im/njk)\n\n```sh\nnpm install --dev njk\n```\n\nor with [yarn](https://yarn.pm/njk)\n\n```sh\nyarn add --dev njk\n```\n\n## Usage\n\n```sh\nnjk \u003cfiles|dirs|globs\u003e [options]\n```\n\n### Command Line Flags\n\n- **`-V`** prints version\n- **`-h or --help`** prints help text\n- **`-v or --verbose`** includes additional logging\n- **`-b or --block`** wraps a content block by default. This is convenient when you you want to extend just one block. This helps you avoid writing extends tag in child template\n- **`-c or --clean`** uses clean urls (urls with forward slash) for output files.\n- **`-q or --quiet`** silences the output until any error occurs.\n- **`-w or --watch`** runs everything in watch mode. HTML is not minified in this mode.\n\n### Command Line Options\n\n- **`-d or --data`** pass either json file path of yaml directory path containing data.\n- **`-t or --template`** pass template directories (nunjucks searchPaths). Multiple template directories can be passed, separated by comma `,`\n- **`-o or --out`** pass output directory\n\n### File Specific Options\n\nFollowing options can be configured through front-matter of individual files.\n\n- **`layout`** parent layout/template to use for rendering a file. This inserts a `extends` tag automatically.\n- **`block`** Wraps a content block around a page. If enabled, an empty content block is required in parent template where content will be inserted.\n- **`clean`** Uses clean urls while writing files. For example `file.html` will be written as `file/index.html`\n\n## Contributing\n\nYou can help improving njk in following ways -\n\n- Found a bug, create an issue with relevant information.\n- Want a feature to be added, A pull request is always welcome.\n\n\u003ch2\u003eSome Examples\u003c/h2\u003e\n\u003cdetails\u003e\n  \u003csummary\u003e\n    \u003cb\u003e1. Rendering a template using block flag and layout option in front matter\u003c/b\u003e\n  \u003c/summary\u003e\n  \u003cbr/\u003e\n\nWe can avoid wrapping `extends` tags and overriding `block` tags, If we need to inject single block in parent template.\n\n**Step 1**\n\nConsider we have a nunjucks template with single block.\n\n_`default.njk`_\n\n```nunjucks\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003ePage Title\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  {% block content %}{% endblock %}\n  \u003c!-- The block name content is important --\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nand a simple html page\n\n_`index.html`_\n\n```nunjucks\n---\nlayout: default\n---\n\u003cheader\u003e\n\u003ch1\u003eOn Laughing\u003c/h1\u003e\n\u003c/header\u003e\n\u003cmain\u003e\n\u003cp\u003eA laugh draws a lot of painful lines.\u003c/p\u003e\n\u003c/main\u003e\n\u003cfooter\u003e\n\u003csmall\u003eCopyright \u0026copy; Creator Inc.\u003c/small\u003e\n\u003c/footer\u003e\n```\n\n**Step 2**\n\nNow, Let's run njk.\n\n```bash\nnjk index.html -b\n```\n\n\u003e The current directory will be used for templates.\n\n**Result**\n\nThe result will be something like\n\n_`dist/index.html`_\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003ctitle\u003ePage Title\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cheader\u003e\n      \u003ch1\u003eOn Laughing\u003c/h1\u003e\n    \u003c/header\u003e\n    \u003cmain\u003e\n      \u003cp\u003eA laugh draws a lot of painful lines.\u003c/p\u003e\n    \u003c/main\u003e\n    \u003cfooter\u003e\n      \u003csmall\u003eCopyright © Creator Inc.\u003c/small\u003e\n    \u003c/footer\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n    \u003cb\u003e2. Rendering a template using layout option in front matter\u003c/b\u003e\n  \u003c/summary\u003e\n  \u003cbr/\u003e\n\nWrapping `extends` tag in each of our file isn't super cool,\n\nand we can avoid this by using `layout` option in front-matter.\n\n### Example\n\n**Step 1**\n\nConsider we have a nunjucks template with 3 blocks.\n\n_`default.njk`_\n\n```nunjucks\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003ePage Title\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cheader\u003e\n    {% block header %}{% endblock %}\n  \u003c/header\u003e\n  \u003cmain\u003e\n    {% block main %}{% endblock %}\n  \u003c/main\u003e\n  \u003cfooter\u003e\n    {% block footer %}{% endblock %}\n  \u003c/footer\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nand a simple html page with content for these 3 blocks\n\n_`index.html`_\n\n```nunjucks\n---\nlayout: default\n---\n{% block header %}\n\u003ch1\u003eOn Laughing\u003c/h1\u003e\n{% endblock %}\n{% block main %}\n\u003cp\u003eA laugh draws a lot of painful lines.\u003c/p\u003e\n{% endblock %}\n{% block footer %}\n\u003csmall\u003eCopyright \u0026copy; Creator Inc.\u003c/small\u003e\n{% endblock %}\n```\n\n**Step 2**\n\nNow, Let's run njk.\n\n```bash\nnjk index.html\n```\n\n\u003e The current directory will be used for templates.\n\n**Result**\n\nThe result will be something like\n\n_`dist/index.html`_\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003ctitle\u003ePage Title\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cheader\u003e\u003ch1\u003eOn Laughing\u003c/h1\u003e\u003c/header\u003e\n    \u003cmain\u003e\u003cp\u003eA laugh draws a lot of painful lines.\u003c/p\u003e\u003c/main\u003e\n    \u003cfooter\u003e\u003csmall\u003eCopyright © Creator Inc.\u003c/small\u003e\u003c/footer\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\n    \u003cb\u003eExtra : Configuring layout through data passed\u003c/b\u003e\n  \u003c/summary\u003e\n  \u003cbr/\u003e\n\nWe can go one step further and configure layout it in the data passed with `-d` or `--data`\n\n**Step 1**\n\nRemove front-matter from _`index.html`_\n\n_`index.html`_\n\n```nunjucks\n{% block header %}\n\u003ch1\u003eOn Laughing\u003c/h1\u003e\n{% endblock %}\n{% block main %}\n\u003cp\u003eA laugh draws a lot of painful lines.\u003c/p\u003e\n{% endblock %}\n{% block footer %}\n\u003csmall\u003eCopyright \u0026copy; Creator Inc.\u003c/small\u003e\n{% endblock %}\n```\n\n**Step 2 ( using yml )**\n\n_`data/page.yml`_\n\n```yml\nlayout: default\n```\n\nWe need to run\n\n```bash\nnjk index.html -d data\n```\n\nNote that file name is important here, as we need `page.layout` property.\n\n**Step 2 ( using json )**\n\nWe can pass a single json file instead of `data` folder\n\n_`data.json`_\n\n```json\n{\n  \"page\": {\n    \"layout\": \"default\"\n  }\n}\n```\n\nWe need to run\n\n```bash\nnjk index.html -d data.json\n```\n\n**Result**\n\nThe result will be same as our previous run (Example 2).\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohitsinghs%2Fnjk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohitsinghs%2Fnjk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohitsinghs%2Fnjk/lists"}