2016-11-13 22:11:49 +00:00
|
|
|
# smartfm
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-14 12:33:16 +00:00
|
|
|
frontmatter done right
|
2016-11-13 22:11:49 +00:00
|
|
|
|
|
|
|
## Availabililty
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-13 22:11:49 +00:00
|
|
|
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartfm)
|
|
|
|
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartfm)
|
|
|
|
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartfm)
|
|
|
|
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartfm/)
|
|
|
|
|
|
|
|
## Status for master
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-13 22:11:49 +00:00
|
|
|
[![build status](https://gitlab.com/pushrocks/smartfm/badges/master/build.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
|
|
|
|
[![coverage report](https://gitlab.com/pushrocks/smartfm/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
|
|
|
|
[![Dependency Status](https://david-dm.org/pushrocks/smartfm.svg)](https://david-dm.org/pushrocks/smartfm)
|
|
|
|
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartfm/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartfm/master/dependencies/npm)
|
|
|
|
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartfm/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartfm)
|
|
|
|
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
|
|
|
|
|
2016-11-14 12:33:16 +00:00
|
|
|
## What is frontMatter?
|
2016-11-13 22:11:49 +00:00
|
|
|
|
|
|
|
say you have the following markdown file:
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-13 22:11:49 +00:00
|
|
|
```markdown
|
|
|
|
---
|
2016-11-14 12:33:16 +00:00
|
|
|
title: A Really Awesome Article
|
2016-11-13 22:11:49 +00:00
|
|
|
date: 23-10-2020
|
|
|
|
type: feature
|
|
|
|
---
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-14 12:33:16 +00:00
|
|
|
# An Awesome Title
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-13 22:11:49 +00:00
|
|
|
The world is cool. And here is why
|
2018-08-27 00:01:18 +00:00
|
|
|
|
|
|
|
- reason 1
|
|
|
|
- reason 2
|
2016-11-13 22:11:49 +00:00
|
|
|
```
|
2018-08-27 00:01:18 +00:00
|
|
|
|
2016-11-14 12:33:16 +00:00
|
|
|
The top part that is enclosed by `---` denotes frontmatter, usually written in yaml notation.
|
|
|
|
Frontmatter is not exclusive to markdown.
|
|
|
|
It can be used as prefix in any type of file when preprocessed with smartfm.
|
|
|
|
|
2018-08-27 00:01:18 +00:00
|
|
|
## Usage
|
|
|
|
|
2016-11-14 12:33:16 +00:00
|
|
|
We recommend TypeScript for best in class Intellisense.
|
2016-11-13 22:11:49 +00:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
import * as smartfm from * smartfm
|
|
|
|
|
|
|
|
let markdownfile = `---
|
|
|
|
testKey: testValue
|
|
|
|
testKey2: testValue2
|
|
|
|
---
|
|
|
|
# some markdown`
|
|
|
|
|
|
|
|
// easy methods
|
|
|
|
let parsedData = smartfm.parse(markdownfile)
|
|
|
|
|
|
|
|
// parsedData will be object
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
data: {
|
|
|
|
testKey: testValue,
|
|
|
|
testKey2: testValue2
|
|
|
|
},
|
|
|
|
content: '# some markdown',
|
|
|
|
orig: '---\ntestKey: testValue\ntestKey2: testValue2\n---\n# some markdown'
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
let newFmString = smartfm.stringify('My awesome string', {testKey1: testValue1})
|
|
|
|
// newFmString will be '---\testKey1: testValue1\n---\nMyawesomeString'
|
|
|
|
|
|
|
|
# class Smartfm
|
|
|
|
let mySmartfm = new smartfm.Smartfm({
|
|
|
|
fmType: 'yaml' // can be yaml or json atm
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
|