# metalsmith-project-images

> A metalsmith plugin that scan all images in subfolders and add it to metadata.

Latest version **1.1.2** (published 2017-02-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install metalsmith-project-images
pnpm add metalsmith-project-images
yarn add metalsmith-project-images
bun add metalsmith-project-images
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2017-02-10 |
| First published | 2015-11-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+13 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Robin Houdmeyers |
| Maintainers | hoetmaaiers |
| Keywords | metalsmith, images, project, scan |

## Links

- npm: https://www.npmjs.com/package/metalsmith-project-images
- Repository: https://github.com/hoetmaaiers/metalsmith-project-images
- Homepage: https://github.com/hoetmaaiers/metalsmith-project-images#readme
- Issues: https://github.com/hoetmaaiers/metalsmith-project-images/issues
- npm.io page: https://npm.io/package/metalsmith-project-images

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^0.7.4
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [minimatch](https://npm.io/package/minimatch.md) ^0.2.14

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2017-02-10
- 1.1.1 — 2016-11-18
- 1.1.0 — 2016-10-03
- 1.0.1 — 2015-11-11
- 1.0.0 — 2015-11-11
- 0.0.1 — 2015-11-03

## README

# Metalsmith Project Images

[![npm version](https://badge.fury.io/js/metalsmith-project-images.svg)](https://badge.fury.io/js/metalsmith-project-images)
[![Build Status](https://travis-ci.org/hoetmaaiers/metalsmith-project-images.svg?branch=master)](https://travis-ci.org/hoetmaaiers/metalsmith-project-images)

A metalsmith plugin that can scan all images in subfolders and add it to a files metadata.

## The idea

Let's say we want to show all images per project. Assume we have a folder structure like below:

```
projects/
|-- hello/
|	|-- hello.md
|	|-- images/
|		|-- image-1.png
|		|-- image-2.png
|-- world/
	|-- world.md
	|-- images/
		|-- beautiful-world.png
		|-- skyfall.jpg
```

This would be possible with the following configuration:

```
var Metalsmith = require('metalsmith');
var images = require('metalsmith-project-images');

var metalsmith = new Metalsmith(__dirname)
  .use(images({
    pattern: 'projects/**/*.md'
  })
  .build();
```

Combined with the [collections metalsmith plugin](https://github.com/segmentio/metalsmith-collections), we can loop over each collection and have access to the images for each project.

```javascript
{{#each project in projects}}
	<h1>{{project.title}}</h1>
	<ul>
		{{#each image in project.images}}
			<li><img src="{{image}}"/></li>
		{{/each}}
	</ul>
{{/each}}
```

## Install

```sh
npm install --save metalsmith-project-images
```

## Quick usage

```js
var Metalsmith = require('metalsmith');
var images = require('metalsmith-project-images');

var metalsmith = new Metalsmith(__dirname)
  .use(images({
  	pattern: 'projects/**/*'
  }))
  .build();
```

## Api

```javascript
var metalsmith = new Metalsmith(__dirname);

var defaultOptions = {
	authorizedExts: ['jpg', 'jpeg', 'svg', 'png', 'gif', 'JPG', 'JPEG', 'SVG', 'PNG', 'GIF'],
	pattern: '',
	imagesDirectory: 'images',
};

metalsmith.use(images(defaultOptions))
// or passing in no options will use the defaults
metalsmith.use(images())
```

##### One options object
```javascript
var options = {
	authorizedExts: ['gif']
	pattern: 'memes/**/*.md',
	imagesDirectory: 'giphys',
}
```

##### Multiple options objects
It is possible to define multiple configuration objects.

```javascript
var options = [
	// only add gif's to memes ;)
	{
		authorizedExts: ['gif']
		pattern: 'memes/**/*.md',
		imagesDirectory: 'giphys',
	},

	// add all images to its matching project
	{
		pattern: 'projects/**/*.md',
	},

	// add all images to its matching project with a different metadata key
	{
		pattern: 'projects/**/*.md',
        imagesDirectory: 'maps',
        imagesKey: 'maps',
	},
]
```

### Options

| name | default | description |
|:------------- |:-------------|:--|
| pattern | `**/*.md` | pattern for files to scan images for |
| authorizedExts | jpg, jpeg, svg, png, gif, JPG, JPEG, SVG, PNG, GIF | allowed image extensions |
| imagesDirectory | `images` | directory inside the pattern to look for images to add |
| imagesKey | `images` | name of metadata key to hold images collection |

Note:

- If `imagesDirectory` does not exist, it is skipped and no collection will be created

## License
MIT

---
_Source: https://npm.io/package/metalsmith-project-images · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
