Metalsmith is the SSG I use to create the main yukinu site. In reality, Metalsmith is not strictly an SSG, but rather a generic framework for transforming files. Metalsmith is written in JavaScript and the codebase is quite small; most of the functionality comes from plugins.
Here is a basic Metalsmith example:
Code: Select all
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(markdown())
.build(function(err) {
if (err) throw err;
});
This code loads all of the files in
./src into memory, and converts the markdown content to html for each file with
.md extension using the
metalsmith-markdown plugin, changing the extension to
.html. Once all plugins have run, the files are written to
./build.
Writing plugins for Metalsmith is quite simple; You create a function with 3 arguments
(files, metalsmith, done), and register the function with a call to
.use(). Here is a basic plugin, it just loop through all the loaded files and transforms their contents:
Code: Select all
function(files, metalsmith, done) {
for (var i = 0; i < files.length; i++) {
var fileName = files[i];
var file = files[fileName];
var content = file.content;
// Transform content here.
file.content = content;
}
done();
}
My site is currently using ~30 plugins. Half of the plugins are from the NPM package repo, the other half are custom plugins that I use to, among other things, generate the feeds, modify html, generate redirects, and build the zine.
[url=https://web.archive.org/web/20210120061609/https://metalsmith.io/]Metalsmith[/url] is the SSG I use to create the main yukinu site. In reality, Metalsmith is not strictly an SSG, but rather a generic framework for transforming files. Metalsmith is written in JavaScript and the codebase is quite small; most of the functionality comes from plugins.
Here is a basic Metalsmith example:
[code]
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.use(markdown())
.build(function(err) {
if (err) throw err;
});
[/code]
This code loads all of the files in [b]./src[/b] into memory, and converts the markdown content to html for each file with [b].md[/b] extension using the [b]metalsmith-markdown[/b] plugin, changing the extension to [b].html[/b]. Once all plugins have run, the files are written to [b]./build[/b].
Writing plugins for Metalsmith is quite simple; You create a function with 3 arguments [b](files, metalsmith, done)[/b], and register the function with a call to [b].use()[/b]. Here is a basic plugin, it just loop through all the loaded files and transforms their contents:
[code]
function(files, metalsmith, done) {
for (var i = 0; i < files.length; i++) {
var fileName = files[i];
var file = files[fileName];
var content = file.content;
// Transform content here.
file.content = content;
}
done();
}
[/code]
My site is currently using ~30 plugins. Half of the plugins are from the NPM package repo, the other half are custom plugins that I use to, among other things, generate the feeds, modify html, generate redirects, and build the zine.