1. @metalsmith/drafts
A metalsmith plugin to hide drafts.
@metalsmith/drafts
Package: @metalsmith/drafts
Created by: metalsmith
Last modified: Tue, 15 Aug 2023 16:41:43 GMT
Version: 1.3.0
License: MIT
Downloads: 233
Repository: https://github.com/metalsmith/drafts

Install

npm install @metalsmith/drafts
yarn add @metalsmith/drafts

@metalsmith/drafts

A metalsmith plugin to hide drafts. Metalsmith will not build a page that is marked as draft.

metalsmith: core plugin
npm: version
ci: build
code coverage
license: MIT

Installation

NPM:

 npm install @metalsmith/drafts

Yarn:

 yarn add @metalsmith/drafts

Usage

Pass the plugin with any options to metalsmith.use.

 import drafts from '@metalsmith/drafts'

metalsmith.use(drafts()) // same as { include: false }
metalsmith.use(drafts(true)) // same as { include: true }
metalsmith.use(drafts({ default: false, include: false })) // same as default

Add draft: true to your files' YAML front-matter to mark them as drafts:

 ---
title: My post
draft: true
---

To build pages that are marked as draft during development, you can use the Node environment and include the draft page in the build accordingly.

 const inDevelopment = process.env.NODE_ENV === 'development'

metalsmith.use(drafts(inDevelopment))

Default value for draft

You can instruct @metalsmith/drafts to mark files as draft by default if they don't have a draft property in their front-matter:

 import drafts from '@metalsmith/drafts'

metalsmith.use(
  drafts({
    default: true
  })
)

Debug

To enable debug logs, set the DEBUG environment variable to @metalsmith/drafts*:

 metalsmith.env('DEBUG', '@metalsmith/drafts*')

Alternatively you can set DEBUG to @metalsmith/* to debug all Metalsmith core plugins.

CLI Usage

To use this plugin with the Metalsmith CLI, add @metalsmith/drafts to the plugins key in your metalsmith.json file:

 {
  "plugins": [
    {
      "@metalsmith/drafts": {
        "default": false
      }
    }
  ]
}

License

MIT

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code