{"id":20603355,"url":"https://github.com/metalsmith/metadata","last_synced_at":"2025-04-15T02:01:07.868Z","repository":{"id":14767692,"uuid":"17489153","full_name":"metalsmith/metadata","owner":"metalsmith","description":"A metalsmith plugin to load global metadata from files.","archived":false,"fork":false,"pushed_at":"2023-07-23T17:50:43.000Z","size":1332,"stargazers_count":41,"open_issues_count":3,"forks_count":19,"subscribers_count":40,"default_branch":"main","last_synced_at":"2024-10-30T00:10:25.474Z","etag":null,"topics":["metadata","metalsmith","metalsmith-plugin"],"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/metalsmith.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-06T19:09:17.000Z","updated_at":"2023-08-25T09:45:01.000Z","dependencies_parsed_at":"2024-06-18T22:35:20.895Z","dependency_job_id":"4bf75dbf-c9ab-42a8-9008-32675159a9e6","html_url":"https://github.com/metalsmith/metadata","commit_stats":{"total_commits":74,"total_committers":9,"mean_commits":8.222222222222221,"dds":0.5540540540540541,"last_synced_commit":"6cbf8ede60b29e17e9553264e8569281373eb089"},"previous_names":["segmentio/metalsmith-metadata"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metalsmith%2Fmetadata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metalsmith%2Fmetadata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metalsmith%2Fmetadata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metalsmith%2Fmetadata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metalsmith","download_url":"https://codeload.github.com/metalsmith/metadata/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991546,"owners_count":21194894,"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":["metadata","metalsmith","metalsmith-plugin"],"created_at":"2024-11-16T09:17:02.508Z","updated_at":"2025-04-15T02:01:07.837Z","avatar_url":"https://github.com/metalsmith.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @metalsmith/metadata\n\nA metalsmith plugin to load global metadata from files and directories.\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: MIT][license-badge]][license-url]\n\n- Reads, parses and merges data files into global metadata and removes them from the build (when applicable).\n- Supports JSON, YAML and TOML files. [TOML parser](https://www.npmjs.com/package/toml) needs to be installed separately.\n- Supports dot-notated metadata keypath targets as option keys, eg `{'config.nav': 'src/config/nav.yml'}`\n\n## Installation\n\nNPM:\n\n```bash\nnpm install @metalsmith/metadata\n```\n\nYarn:\n\n```bash\nyarn add @metalsmith/metadata\n```\n\n## Usage\n\nPass the options to `Metalsmith#use`. The options object is in the format `{ 'metadata.key': 'path/to/(file.ext|dir)' }`. Relative file/directory paths are resolved to `metalsmith.directory()`. Directory option keys will include direct children of the directory, see [Mapping nested metadata directories](#mapping-nested-metadata-directories) for creating nested directory structures.\n\n```js\nimport Metalsmith from 'metalsmith'\nimport metadata from '@metalsmith/metadata'\n\nconst __dirname = dirname(new URL(import.meta.url).pathname)\n\nMetalsmith(__dirname)\n  .use(\n    metadata({\n      // in-source JSON file\n      jsonFile: 'src/data/a-json-file.json',\n      // out-of-source YAML file at nested keypath\n      'nested.yamlFile': 'some-directory/a-yaml-file.yaml',\n      // out-of-source directory\n      aDirectory: 'some-directory/a-directory'\n    })\n  )\n  .build((err) =\u003e {\n    console.log(metalsmith.metadata())\n    // logs { jsonFile: {...}, nested: { yamlFile: {...}}, aDirectory: {...} }\n  })\n```\n\nFiles inside `metalsmith.source()` will be considered metadata and thus removed from the build output.\n\n### Plugin order\n\nTypically, you want to use this plugin somewhere at the start of the chain, before any rendering plugins run, like [@metalsmith/layouts](https://github.com/metalsmith/layouts) or [@metalsmith/in-place](https://github.com/metalsmith/in-place).\n\n### Merging metadata files into objects\n\nYou can merge metadata files into objects by making the root of the data file an object. For example, given the following 2 files:\n\n\u003ctable\u003e\n  \u003ctr\u003e\u003cth\u003e\u003ccode\u003esrc/themes/red.json\u003c/code\u003e\u003c/th\u003e\u003cth\u003e\u003ccode\u003esrc/themes/blue.json\u003c/code\u003e\u003c/th\u003e\u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003cpre\u003e{\n  \"red\": {\n    \"primary-color\": \"#FF0000\"\n  }\n}\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003cpre\u003e{\n  \"blue\": {\n    \"primary-color\": \"#00FF00\"\n  }\n}\u003c/pre\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nwith a usage like `metalsmith.use(metadata({ themes: 'src/themes' }))`, `metalsmith.metadata().themes` will be `{ red: {\"primary-color\": #00FF00\"}, blue: {\"primary-color\": \"#00FF00\"}}`.\n\n### Merging metadata files into arrays\n\nYou can merge metadata files into an array by making the root of the data file an array. For example, given the following 2 files:\n\n\u003ctable\u003e\n  \u003ctr\u003e\u003cth\u003e\u003ccode\u003esrc/themes/red.json\u003c/code\u003e\u003c/th\u003e\u003cth\u003e\u003ccode\u003esrc/themes/blue.json\u003c/code\u003e\u003c/th\u003e\u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003cpre\u003e[\n  {\n    \"primary-color\": \"#FF0000\"\n  }\n]\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n      \u003cpre\u003e[\n  {\n    \"primary-color\": \"#00FF00\"\n  }\n]\u003c/pre\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nwith a usage like `metalsmith.use(metadata({ themes: 'src/themes' }))`, `metalsmith.metadata().themes` will be `[{\"primary-color\": #00FF00\"}, {\"primary-color\": \"#00FF00\"}]`.\n\n### Mapping nested metadata directories\n\nYou can map nested metadata directories by specifying multiple options:\n\n```js\nmetalsmith.use(\n  metadata({\n    config: 'src/config',\n    'config.theme': 'src/config/theme',\n    'config.theme.summer': 'src/config/theme/summer',\n    'config.constants': 'src/config/constants.yaml'\n  })\n)\n```\n\nThe resulting metadata will have a structure like:\n\n```js\n{\n  ...otherMetadata,\n  config: {\n    ...metadata_from_config_dir\n    theme: {\n      ...metadata_from_config_theme_dir\n      summer: { ...metadata_from_config_theme_summer_dir }\n    }\n  },\n  constants: {\n    ...metadata_from_config_constants_file\n  }\n}\n```\n\n## Debug\n\nTo enable debug logs, set the `DEBUG` environment variable to `@metalsmith/metadata`:\n\n```js\nmetalsmith.env('DEBUG', '@metalsmith/metadata*')\n```\n\n## CLI Usage\n\nTo use this plugin with the Metalsmith CLI,add the `@metalsmith/metadata` key to your `metalsmith.json` plugins. Each key in the dictionary of options will be the key for the global metadata object, like so:\n\n```json\n{\n  \"plugins\": {\n    \"@metalsmith/metadata\": {\n      \"authors\": \"src/authors.json\",\n      \"categories\": \"src/categories.yaml\",\n      \"customers\": \"external_data/customers\"\n    }\n  }\n}\n```\n\n## License\n\n[MIT][license-url]\n\n[npm-badge]: https://img.shields.io/npm/v/@metalsmith/metadata.svg\n[npm-url]: https://www.npmjs.com/package/@metalsmith/metadata\n[ci-badge]: https://github.com/metalsmith/metalsmith/actions/workflows/test.yml/badge.svg\n[ci-url]: https://github.com/metalsmith/metalsmith/actions/workflows/test.yml\n[metalsmith-badge]: https://img.shields.io/badge/metalsmith-core_plugin-green.svg?longCache=true\n[metalsmith-url]: https://metalsmith.io\n[codecov-badge]: https://img.shields.io/coveralls/github/metalsmith/metadata\n[codecov-url]: https://coveralls.io/github/metalsmith/metadata\n[license-badge]: https://img.shields.io/github/license/metalsmith/metadata\n[license-url]: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetalsmith%2Fmetadata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetalsmith%2Fmetadata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetalsmith%2Fmetadata/lists"}