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-layouts
Advanced tools
A metalsmith plugin for layouts
This plugin allows you to apply layouts to your source files. It passes your source files to the selected layout as contents
and renders the result with the templating engine of your choice. You can use any templating engine supported by consolidate.js.
$ npm install metalsmith-layouts
Configuration in metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "handlebars"
}
}
}
Source file src/index.html
:
---
layout: layout.html
title: The title
---
<p>The contents</p>
Layout layouts/layout.html
:
<!doctype html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{{contents}}}
</body>
</html>
Results in build/index.html
:
<!doctype html>
<html>
<head>
<title>The title</title>
</head>
<body>
<p>The contents</p>
</body>
</html>
This is a very basic example. For a ready-to-use boilerplate that utilizes this plugin see metalsmith-boilerplates.
You can pass options to metalsmith-layouts
with the Javascript API or CLI. The options are:
The engine that will render your layouts. Metalsmith-layouts uses consolidate.js to render templating syntax, so any engine supported by consolidate.js can be used. Don't forget to install the templating engine separately. So this metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "swig"
}
}
}
Will render your layouts with swig.
The default layout to use. Can be overridden with the layout
key in each file's YAML frontmatter. If a default
layout hasn't been specified, metalsmith-layouts
will only process files with a layout
option in their front-matter. Don't forget to specify the file extension. So this metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "swig",
"default": "default.html"
}
}
}
Will apply the default.html
layout to all files, unless specified otherwise in the frontmatter.
The directory where metalsmith-layouts
looks for the layouts. By default this is layouts
. So this metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "swig",
"directory": "templates"
}
}
}
Will look for layouts in the templates
directory, instead of in layouts
.
The directory where metalsmith-layouts
looks for partials. Each partial is named by removing the file extension from its path (relative to the partials directory), so make sure to avoid duplicates. So this metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "handlebars",
"partials": "partials"
}
}
}
Would mean that a partial at partials/nav.html
can be used in layouts as {{> nav }}
, and partials/nested/footer.html
can be used as {{> nested/footer }}
. Note that passing anything but a string to the partials
option will pass the option on to consolidate.
Only files that match this pattern will be processed. So this metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "swig",
"pattern": "*.md"
}
}
}
Would only process files that have the .md
extension.
Any unrecognised options will be passed on to consolidate.js. You can use this, for example, to disable caching by passing cache: false
. See the consolidate.js documentation for all options supported by consolidate.
This plugin is a fork of the now deprecated metalsmith-templates. Splitting up metalsmith-templates
into two plugins was suggested by Ian Storm Taylor. The results are:
MIT
1.4.4 - January 27, 2016
FAQs
A metalsmith plugin for layouts.
The npm package metalsmith-layouts receives a total of 2,674 weekly downloads. As such, metalsmith-layouts popularity was classified as popular.
We found that metalsmith-layouts 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.