在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):metalsmith/metalsmith开源软件地址(OpenSource Url):https://github.com/metalsmith/metalsmith开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):Metalsmith
In Metalsmith, all of the logic is handled by plugins. You simply chain them together. Here's what the simplest blog looks like: const Metalsmith = require('metalsmith')
const layouts = require('@metalsmith/layouts')
const markdown = require('@metalsmith/markdown')
Metalsmith(__dirname)
.use(markdown())
.use(layouts())
.build(function (err) {
if (err) throw err
console.log('Build finished!')
}) InstallationNPM:
Yarn:
QuickstartWhat if you want to get fancier by hiding unfinished drafts, grouping posts in collections, and using custom permalinks? Just add plugins... const Metalsmith = require('metalsmith')
const collections = require('@metalsmith/collections')
const layouts = require('@metalsmith/layouts')
const markdown = require('@metalsmith/markdown')
const permalinks = require('@metalsmith/permalinks')
Metalsmith(__dirname)
.source('./src')
.destination('./build')
.clean(true)
.frontmatter({
excerpt: true
})
.env({
NAME: process.env.NODE_ENV,
DEBUG: '@metalsmith/*',
DEBUG_LOG: 'metalsmith.log'
})
.metadata({
sitename: 'My Static Site & Blog',
siteurl: 'https://example.com/',
description: "It's about saying »Hello« to the world.",
generatorname: 'Metalsmith',
generatorurl: 'https://metalsmith.io/'
})
.use(
collections({
posts: 'posts/*.md'
})
)
.use(markdown())
.use(
permalinks({
relative: false
})
)
.use(layouts())
.build(function (err) {
if (err) throw err
}) How does it work?Metalsmith works in three simple steps:
Each plugin is invoked with the contents of the source directory, and each file can contain YAML front-matter that will be attached as metadata, so a simple file like...
...would be parsed into...
...which any of the plugins can then manipulate however they want. Writing plugins is incredibly simple, just take a look at the example drafts plugin. Of course they can get a lot more complicated too. That's what makes Metalsmith powerful; the plugins can do anything you want! PluginsA Metalsmith plugin is a function that is passed the file list, the metalsmith instance, and a done callback. It is often wrapped in a plugin initializer that accepts configuration options. Check out the official plugin registry at: https://metalsmith.io/plugins. APICheck out the full API reference at: https://metalsmith.io/api. CLIIn addition to a simple Javascript API, the Metalsmith CLI can read configuration from a
{
"source": "src",
"destination": "build",
"clean": true,
"metadata": {
"sitename": "My Static Site & Blog",
"siteurl": "https://example.com/",
"description": "It's about saying »Hello« to the world.",
"generatorname": "Metalsmith",
"generatorurl": "https://metalsmith.io/"
},
"plugins": [
{ "@metalsmith/drafts": true },
{ "@metalsmith/collections": { "posts": "posts/*.md" } },
{ "@metalsmith/markdown": true },
{ "@metalsmith/permalinks": "posts/:title" },
{ "@metalsmith/layouts": true }
]
} Then run: metalsmith
# Metalsmith · reading configuration from: /path/to/metalsmith.json
# Metalsmith · successfully built to: /path/to/build Options recognised by Local pluginsIf you want to use a custom plugin, but feel like it's too domain-specific to be published to the world, you can include plugins as local npm modules: (simply use a relative path from your root directory) {
"plugins": [{ "./lib/metalsmith/plugin.js": true }]
} The secret...We often refer to Metalsmith as a "static site generator", but it's a lot more than that. Since everything is a plugin, the core library is just an abstraction for manipulating a directory of files. Which means you could just as easily use it to make...
Resources
TroubleshootingUse debug to debug your build with Node Version RequirementsFuture Metalsmith releases will at least support the oldest supported Node LTS versions. Metalsmith 2.5.x supports NodeJS versions 12 and higher. Compatibility & support policyMetalsmith is supported on all common operating systems (Windows, Linux, Mac). Metalsmith releases adhere to semver (semantic versioning) with 2 minor gray-area exceptions for what could be considered breaking changes:
CreditsSpecial thanks to Ian Storm Taylor, Andrew Meyer, Dominic Barnes, Andrew Goodricke, Ismay Wolff, Kevin Van Lierde and others for their contributions! License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论