Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metalsmith-drafts

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metalsmith-drafts - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.editorconfig

3

History.md

@@ -0,1 +1,4 @@

0.1.0 - December 15, 2015
------------------------
- Added option `defaults`, defining what the default value for `draft` should be if not defined.

@@ -2,0 +5,0 @@ 0.0.1 - February 4, 2013

@@ -1,2 +0,1 @@

/**

@@ -14,10 +13,35 @@ * Expose `plugin`.

function plugin(){
return function(files, metalsmith, done){
function plugin(opts) {
var draftFallback =
opts && strictBool(opts.default) !== undefined
? strictBool(opts.default)
: false;
function strictBool(val) {
if (typeof val == 'boolean') {
return val;
}
if (typeof val == 'string') {
if (val.toLowerCase() === 'true') {
return true;
} else if (val.toLowerCase() === 'false') {
return false;
}
}
return undefined;
}
return function(files, metalsmith, done) {
setImmediate(done);
Object.keys(files).forEach(function(file){
Object.keys(files).forEach(function(file) {
var data = files[file];
if (data.draft) delete files[file];
var isDraft =
strictBool(data.draft) !== undefined
? strictBool(data.draft)
: draftFallback;
if (isDraft) {
delete files[file];
}
});
};
}
}

@@ -5,10 +5,24 @@ {

"repository": "git://github.com/segmentio/metalsmith-drafts.git",
"version": "0.0.1",
"version": "0.1.0",
"license": "MIT",
"main": "lib/index.js",
"scripts": {
"pretest": "npm run lint",
"test": "mocha --reporter spec",
"lint": "eslint --cache --fix .",
"dev": "nodemon --exec 'npm test'",
"preversion": "npm test",
"postversion": "git push && git push --tags && npm publish"
},
"devDependencies": {
"mocha": "1.x",
"metalsmith": "0.0.0",
"assert-dir-equal": "0.0.1"
"assert-dir-equal": "^1.1.0",
"del": "^3.0.0",
"eslint": "^5.5.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-prettier": "^2.6.2",
"metalsmith": "^2.3.0",
"mocha": "^5.2.0",
"nodemon": "^1.18.4",
"prettier": "^1.14.2"
}
}

@@ -0,6 +1,11 @@

# Metalsmith Drafts
# metalsmith-drafts
[![npm version][npm-badge]][npm-url]
[![code style: prettier][prettier-badge]][prettier-url]
[![metalsmith: plugin][metalsmith-badge]][metalsmith-url]
A metalsmith plugin to hide drafts.
[![Build Status][travis-badge]][travis-url]
A metalsmith plugin to hide drafts.
## Installation

@@ -22,5 +27,18 @@

Then in your files YAML front-matter add `draft: true`.
In case you want to force all files to be set to `draft: true`, use the following plugin-option:
```json
{
"plugins": {
"metalsmith-drafts": {
"default": true
}
}
}
```
## Javascript Usage
Pass the plugin to `Metalsmith#use`:
Pass the plugin to `Metalsmith#use`, like so:

@@ -33,4 +51,27 @@ ```js

Then in your files YAML front-matter add `draft: true`.
### Default value for `draft`
If you want to define a default value for `draft` (in case they are not definied in the YAML front-matter, then use the plugin option `default`:
```js
var drafts = require('metalsmith-drafts');
metalsmith.use(drafts( {
default: true
}));
```
## License
MIT
MIT
[npm-badge]: https://img.shields.io/npm/v/metalsmith-drafts.svg
[npm-url]: https://www.npmjs.com/package/metalsmith-drafts
[prettier-badge]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
[prettier-url]: https://github.com/prettier/prettier
[metalsmith-badge]: https://img.shields.io/badge/metalsmith-plugin-green.svg?longCache=true
[metalsmith-url]: http://metalsmith.io
[travis-badge]: https://travis-ci.org/segmentio/metalsmith-drafts.svg?branch=master
[travis-url]: https://travis-ci.org/segmentio/metalsmith-drafts

@@ -0,16 +1,57 @@

/* eslint-env mocha */
const equal = require('assert-dir-equal');
const Metalsmith = require('metalsmith');
const drafts = require('..');
const del = require('del');
var equal = require('assert-dir-equal');
var Metalsmith = require('metalsmith');
var drafts = require('..');
describe('metalsmith-drafts', function() {
function cleanUp(done) {
del('test/**/build/').then(function() {
done();
});
}
describe('metalsmith-drafts', function(){
it('should remove drafts from output', function(done){
Metalsmith('test/fixture')
beforeEach(function(done) {
cleanUp(done);
});
afterEach(function(done) {
//cleanUp( done );
done();
});
it('should remove drafts from output (default behavior / ensure backwards-compatibility)', function(done) {
Metalsmith('test/fixture/default')
.use(drafts())
.build(function(err){
.build(function(err) {
if (err) return done(err);
equal('test/fixture/expected', 'test/fixture/build');
equal('test/fixture/default/expected', 'test/fixture/default/build');
done();
});
});
});
it('should remove drafts from output (defaults=true)', function(done) {
Metalsmith('test/fixture/defaults-to-true')
.use(drafts({ default: true }))
.build(function(err) {
if (err) return done(err);
equal(
'test/fixture/defaults-to-true/expected',
'test/fixture/defaults-to-true/build'
);
done();
});
});
it('should remove drafts from output (defaults=false)', function(done) {
Metalsmith('test/fixture/defaults-to-false')
.use(drafts({ default: false }))
.build(function(err) {
if (err) return done(err);
equal(
'test/fixture/defaults-to-false/expected',
'test/fixture/defaults-to-false/build'
);
done();
});
});
});
.npmignore
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc