Détail du package

@metalsmith/drafts

metalsmith450MIT1.3.0

A metalsmith plugin to hide drafts.

drafts, metalsmith, metalsmith-plugin, static-site

readme

@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

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

v1.3.0

  • Drops support for metalsmith < 2.5.0 0f3dc82
  • Adds metalsmith.debug logs, removes setImmediate b5a11b3
  • Adds Typescript support b5d43c7
  • Renames default export to draft for better intellisense 4dd20fc

v1.2.0

6 August 2022

  • Added conditional draft use in readme file #14
  • Support dual bundle ESM/CJS c26f5f3
  • Feature: accept single bool param to include/omit drafts from the output 0183e74
  • Add Typescript types & option JSdocs 5e97ec2
  • Add example to JSdoc 9427720
  • Drop support for Node < 12 fa8a498

v1.1.1

21 December 2021

  • Align core plugin setup, add test, run prettier 29b03ff

1.1.0 - 2021-07-13

  • Finalize move to @metalsmith/drafts
  • Dropped support for Node < 10
  • Added limited JSDoc support
  • Added LICENSE file

1.0.0 - 2019-10-30

Previous

0.1.0 - December 15, 2015

  • Added option defaults, defining what the default value for draft should be if not defined.

0.0.1 - February 4, 2013


:sparkles: