Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
metalsmith-matters
Advanced tools
A Metalsmith plugin to read file metadata from frontmatter. Supports all frontmatter formats supported by the gray-matter library (including YAML, JSON, TOML, CSON, and more).
"But wait!" you say. "Doesn't Metalsmith already have frontmatter parsing built-in"? Well, yes. For now anyway. This plugin is an attempt to extract that functionality out of the Metalsmith core. Eventually the goal is to have frontmatter parsing removed from the Metalsmith core entirely in favor of this plugin or a similar one (see segmentio/metalsmith#157).
Even in the absence of that change though, this plugin has several key
advantages over the built-in frontmatter parsing in Metalsmith. Firstly, it's
composable with other plugins. For example, you could use it with
metalsmith-branch
to turn on
frontmatter parsing for only a subset of files, or you could place it after
metalsmith-s3
in the plugin list
so that it parses frontmatter in downloaded files.
Secondly, this plugin provides a way to pass options to the underlying frontmatter parsing library, gray-matter. This allows you to do things like change the delimiter used to separate frontmatter from the rest of the file, or set TOML as the default frontmatter format.
Thirdly, this plugin provides an additional feature allowing parsed frontmatter
to be automatically namespaced under a single key (e.g. page.keys
instead of
keys
).
These are all things you can't do with Metalsmith's built-in frontmatter parsing.
npm install --save metalsmith-matters
After installing metalsmith-matters, simply add the metalsmith-matters
key to
the plugins in your metalsmith.json
file. Be sure to include it before any
plugins which need to use the metadata in your frontmatter, or which expect as
input files with no frontmatter header. Generally speaking, this means that
metalsmith-matters should be the first plugin in the list.
{
"frontmatter": false, // Disable built-in frontmatter parsing (recommended)
"plugins": {
"metalsmith-matters": {
// Options
}
// Other plugins...
}
}
After installing metalsmith-matters, you can require metalsmith-matters
in
your code, then call the exported value to initialize the plugin and pass the
result to Metalsmith.use
(just as you would with any other Metalsmith plugin).
Again, be sure to use metalsmith-matters before any plugins which need to use
the metadata defined your frontmatter, or which expect as input files with no
frontmatter header. Generally speaking, this means that metalsmith-matters
should be the first plugin in the list.
var frontmatter = require('metalsmith-matters');
Metalsmith(__dirname)
.frontmatter(false) // Disable built-in frontmatter parsing (recommended)
.use(frontmatter({
// Options
}))
.use(/* Other plugins... */)
.build(function(err) {
if (err) throw err;
});
namespace
Type: string
Default: undefined
Namespace all parsed data under a single key.
Your frontmatter:
---
title: My title
author: Joe Writer
---
In the JavaScript:
// new Metalsmith…
.use(frontmatter({ namespace: 'page' }))
// …build()
Now in your HTML, you can access the metadata like this (example with Handlebars):
<h1>{{ page.title }}</h1>
<p>Author: {{ page.author }}</p>
metalsmith-matters also supports all the options supported by
gray-matter
,
metalsmith-matters' underlying frontmatter parsing library (it's the same one
used by the Metalsmith core). These include:
parser
eval
lang
delims
For details on how to use these options, see the
documentation for gray-matter
.
FAQs
A Metalsmith plugin to read file metadata from frontmatter
The npm package metalsmith-matters receives a total of 2 weekly downloads. As such, metalsmith-matters popularity was classified as not popular.
We found that metalsmith-matters demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.