Table of Contents
Convert
exports
Converts the given field to an array, unless it is already an array
Parameters
patterns
string A file path or glob pattern to search for files to modifyfield
string The field you want to convertoptions
Object Configuration optionsoptions.ignore
string A file path or glob pattern to search for files not to modify. Defaults to “node_modules”.
Examples
var fmp = require("front-matter-manipulator")
fmp.convert("_posts/example-post.md", "categories")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md"
}
fmp.convert("_posts/**/*.md", "categories", options)
Drop
exports
Deletes the given fields from the front matter
Parameters
patterns
string A file path or glob pattern to search for files to modifyfields
string A space delimited list of fields you wish to dropoptions
Object Configuration optionsoptions.ignore
string A file path or glob pattern to search for files not to modify. Defaults to “node_modules”.options.exclude
string Exclude files that have a certain values. Formatted as a comma delimited list of key value pairs.options.include
string Only include files that have a certain values. Formatted as a comma delimited list of key value pairs.
Examples
var fmp = require("front-matter-manipulator")
fmp.drop("_posts/example-post.md", "categories tags")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md",
include: "layout=post",
exclude: "featured=true"
}
fmp.drop("**/*.md", "categories tags", options)
Values
exports
Retrieves all fields for one or more files
Parameters
patterns
string A file path or glob pattern to search for filesfields
string A space delimited list of fields to get values foroptions
Object Configuration options
Examples
var fmp = require("front-matter-manipulator")
fmp.values("_posts/example-post.md", "categories tags")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md"
}
fmp.values("**/*.md", "categories tags", options)
Returns Object values
Update
exports
Updates the given key value pair’s value
Parameters
patterns
string A file path or glob pattern to search for files to modifyfield
string The name of the field you wish to update-
replacement
**(stringreplacementCallback)** The new value of the field options
Object Configuration optionsoptions.ignore
string A file path or glob pattern to search for files not to modify. Defaults to “node_modules”.options.exclude
string Exclude files that have a certain values. Formatted as a comma delimited list of key value pairs.options.include
string Only include files that have a certain values. Formatted as a comma delimited list of key value pairs.
Examples
var fmp = require("front-matter-manipulator")
fmp.update("_posts/example-post.md", "draft", "true")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md",
include: "layout=post",
exclude: "featured=true"
}
fmp.rename("**/*.md", "draft", "true", options)
replacementCallback - Function to run to rename the field
Optional replacement function to be run for each match
Type: Function
Parameters
value
string The field’s current valuefield
string The current field permutationfilePath
string The current file’s path
Examples
var fmp = require("front-matter-manipulator")
function replacement(field, filePath) {
if (field.indexOf(0) > -1) { // Update if array index 0
replacement = "newKey"
}
}
fmp.rename("**/*.md", "categories", replacement, options)
Returns string replacement - The replacement value
Fields
exports
Retrieves all fields for one or more files
Parameters
patterns
string A file path or glob pattern to search for filesoptions
Object Configuration optionsoptions.ignore
string A file path or glob pattern to search for files not to modify. Defaults to “node_modules”.options.exclude
string Exclude files that have a certain values. Formatted as a comma delimited list of key value pairs.options.include
string Only include files that have a certain values. Formatted as a comma delimited list of key value pairs.options.outputFile
string path to a file where output should be savedoptions.outputstring
string output values as a space delimited string instead of JSON
Examples
var fmp = require("front-matter-manipulator")
fmp.fields("_posts/example-post.md")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md",
include: "layout=post",
exclude: "featured=true"
}
fmp.fields("**/*.md", options)
Returns Object fields
Rename
exports
Renames the given field
Parameters
patterns
string A file path or glob pattern to search for files to modifykey
-
replacement
**(stringreplacementCallback)** The replacement name for the field. options
Object Configuration optionsoptions.ignore
string A file path or glob pattern to search for files not to modify. Defaults to “node_modules”.options.exclude
string Exclude files that have a certain values. Formatted as a comma delimited list of key value pairs.options.include
string Only include files that have a certain values. Formatted as a comma delimited list of key value pairs.
field
string The name of the field you wish to rename
Examples
var fmp = require("front-matter-manipulator")
fmp.rename("_posts/example-post.md", "categories", "tags")
var fmp = require("front-matter-manipulator")
var options = {
ignore: "_posts/subdirectory/*.md",
include: "layout=post",
exclude: "featured=true"
}
fmp.rename("**/*.md", "categories", "tags", options)
replacementCallback - Function to run to rename the field
Optional replacement function to be run for each match
Type: Function
Parameters
Examples
var fmp = require("front-matter-manipulator")
function replacement(field, filePath) {
if (field.indexOf(0) > -1) { // Update if array index 0
replacement = "newKey"
}
}
fmp.rename("**/*.md", "categories", replacement, options)
Returns string replacement - The replacement field name