{"id":16485384,"url":"https://github.com/morganconrad/metalsmith-keymaster","last_synced_at":"2025-03-23T12:32:59.437Z","repository":{"id":13498309,"uuid":"74601333","full_name":"MorganConrad/metalsmith-keymaster","owner":"MorganConrad","description":"A metalsmith plugin to copy or preserve properties to new keys","archived":false,"fork":false,"pushed_at":"2023-01-07T07:27:49.000Z","size":182,"stargazers_count":3,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T12:29:18.792Z","etag":null,"topics":["metalsmith","metalsmith-plugin","properties"],"latest_commit_sha":null,"homepage":null,"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/MorganConrad.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":"2016-11-23T17:56:10.000Z","updated_at":"2021-11-24T19:36:52.000Z","dependencies_parsed_at":"2023-01-13T17:29:53.532Z","dependency_job_id":null,"html_url":"https://github.com/MorganConrad/metalsmith-keymaster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-keymaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-keymaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-keymaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MorganConrad%2Fmetalsmith-keymaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MorganConrad","download_url":"https://codeload.github.com/MorganConrad/metalsmith-keymaster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245104463,"owners_count":20561377,"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":["metalsmith","metalsmith-plugin","properties"],"created_at":"2024-10-11T13:25:44.490Z","updated_at":"2025-03-23T12:32:59.125Z","avatar_url":"https://github.com/MorganConrad.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://secure.travis-ci.org/MorganConrad/metalsmith-keymaster.png)](http://travis-ci.org/MorganConrad/metalsmith-keymaster)\r\n[![License](http://img.shields.io/badge/license-MIT-A31F34.svg)](https://github.com/MorganConrad/metalsmith-keymaster)\r\n[![NPM Downloads](http://img.shields.io/npm/dm/metalsmith-keymaster.svg)](https://www.npmjs.org/package/metalsmith-keymaster)\r\n[![Known Vulnerabilities](https://snyk.io/test/github/morganconrad/metalsmith-keymaster/badge.svg)](https://snyk.io/test/github/morganconrad/metalsmith-keymaster)\r\n[![Coverage Status](https://coveralls.io/repos/github/MorganConrad/metalsmith-keymaster/badge.svg)](https://coveralls.io/github/MorganConrad/metalsmith-keymaster)\r\n# metalsmith-keymaster\r\nA general-purpose [Metalsmith](http://www.metalsmith.io/) plugin to copy or add file properties, and save under new keys\r\n\r\n### Usage\r\n\r\nInstall as usual,  `npm install metalsmith-keymaster`.\r\n\r\nJavascript:  `use(keymaster({from: from, to: to, filter: filter}))`\r\n\r\nCLI: You'll lose a few options since it can't support functions or regular expressions.\r\n\r\n**from** is required and defines the value to be added/copied to the file object (here named **fileData**):\r\n - if `from` is '.', use `fileData.contents.toString()`.\r\n - if `from` is a String, use `fileData[from]` (shallow copy).\r\n - if `from` is a function, use `from(fileData, filePath, metalsmith)`.   \r\n\r\n**to** is required, the value derived from **from** will be placed there, _i.e._  `fileData[to] = value;`\r\n\r\n**filter** is optional and filters which files will be processed\r\n - if missing, process all files.\r\n - if a string or Regex, only process matching filePaths.\r\n - if a function, only process when filter(filePath, data, metalsmith) returns true.  \r\n _e.g._ If you want to use [multimatch](https://www.npmjs.com/package/multimatch), pass something like `function(filePath) { return multimatch([filePath], [\"blogs/**\", ...])[0] };`\r\n\r\n\r\n### Possible uses:\r\n\r\n##### You have existing markdown files and template files, but the names of some fields have changed over time and are incompatible.\r\n_e.g._, if the template now uses {{ userName }} instead of {{ name }}, but you don't want to redo all the YAML:\r\n\r\n`.use(keymaster({from: 'name', to: 'userName'}))`\r\n\r\n##### You want to preserve `.contents` before the next step processes them.\r\n_e.g._, to preserve the raw contents before markdown changes them, add the following before `use(markdown())`:\r\n\r\n    .use(keymaster({from: '.', to: 'raw'}))  // save contents\r\n       // then\r\n    .use(markdown())            // before markdown changes them\r\n\r\n\r\n##### You are lazy and want a quick-and-dirty plugin of your own.\r\nThis plugin serves as an excellent framework for writing your own plugin.  _e.g._, to quickly hack your own not-very-smart excerpt plugin:\r\n\r\n    .use(keymaster({from: function(data) {\r\n                      return data.contents.toString().substring(0, 50);\r\n                   },\r\n                   to: 'excerpt'}))\r\n\r\n\r\n### Notes, Todos, and Caveats\r\n\r\nIf you want a deep copy, pass in a function for from and do it there.\r\n\r\nCurrently only supports a _single_ level of keys, _i.e._ `from` can be `\"foo\"` but not `\"foo.bar\"`.  If you want deeper use the function version for from.\r\n\r\nTo copy multiple fields, just use keymaster multiple times, _e.g._\r\n\r\n    .use(keymaster({from: 'foo', to: 'bar'}))\r\n    .use(keymaster({from: 'abc', to: 'xyz'}))\r\n\r\n**Warning:** The code does not check if the property already exists, so be careful not to overwrite something you need!\r\n\r\n### More Examples\r\n\r\nInstead of using [metalsmith-filenames](https://www.npmjs.com/package/metalsmith-filenames), use\r\n\r\n    .use(keymaster({from: function(data, filePath) {\r\n                       return filePath;\r\n                  },\r\n                  to: 'yourKeyHere'}));\r\n\r\n   and you have the options to filter files or keymaster the key.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Fmetalsmith-keymaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorganconrad%2Fmetalsmith-keymaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganconrad%2Fmetalsmith-keymaster/lists"}