# express-blog-middleware

> Blog middleware for the Express framework

Latest version **0.1.2** (published 2016-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-blog-middleware
pnpm add express-blog-middleware
yarn add express-blog-middleware
bun add express-blog-middleware
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-08-18 |
| First published | 2016-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+5 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bill Granfield |
| Maintainers | b-gran |
| Keywords | express, expressjs, middleware, blog, blogging |

## Links

- npm: https://www.npmjs.com/package/express-blog-middleware
- Repository: https://github.com/b-gran/express-blog-middleware
- Issues: https://github.com/b-gran/express-blog-middleware/issues
- npm.io page: https://npm.io/package/express-blog-middleware

## Dependencies (5)

- [pug](https://npm.io/package/pug.md) ^2.0.0-beta5
- [lodash](https://npm.io/package/lodash.md) ^4.15.0
- [marked](https://npm.io/package/marked.md) ^0.3.6
- [express](https://npm.io/package/express.md) ^4.14.0
- [front-matter](https://npm.io/package/front-matter.md) ^2.1.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2016-08-18
- 0.1.1 — 2016-08-18
- 0.1.0 — 2016-08-18

## README

# `express-blog-middleware`

Dead simple blogging middleware for the Express framework.

Allows you to mount a blog anywhere in an existing Express app.
The posts are just `markdown` or `pug` files sitting in a directory
somewhere.

## Installing

```
npm install express-blog-middleware
```

## Usage

```
import express from 'express';
const app = express();

import blog from 'express-blog-middleware';

app.use('/blog', blog({
    postsDirectory: 'posts'
});
```

The blog middleware creates two routes:

### Main blog view

```
# A page of posts
GET /?page=N
```

For the above example, the URL `/blog/` would retrieve the main blog
view, which would display the first page of posts.

`/blog/?page=2` would display the second page of posts.

### Individual posts

```
# A particular post
GET /post/:postName
```

Each post is identified by its filename without the file extension.

So if the post `posts/` directory looks like this:

```
/posts/
----/post-1.md
----/post-2.markdown
----/post-3.pug
----/post-4.jade
----/post-5.MD
```

`/blog/post/post-2` would display the post `post-1.md` and 
`/blog/post/post-4` would display the post `post-4.jade`.

## Configuration

The `blog()` function takes a configuration parameter which accepts the
following options:

| Parameter | Type | Required | Default | Notes |
| --- | --- | --- | --- | --- |
| postsDirectory | String | `true` | | Path to the `posts` directory. |
| post | String | `false` | express-blog-middleware's default template | Path to a pug template to use for an __individual__ post |
| page | String | `false` | express-blog-middleware's default template | Path to a pug template to use for a __page__ of posts. Also used for the main page of the blog |
| postsPerPage | Number | `false` | 10 | Number of posts to display per page |
| blogURL | String | `false` | `/` | URL to the root of the blog. Used for direct links to posts |

Example (default options):

```
app.use('/blog', blog({
    postsDirectory: 'posts',
    post: 'post.pug',
    page: 'page.pug',
    postsPerPage: 10,
    blogURL: '/',
});
```

## Examples

See `/tools/startServer` for an example of a server with a blog mounted at `/`.

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