# md-directory

> Convert a directory of Markdown files to HTML

Latest version **1.1.1** (published 2020-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install md-directory
pnpm add md-directory
yarn add md-directory
bun add md-directory
```

## 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.1 |
| Published | 2020-04-16 |
| First published | 2017-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Seth Thompson |
| Maintainers | s3ththompson |
| Keywords | markdown, browserify, inline, convert, frontmatter, brfs |

## Links

- npm: https://www.npmjs.com/package/md-directory
- Repository: https://github.com/s3ththompson/md-directory
- Homepage: https://github.com/s3ththompson/md-directory#readme
- Issues: https://github.com/s3ththompson/md-directory/issues
- npm.io page: https://npm.io/package/md-directory

## Dependencies (7)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [defaults](https://npm.io/package/defaults.md) ^1.0.3
- [through2](https://npm.io/package/through2.md) ^3.0.1
- [commonmark](https://npm.io/package/commonmark.md) ^0.29.1
- [gray-matter](https://npm.io/package/gray-matter.md) ^4.0.2
- [static-module](https://npm.io/package/static-module.md) ^3.0.3
- [read-directory](https://npm.io/package/read-directory.md) ^3.0.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2020-04-16
- 1.1.0 — 2020-04-16
- 1.0.2 — 2019-07-14
- 1.0.1 — 2019-07-10
- 0.1.2 — 2017-09-10
- 0.1.1 — 2017-06-19
- 0.1.0 — 2017-06-19
- 0.0.1 — 2017-06-19

## README

# md-directory

[![npm version](https://img.shields.io/npm/v/md-directory.svg?style=flat-square)](https://npmjs.org/package/md-directory) [![build status](https://img.shields.io/travis/s3ththompson/md-directory/master.svg?style=flat-square)](https://travis-ci.org/s3ththompson/md-directory) [![stability](https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square)](https://nodejs.org/api/documentation.html#documentation_stability_index)

Convert a directory of Markdown files to HTML.

Uses the [commonmark](https://github.com/jgm/commonmark.js) Markdown renderer and the [gray-matter](https://github.com/jonschlinkert/gray-matter) frontmatter parser.

## Install

Install with [npm](https://github.com/npm/npm):

```sh
npm install --save md-directory
```

or, if using [Yarn](https://github.com/yarnpkg/yarn):

```sh
yarn add md-directory
```

## Usage

Given a directory `posts` with a file `hi.md`:

```md
---
title: foo
---
# bar
```

```javascript
var md = require('md-directory')
md.parseDirSync('./posts')
```

returns:

```js
{
  "hi.md": {
    "data": {
      "title": "foo"
    },
    "content": "<h1>bar</h1>\n"
  }
}
```

Since version 1.0, `md-directory` no longer supports the `extensions` option since it was dropped by [read-directory](https://github.com/sethvincent/read-directory).

## Inlining results with Browserify

Use [transform.js](transform.js) to convert calls to `md-directory` methods into the contents they return. It is highly recommended that you use the synchronous methods `md.parseDirSync` and `md.parseSync` with Browserify.

### Source

```js
var path = require('path')
var md = require('md-directory')
var contents = md.parseDirSync(path.join(__dirname, 'posts'))
```

### Browserify

```sh
browserify index.js -t md-directory/transform -o bundle.js 
```

### Output

```js
var contents = {"hi":{"data":{"title":"foo"},"content":"<h1>bar</h1>\n"}};
```

Note: to use this transform, the path to the file directory can not be a variable. If you use the async methods, the callback must be an ES5 function (not an ES6 arrow function) and the results will be inlined with `process.nextTick`. See [brfs](https://github.com/substack/brfs#async) for more details on this behavior.

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### parseDir

Read the contents of a directory and convert to Markdown asynchronously

**Parameters**

-   `dir` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – The directory to read
-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `opts.md` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse markdown, default: commonmark
    -   `opts.frontmatter` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse frontmatter, default: gray-matter
    -   `opts.encoding` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: `utf8`
    -   `opts.filter` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for filtering files, default: `**\/*.md`
    -   `opts.ignore` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for ignoring files
    -   `opts.ignore` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** – array of glob patterns for ignoring files
    -   `opts.dirnames` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** – include or exclude subdirectory names in keys of returned object, default: `false`
    -   `opts.transform` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are converted
-   `cb`  

**Examples**

```javascript
var md = require('md-directory')
md.parseDir('./posts', function (err, contents) {
  console.log(contents)
})
```

### parseDirSync

Read the contents of a directory and convert to Markdown synchronously

**Parameters**

-   `dir` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – The directory to read
-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `opts.md` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse markdown, default: commonmark
    -   `opts.frontmatter` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse frontmatter, default: gray-matter
    -   `opts.encoding` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: `utf8`
    -   `opts.filter` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for filtering files, default: `**\/*.md`
    -   `opts.ignore` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – glob pattern for ignoring files
    -   `opts.ignore` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** – array of glob patterns for ignoring files
    -   `opts.dirnames` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** – include or exclude subdirectory names in keys of returned object, default: `false`
    -   `opts.transform` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are converted

**Examples**

```javascript
var md = require('md-directory')
var contents = md.parseDirSync('./posts')
```

### parse

Read the contents of a file and convert to Markdown asynchronously

**Parameters**

-   `filename` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – The filename to read
-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `opts.md` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse markdown, default: commonmark
    -   `opts.frontmatter` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse frontmatter, default: gray-matter
    -   `opts.encoding` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: `utf8`
    -   `opts.transform` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are converted
-   `cb`  

**Examples**

```javascript
var md = require('md-directory')
md.parse('./post.md', function (err, contents) {
  console.log(contents)
})
```

### parseSync

Read the contents of a file and convert to Markdown synchronously

**Parameters**

-   `filename` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – The filename to read
-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `opts.md` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse markdown, default: commonmark
    -   `opts.frontmatter` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** alternate function to parse frontmatter, default: gray-matter
    -   `opts.encoding` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** – encoding of files, default: `utf8`
    -   `opts.transform` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** – A function you can use to transform the contents of files after they are converted

**Examples**

```javascript
var md = require('md-directory')
var contents = md.parseSync('./post.md')
```

## See also

-   [sethvincent/read-directory](https://github.com/sethvincent/read-directory)
-   [substack/brfs](https://github.com/substack/brfs)

## License

[MIT](LICENSE.md)

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