Skip to content

metalsmith/drafts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

735855c · Nov 1, 2024

History

59 Commits
Nov 1, 2024
Dec 7, 2022
Nov 1, 2024
Nov 1, 2024
Sep 11, 2018
Dec 21, 2021
Aug 22, 2023
Aug 22, 2023
Dec 21, 2021
Jul 28, 2022
Dec 7, 2022
Dec 21, 2021
Dec 7, 2022
Nov 1, 2024
Nov 1, 2024
Nov 1, 2024

Repository files navigation

@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