{"id":16007356,"url":"https://github.com/armordarks/grunt-gray-matter","last_synced_at":"2026-05-14T18:04:38.854Z","repository":{"id":57255110,"uuid":"81100587","full_name":"ArmorDarks/grunt-gray-matter","owner":"ArmorDarks","description":"A Grunt task for extracting data header from file contents using Gray Matter","archived":false,"fork":false,"pushed_at":"2017-10-06T13:54:25.000Z","size":80,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-19T16:11:34.577Z","etag":null,"topics":["front-matter","frontmatter","gray-matter","graymatter","grunt","grunt-plugin","grunt-plugins","grunt-task","gruntjs","gruntplugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArmorDarks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-06T15:20:33.000Z","updated_at":"2017-10-06T13:32:14.000Z","dependencies_parsed_at":"2022-09-04T13:10:13.947Z","dependency_job_id":null,"html_url":"https://github.com/ArmorDarks/grunt-gray-matter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArmorDarks%2Fgrunt-gray-matter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArmorDarks%2Fgrunt-gray-matter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArmorDarks%2Fgrunt-gray-matter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArmorDarks%2Fgrunt-gray-matter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArmorDarks","download_url":"https://codeload.github.com/ArmorDarks/grunt-gray-matter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240645417,"owners_count":19834412,"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":["front-matter","frontmatter","gray-matter","graymatter","grunt","grunt-plugin","grunt-plugins","grunt-task","gruntjs","gruntplugin"],"created_at":"2024-10-08T12:03:00.032Z","updated_at":"2026-05-14T18:04:33.834Z","avatar_url":"https://github.com/ArmorDarks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"grunt-gray-matter [![Build Status](https://travis-ci.org/ArmorDarks/grunt-gray-matter.svg?branch=master)](https://travis-ci.org/ArmorDarks/grunt-gray-matter)\n=================\n\n\u003e A Grunt task for extracting data header from file contents using Gray Matter\n\n![grunt-gray-matter task demo](https://cloud.githubusercontent.com/assets/4460311/22854588/92609ace-f07a-11e6-8c83-5cbcc7a13a7b.gif)\n\n\n## Getting Started\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the\n[Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create\na [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins.\n\nInstall plugin with following command:\n\n``` shell\nnpm install grunt-gray-matter --save\n```\n\nOnce installed, eenable task inside your Gruntfile:\n\n``` coffee\ngrunt.loadNpmTasks('grunt-gray-matter')\n```\n\nAdd minimal configuration for task in Gruntfile:\n\n``` coffee\ngrunt.initConfig\n  grayMatter:\n    build:\n      src: 'source/templates/{,**/}*.html'\n      dest: 'data/matter.json'\n```\n\nFinally, run task with following command:\n\n``` shell\ngrunt grayMatter\n```\n\n\n## The `grayMatter` task\n\nTask scans specified in `files` `src` files, reads Gray Matter (Front Matter) header with [Gray Matter](https://github.com/jonschlinkert/gray-matter) and outputs collected result in form of JSON to specified `dest` file.\n\nPath of each discovered `src` will serve as property in final JSON for extracted Gray Matter data of that `src`.\n\n### Options\n\n#### options.baseDir\n\nType: `String` Default: `''`\n\nPath portion which should be subtracted from path to discovered `src` file.\n\nResult will be used in `dest` file JSON as property of extracted Gray Matter data.\n\n``` coffee\n@config 'grayMatter',\n  build:\n    options:\n      baseDir: 'source/templates'\n    src: 'source/templates/page.html'\n    dest: 'matter.json'\n```\n\nWill result in\n\n``` json\n{\n  \"page\": {\n    \"html\": {\n      ...\n    },\n  }\n}\n```\n\ninstead of\n\n``` json\n{\n  \"source/templates/page\": {\n    \"html\": {\n      ...\n    },\n  }\n}\n```\n\n#### options.preprocessPath\n\nType: `Function` Default: `undefined`\n\nAllows to alter path (property) under which extracted Matter data will be placed in `dest` JSON file.\n\nNesting will be done with [_.set](https://lodash.com/docs/4.17.4#set), thus any `.` in path or array of strings will result in nesting data deeper.\n\nYou can see [here](https://github.com/LotusTM/Kotsu/blob/master/tasks/data.coffee#L19) as Kotsu uses this option to mirror templates directory structure in final JSON.\n\nWill be invoked with injected values for following arguments:\n\n* `path` — formed after subtracting `options.baseDir` path of current `src`, used to nest data in final JSON;\n* `filepath` — filepath of current `src`.\n\n`this` will correspond to current `file` of task.\n\nShould return altered path in form of `String` or `String[]`.\n\n#### options.preprocessMatterData\n\nType: `Function` Default: `undefined`\n\nAllows to alter extracted Gray Matter data for each discovered `src`.\n\nAs for an example, check out how Kotsu [injects additional data](https://github.com/LotusTM/Kotsu/blob/master/tasks/data.coffee#L22) for each page into final Matter data.\n\nWill be invoked with injected values for following arguments:\n\n* `matterData` — extracted Matter data of current `src`;\n* `path` — formed after subtracting `options.baseDir` path of current `src`, used to nest data in final JSON;\n* `filepath` — filepath of current `src`.\n\n`this` will correspond to current `file` object.\n\nShould return altered Gray Matter data in form of `Object`.\n\n#### options.preprocessData\n\nType: `Function` Default: `undefined`\n\nAllows to alter final data, constructed from extracted Matter data.\n\nResult of this function will be used for printing Object to `dest` file.\n\nWill be invoked with injected values for following arguments:\n\n* `data` — extracted and assembled data from all current `src`es Matter data, processed by `preprocessPath` and `preprocessMatterData` (if specified).\n\n`this` will correspond to current `this` of task.\n\nShould return altered final data in form of `Object`, which will be printed to `dest` file.\n\n#### options.replacer\n\nType: `Function|String[]|Number[]` Default: `null`\n\nPass [replacer](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) parameter to `JSON.stringify()`.\n\n#### options.space\n\nType: `String|Integer` Default: `2`\n\nPass [space](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) parameter to `JSON.stringify()`.\n\nControls indentation for outputted JSON file.\n\n#### options.parser\n\nType: `Function` Default: `undefined`\n\nPass [custom parser](https://github.com/jonschlinkert/gray-matter#optionsparser) to Gray Matter.\n\n#### options.eval\n\nType: `Boolean` Default: `false`\n\nPass [eval](https://github.com/jonschlinkert/gray-matter#optionseval) parameter to Gray Matter.\n\nForces Gray Matter to evaluate CoffeeScript or JavaScript in Front Matter.\n\n#### options.lang\n\nType: `String` Default: `undefined`\n\nPass [lang](https://github.com/jonschlinkert/gray-matter#optionslang) parameter to Gray Matter.\n\n#### options.delims\n\nType: `String` Default: `undefined`\n\nPass [delims](https://github.com/jonschlinkert/gray-matter#optionsdelims) parameter to Gray Matter.\n\n\n\n## Usage examples\n\n``` coffee\n@config 'grayMatter',\n  build:\n    options:\n      baseDir: 'source/templates'\n\n      preprocessPath: (path) -\u003e\n        # do something with paths in constructed json file\n        return path\n\n      preprocessMatterData: (data, path, src) -\u003e\n        # do something with extracted data\n        return data\n\n    src: 'source/templates/{,**/}*.html'\n    dest: 'data/matter.json'\n```\n\n\n## Node support\n\nRequires Node 6.0 or higher.\n\nJust in case, `grunt-gray-matter` 1.2.0 was the last version to support Node 0.10.0. But better go update your Node. Seriously.\n\n\n## Testing\n\nRun `npm test` to launch tests or `npm run test:watch` to watch tests. Observe how magic happens.\n\nTesting requires Node \u003e= 4.0.0.\n\n\n## Examples\n\n* [Kotsu Web Starter Kit](https://github.com/LotusTM/Kotsu)\n\n\n## License\nCopyright 2016 Serj Lavrin.\n\nLicensed under the [Apache 2.0 license](https://github.com/LotusTM/Kotsu/blob/master/LICENSE.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmordarks%2Fgrunt-gray-matter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farmordarks%2Fgrunt-gray-matter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmordarks%2Fgrunt-gray-matter/lists"}