https://github.com/dpobel/metalsmith-filemetadata
Metalsmith plugin to add metadata on files based on a pattern
https://github.com/dpobel/metalsmith-filemetadata
metadata metalsmith metalsmith-plugin
Last synced: 5 months ago
JSON representation
Metalsmith plugin to add metadata on files based on a pattern
- Host: GitHub
- URL: https://github.com/dpobel/metalsmith-filemetadata
- Owner: dpobel
- License: mit
- Created: 2014-05-14T07:50:57.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2025-05-01T04:39:58.000Z (5 months ago)
- Last Synced: 2025-05-04T05:32:42.190Z (5 months ago)
- Topics: metadata, metalsmith, metalsmith-plugin
- Language: JavaScript
- Size: 937 KB
- Stars: 21
- Watchers: 3
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# metalsmith-filemetadata
A Metalsmith plugin to add metadata on files based on a pattern.

## Installation
This plugin requires Node.js 20 or later
$ npm install metalsmith-filemetadata
## JavaScript usage
```js
const fileMetadata = require("metalsmith-filemetadata");metalsmith.use(
fileMetadata([
{ pattern: "posts/*", metadata: { section: "blogs", type: "post" } },
{ pattern: "pages/*", metadata: { section: "content", type: "page" } },
]),
);
```The `pattern` property of each rule should be a valid
[minimatch](https://www.npmjs.org/package/minimatch) pattern. If the pattern
matches the file, the corresponding `metadata` are set on the file entry. For a
given file, all patterns are tested, so if several rules are matching, the latter
can override the previously applied rules.The `metadata` property can also be a function, to enable making global metadata available to files,
or setting file metadata defaults, e.g.:```js
{
pattern: "posts/*",
metadata: function(file, globalMetadata) {
return {
title: file.keywords || globalMetadata.keywords,
allPosts: globalMetadata.collections.posts
};
}
}
```Adding `preserve: true` to any rule will prevent overriding pre-defined values.
## CLI usage
```json
{
"plugins": {
"metalsmith-filemetadata": [
{
"pattern": "posts/*",
"metadata": { "section": "blogs", "type": "post" }
},
{
"pattern": "pages/*",
"metadata": { "section": "content", "type": "page" }
}
]
}
}
```## License
MIT