# yaml-blog

> a serious blog module.

Latest version **1.2.1** (published 2016-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install yaml-blog
pnpm add yaml-blog
yarn add yaml-blog
bun add yaml-blog
```

## 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.2.1 |
| Published | 2016-06-22 |
| First published | 2016-06-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | fra 9001 |
| Maintainers | fra9001 |
| Keywords | blog, blogging, posts, writing |

## Links

- npm: https://www.npmjs.com/package/yaml-blog
- npm.io page: https://npm.io/package/yaml-blog

## Dependencies (7)

- [when](https://npm.io/package/when.md) ^3.7.7
- [marked](https://npm.io/package/marked.md) ^0.3.5
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.6.1
- [then-fs](https://npm.io/package/then-fs.md) ^2.0.0
- [underscore](https://npm.io/package/underscore.md) 1.8.x
- [front-matter](https://npm.io/package/front-matter.md) ^2.0.8
- [json-front-matter](https://npm.io/package/json-front-matter.md) >= 0.1.4

## 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
- [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
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.2.1 (latest) — 2016-06-22
- 1.2.0 — 2016-06-22
- 1.0.1 — 2016-06-03
- 1.0.0 — 2016-06-03

## README

# yaml-blog

this is a small module that tries to be a blog engine.

it reads from the file system and uses yaml, markdown and promises

## API

the module is composed by three classes:

- `FileRepository`
- `PostRepository`
- `Blog`

this is the schema of classes

- `Blog`
    - `PostRepository @post`
        - `FileRepository @fs`

the three classes are created with dependency injection and defaults. they share the same configuration object.

the `post` object is the `yaml-front-matter` result. The `post.body` is HTML

### Blog

#### Constructor

    blog = new Blog
        path: <string>,<required>
        post_per_page: <int>,<default:5>
        post: <class>,<default:PostRepository>
        fs: <class>,<default:FileRepository>

#### Methods

- `.getTags()`: returns a list of tag
    
    blog.getTags() -> <promise>

    blog.getTags().then (tags) ->
        ...

- `.getPosts(o)`: returns different object based on the query

    blog.getPosts
        from: <int>, to: <int> #slices the list
        title: <string> #gets a post by title
        slug: <string> #gets a post by slug
        page: <int> #pages the collection based on the value from the constructor
        <null>: <null> #gets all posts

    blog.getPosts() -> <promise>

    blog.getPosts().then (posts) ->
        ...

- `.getTree()`: return a tree of the posts divided by year and month

    blog.getTree() -> <promise>

    blog.getTree().then (tree) ->
        tree[<year:string>]                 #the posts from the year <object>
        tree[<year>][<month:string>]        #the posts from the month <array>
        tree[<year>][<month>][<index:int>]  #a post object <object>
        ...
- `.save(post)`: saves the post through the @fs object

    blog.save(post) -> <promise>

    blog.save(post).then () ->
        ...

### PostRepository

the `PostRepository` instance is accessible via the `.post` property of `Blog`

#### Constructor

    postRep = new PostRepository
        fs: <class>, <default:FileRepository>
        path: <string>

#### Methods

- `.parse(data = null)`: parses in or out the data

    postRep.parse() -> promise

    postRep.parse().then (posts) ->
        ... #array with the posts

    postRep.parse(post).then ->
        ... #saves the post in the filesystem

- `.delete(post)`: deletes the post

    postRep.delete(post) -> <promise>

    postRep.delete(post).then () ->
        ...

### FileRepository

the `FileRepository` instance is accessible via the `.fs` property of `PostRepository`

#### Constructor

    fileRep = new FileRepository(path <string>)

#### Methods

- `.getAllPath(dir = @dir)`: gets all the directory recursively. the optional argument is the path given from the constructor

    fileRep.getAllPath() -> <promise>

    fileRep.getAllPath().then (paths) ->
        ...

- `.pathify(dir, file)`: unites the dir and the filename

    fileRep.pathify(dir <string>, file <string>) -> <string>

- `.read(file)`: reads the file

    fileRep.read(file).then (content) ->
        ...

- `.write(file, data)`: writes the file on the filesystem

    fileRep.write(file <string>, data <string>) -> promise

    fileRep.write(file, data).then () ->
        ...

- `.delete(file)`: deletes the file

    fileRep.delete(file <string>) -> <promise>

    fileRep.delete(file).then () ->
        ...

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