Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metalsmith/drafts
A metalsmith plugin to hide drafts.
https://github.com/metalsmith/drafts
drafts metalsmith metalsmith-plugin
Last synced: 3 days ago
JSON representation
A metalsmith plugin to hide drafts.
- Host: GitHub
- URL: https://github.com/metalsmith/drafts
- Owner: metalsmith
- License: mit
- Created: 2014-02-05T06:06:30.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2024-11-01T14:35:34.000Z (2 months ago)
- Last Synced: 2024-12-25T08:34:14.257Z (9 days ago)
- Topics: drafts, metalsmith, metalsmith-plugin
- Language: JavaScript
- Homepage:
- Size: 1.21 MB
- Stars: 35
- Watchers: 40
- Forks: 14
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @metalsmith/drafts
A metalsmith plugin to hide drafts. Metalsmith will not build a page that is marked as draft.
[![metalsmith: core plugin][metalsmith-badge]][metalsmith-url]
[![npm: version][npm-badge]][npm-url]
[![ci: build][ci-badge]][ci-url]
[![code coverage][codecov-badge]][codecov-url]
[![license: MIT][license-badge]][license-url]## Installation
NPM:
```bash
npm install @metalsmith/drafts
```Yarn:
```bash
yarn add @metalsmith/drafts
```## Usage
Pass the plugin with any options to `metalsmith.use`.
```js
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:
```yaml
---
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.
```js
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:
```js
import drafts from '@metalsmith/drafts'metalsmith.use(
drafts({
default: true
})
)
```### Debug
To enable debug logs, set the `DEBUG` environment variable to `@metalsmith/drafts*`:
```js
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:
```json
{
"plugins": [
{
"@metalsmith/drafts": {
"default": false
}
}
]
}
```## License
[MIT](LICENSE)
[npm-badge]: https://img.shields.io/npm/v/@metalsmith/drafts.svg
[npm-url]: https://www.npmjs.com/package/@metalsmith/drafts
[ci-badge]: https://github.com/metalsmith/drafts/actions/workflows/test.yml/badge.svg
[ci-url]: https://github.com/metalsmith/drafts/actions/workflows/test.yml
[metalsmith-badge]: https://img.shields.io/badge/metalsmith-core_plugin-green.svg?longCache=true
[metalsmith-url]: http://metalsmith.io
[codecov-badge]: https://img.shields.io/coveralls/github/metalsmith/drafts
[codecov-url]: https://coveralls.io/github/metalsmith/drafts
[license-badge]: https://img.shields.io/github/license/metalsmith/drafts
[license-url]: LICENSE