{"id":16881382,"url":"https://github.com/webketje/metalsmith-handlebars-x","last_synced_at":"2025-04-11T11:44:36.826Z","repository":{"id":42520692,"uuid":"271884547","full_name":"webketje/metalsmith-handlebars-x","owner":"webketje","description":"The best plugin for metalsmith + Handlebars. Global/local partials, in-place \u0026 layout compilation, and maximum flexibility.","archived":false,"fork":false,"pushed_at":"2022-11-05T00:18:06.000Z","size":475,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T08:11:04.421Z","etag":null,"topics":["handlebars","helpers","metalsmith","metalsmith-plugin","partials","plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webketje.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-06-12T20:28:13.000Z","updated_at":"2023-02-10T22:49:19.000Z","dependencies_parsed_at":"2022-09-05T06:21:42.945Z","dependency_job_id":null,"html_url":"https://github.com/webketje/metalsmith-handlebars-x","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webketje%2Fmetalsmith-handlebars-x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webketje%2Fmetalsmith-handlebars-x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webketje%2Fmetalsmith-handlebars-x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webketje%2Fmetalsmith-handlebars-x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webketje","download_url":"https://codeload.github.com/webketje/metalsmith-handlebars-x/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027362,"owners_count":21035590,"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":["handlebars","helpers","metalsmith","metalsmith-plugin","partials","plugin"],"created_at":"2024-10-13T16:01:44.019Z","updated_at":"2025-04-11T11:44:36.807Z","avatar_url":"https://github.com/webketje.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Metalsmith+handlebars\n\nThe best plugin for metalsmith + Handlebars. Global/local partials, in-place \u0026 layout compilation, and maximum customizability.\n\nCombines all of [metalsmith-handlebars], [metalsmith-handlebars-contents], [metalsmith-handlebars-layouts], [metalsmith-discover-helpers], [metalsmith-discover-partials], [@goodthnx/metalsmith-handlebars], [metalsmith-nested], [metalsmith-register-helpers], [metalsmith-register-partials] and adds more. Written out of frustration with incomplete and/or complex existing options.\n\n[![metalsmith: plugin][metalsmith-badge]][metalsmith-url]\n[![npm: version][npm-badge]][npm-url]\n[![travis: build][ci-badge]][ci-url]\n[![code coverage][codecov-badge]][codecov-url]\n[![license: LGPL-3.0][license-badge]][license-url]\n\n## Features\n\n- filter files by `pattern`\n- auto-load global and local partials found in directory specified by option `partials`\n- compile contents (like metalsmith-in-place) and layout (like metalsmith-layouts)\n- includes useful basic `set` and `call` helpers\n- allows custom Handlebars, partials, helpers\n- also works with [metalsmith-layouts], [handlebars-layouts]\n\n## Install\n\nNPM:\n\n```bash\nnpm i -D metalsmith-handlebars-x\n```\n\nYarn:\n\n```bash\nyarn add metalsmith-handlebars-x\n```\n\n## Quickstart\n\n```js\nvar xhandlebars = require('metalsmith-handlebars-x');\n\n// use defaults\nmetalsmith.use(xhandlebars());\n\n// use defaults (explicit)\nmetalsmith.use(xhandlebars({\n  instance: require('handlebars'),\n  pattern: '**/*.{hbs,handlebars}',\n  layout: true,\n  partials: 'partials',\n  helpers: {},\n  context: (filemeta, globalmeta) =\u003e Object.assign({}, globalmeta, filemeta),\n  renameExtension: null\n});\n```\n\n## Debug\n\nSet env var `DEBUG` to `metalsmith-handlebars-x`.\n\nLinux / OSX\n\n```bash\nDEBUG=metalsmith-handlebars-x\n```\n\nWindows\n\n```batch\nset DEBUG=metalsmith-handlebars-x\n```\n\n## Usage\n\n### Partials\n\nPartials will be looked for in the directory specified in the `partials` option.\nPartials are automatically removed from the build output unless `layout: false`.\nA partial at `partials/blockquote.hbs` will be usable in templates as `blockquote`.  \nA partial at `partials/layout/default.hbs` will be usable in templates as `layout/default`.\n\n#### Global partials\n\nGlobal partials (available to all templates) can be registered either by specifying a directory in the `Metalsmith.source` directory:\n\n```js\nmetalsmith.use(handlebars({ partials: 'partials' }));\n```\n\nor by passing the Handlebars instance to the plugin:\n\n```js\nvar Handlebars = require('handlebars');\nHandlebars.registerPartial('blockquote', '\u003cblockquote cite=\"{{url}}\"\u003e{{ quote }}\u003c/blockquote\u003e');\n\nmetalsmith.use(handlebars({ instance: Handlebars }));\n```\n\nBoth can be used together!\n\n#### Local partials\n\nLocal partials will be available to all templates that reside in the same directory.  \nIn the directory structure below both `.md` files have access to partial `layout/default`.\n\n```txt\n├── partials\n|    └── layout\n|         └── default.hbs\n└── posts\n    ├── partials\n    |    └── local.hbs\n    ├── subfolder\n    |    └── post-without-local-partials.md\n    └── post-with-local-partials.md\n```\n\n### Helpers\n\nmetalsmith-handlebars-x provides 2 useful helpers by default:\n\n- `call` : `{{ call func arg1 arg2 arg3 }}` allows calling functions available in template context\n- `set`: `{{ set varname value }}` allows storing temporary variables for re-use in the template\n\nRegister extra helpers through the `helpers` option as `{[helperName]: helperFunc}`, or similar to global partials,\nregister them directly on a Handlebars instance passed to the `instance` option.\n\n### Metadata mapping\n\nSpecify a custom `context` option to map file \u0026 global metadata in your templates, e.g:\n\n```js\ncontext: function(filemeta, globalmeta) {\n  return {\n    page: filemeta,\n    site: globalmeta\n  };\n}\n```\n\nIn your templates:\n\n```html\n{{ site.sitename }} {{ page.stats.birthTime }}\n```\n\n### File extensions\n\nWith the `renameExtension` option you can choose what to do with a file's extension:\n\n- `null` or `undefined` does nothing (default)\n- `\"\"` (empty string) removes the last extension (so `index.hbs` would become `index`, while `style.css.hbs` would become `style.css`)\n- `\".\u003cext\u003e\"` renames the last extension to `\u003cext\u003e`, for example `index.hbs` would become `index.html` if `renameExtension: '.html'`.\n\n### Usage with handlebars-layouts\n\nRelatively straight-forward:\n\n```js\nconst Handlebars = require('handlebars');\nconst hbsLayouts = require('handlebars-layouts')(Handlebars);\nconst xhandlebars = require('metalsmith-handlebars-x');\n\nHandlebars.registerHelper(hbsLayouts);\n\nmetalsmith.use(xhandlebars({ instance: Handlebars }));\n```\n\n### With @metalsmith/layouts \u0026 metalsmith-discover-partials\n\nYou can use this plugin together with @metalsmith/layouts \u0026 metalsmith-discover-partials but you should specify `layout: false` in order to avoid conflicts. metalsmith-handlebars-x will then only compile file `contents`. See [test.js](./tests/test.js#L211) for an example.\n\n## License\n\n[LGPL v3](./LICENSE)\n\n[npm-badge]: https://img.shields.io/npm/v/metalsmith-handlebars-x\n[npm-url]: https://www.npmjs.com/package/metalsmith-handlebars-x\n[ci-badge]: https://img.shields.io/travis/webketje/metalsmith-handlebars-x\n[ci-url]: https://travis-ci.org/webketje/metalsmith-handlebars-x\n[license-badge]: https://img.shields.io/github/license/webketje/metalsmith-handlebars-x\n[license-url]: https://choosealicense.com/licenses/lgpl-3.0/\n[codecov-badge]: https://img.shields.io/coveralls/github/webketje/metalsmith-handlebars-x\n[codecov-url]: https://coveralls.io/github/webketje/metalsmith-handlebars-x\n[metalsmith-badge]: https://img.shields.io/badge/metalsmith-plugin-green.svg?longCache=true\n[metalsmith-url]: https://metalsmith.io/\n[metalsmith-handlebars]: https://www.npmjs.com/package/metalsmith-handlebars\n[metalsmith-layouts]: https://www.npmjs.com/package/metalsmith-layouts\n[handlebars-layouts]: https://www.npmjs.com/package/handlebars-layouts\n[handlebars-rename]: https://www.npmjs.com/package/metalsmith-rename\n[metalsmith-handlebars-contents]: https://www.npmjs.com/package/metalsmith-handlebars-contents\n[metalsmith-handlebars-layouts]: https://www.npmjs.com/package/metalsmith-handlebars-layouts\n[metalsmith-discover-helpers]: https://www.npmjs.com/package/metalsmith-discover-helpers\n[metalsmith-discover-partials]: https://www.npmjs.com/package/metalsmith-discover-partials\n[@goodthnx/metalsmith-handlebars]: https://www.npmjs.com/package/@goodthnx/metalsmith-handlebars\n[metalsmith-nested]: https://www.npmjs.com/package/metalsmith-nested\n[metalsmith-register-helpers]: https://www.npmjs.com/package/metalsmith-register-helpers\n[metalsmith-register-partials]: https://www.npmjs.com/package/metalsmith-register-partials\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebketje%2Fmetalsmith-handlebars-x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebketje%2Fmetalsmith-handlebars-x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebketje%2Fmetalsmith-handlebars-x/lists"}