@hutools/drafts
v1.0.1
Published
A hutools plugin to hide drafts.
Downloads
4
Maintainers
Readme
@hutools/drafts
A hutools plugin to hide drafts. Hutools will not build a page that is marked as draft.
Installation
NPM:
npm install @hutools/drafts
Yarn:
yarn add @hutools/drafts
Usage
Pass the plugin with any options to Hutools.use
.
const drafts = require('@hutools/drafts')
hutools.use(drafts())
hutools.use(drafts({ default: 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, use the hutools-if plugin to check the node environment and include the draft page in the build accordingly.
const when = require('hutools-if');
...
const isProduction = process.env.NODE_ENV === 'production';
...
.use(when(isProduction, drafts()))
Default value for draft
You can instruct @hutools/drafts
to mark files as draft
by default if they don't have a draft
property in their front-matter:
const drafts = require('@hutools/drafts')
hutools.use(
drafts({
default: true
})
)
CLI Usage
To use this plugin with the Hutools CLI, add @hutools/drafts
to the plugins
key in your hutools.json
file:
{
"plugins": [
{
"@hutools/drafts": {
"default": false
}
}
]
}