Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kingjollie #151

Open
wants to merge 33 commits into
base: sections
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
80b82d7
lint
jonschlinkert Oct 21, 2017
64ed507
3.1.1
jonschlinkert Oct 21, 2017
58a6297
Update excerpt documentation and examples
reccanti Nov 9, 2017
167e846
Fix indents
reccanti Nov 10, 2017
5d9e704
Lock down coffee-script to remove error being thrown in 1.12.8
Nov 30, 2017
94a631f
change required package from coffee-script to coffeescript
Nov 30, 2017
3a188c6
Lesson learned. test before pushing. fixed replace of coffeescript.
Nov 30, 2017
9a05990
Merge pull request #53 from reccanti/update-excerpt-docs
doowb Mar 3, 2018
9b63b5f
run verb to generate readme
doowb Mar 3, 2018
ba30f13
Extend TypeScript declaration
qm3ster Mar 4, 2018
6d31595
Merge pull request #64 from qm3ster/patch-2
jonschlinkert Mar 21, 2018
1eb7d19
Merge pull request #57 from aljopro/master
jonschlinkert Mar 21, 2018
da329cd
isempty (#66)
jonschlinkert Apr 2, 2018
cd98d0f
remove dep
jonschlinkert Apr 2, 2018
280c4b4
4.0.0
jonschlinkert Apr 2, 2018
c6735b8
4.0.1
jonschlinkert Apr 2, 2018
1d02a88
4.0.1
jonschlinkert Apr 2, 2018
73fa659
GrayMatterFile interface typo: excrept
arlair Apr 18, 2018
97eb641
Merge pull request #70 from arlair/patch-1
doowb Apr 18, 2018
7b751e0
use index type for GrayMatterFile.data
Apr 26, 2018
d9255dc
fix GrayMatterOption.engines type
Apr 26, 2018
86be0eb
Arrow function breaks in IE 11
ajaymathur Jul 14, 2018
82b8e82
added gray matter loader to related project
ajaymathur Nov 26, 2018
59122ca
Merge pull request #74 from stas-vilchik/fix-graymatteroption-engines
robertmassaioli Jan 10, 2019
0651c33
Merge pull request #73 from stas-vilchik/index-type-for-graymatterfil…
robertmassaioli Jan 10, 2019
eee3c0b
Adding in more test cases for invalid data.
robertmassaioli Jan 10, 2019
4433e1b
Merge branch 'patch-1' of https://github.com/ajaymathur/gray-matter i…
robertmassaioli Jan 10, 2019
a425516
Removing all references to arrow functions.
robertmassaioli Jan 10, 2019
7e3edf3
Putting in better formatting for the clearCache function.
robertmassaioli Jan 10, 2019
90f8120
4.0.2
robertmassaioli Jan 11, 2019
9521ec7
Merge pull request #87 from jonschlinkert/issue/more-test-cases-for-i…
robertmassaioli Jan 11, 2019
5a5817d
Merge pull request #88 from jonschlinkert/ajaymathur-patch-1
robertmassaioli Jan 11, 2019
8a22958
Merge pull request #82 from ajaymathur/master
robertmassaioli Jan 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"extends": [
"eslint:recommended",
"./package.json"
],

"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},

"parserOptions":{
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},

"globals": {
"document": false,
"navigator": false,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# always ignore files
*.DS_Store
.idea
.vscode
*.sublime-*

# test related, or directories generated by tests
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ os:
language: node_js
node_js:
- node
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
70 changes: 54 additions & 16 deletions .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Please see the [changelog](CHANGELOG.md) to learn about breaking changes that we
Add the HTML in the following example to `example.html`, then add the following code to `example.js` and run `$ node example` (without the `$`):

```js
var fs = require('fs');
var matter = require('gray-matter');
var str = fs.readFileSync('example.html', 'utf8');
const fs = require('fs');
const matter = require('gray-matter');
const str = fs.readFileSync('example.html', 'utf8');
console.log(matter(str));
```

Expand Down Expand Up @@ -72,10 +72,10 @@ Some libraries met most of the requirements, but _none met all of them_.
* Have no problem with complex content, including **non-front-matter** fenced code blocks that contain examples of YAML front matter. Other parsers fail on this.
* Support stringifying back to front-matter. This is useful for linting, updating properties, etc.
* Allow custom delimiters, when it's necessary for avoiding delimiter collision.
* Should return an object with at least these three properties (for debugging):
* Should return an object with at least these three properties:
- `data`: the parsed YAML front matter, as a JSON object
- `content`: the contents as a string, without the front matter
- `orig`: the "original" content
- `orig`: the "original" content (for debugging)

</details>

Expand All @@ -85,7 +85,7 @@ Some libraries met most of the requirements, but _none met all of them_.
Using Node's `require()` system:

```js
var matter = require('gray-matter');
const matter = require('gray-matter');
```

Or with [typescript](https://www.typescriptlang.org)
Expand Down Expand Up @@ -126,6 +126,8 @@ gray-matter returns a `file` object with the following properties.
- `file.data` **{Object}**: the object created by parsing front-matter
- `file.content` **{String}**: the input string, with `matter` stripped
- `file.excerpt` **{String}**: an excerpt, if [defined on the options](#optionsexcerpt)
- `file.empty` **{String}**: when the front-matter is "empty" (either all whitespace, nothing at all, or just comments and no data), the original string is set on this property. See [#65](https://github.com/jonschlinkert/gray-matter/issues/65) for details regarding use case.
- `file.isEmpty` **{Boolean}**: true if front-matter is empty.

**Non-enumerable**

Expand All @@ -134,7 +136,7 @@ In addition, the following non-enumberable properties are added to the object to
- `file.orig` **{Buffer}**: the original input string (or buffer)
- `file.language` **{String}**: the front-matter language that was parsed. `yaml` is the default
- `file.matter` **{String}**: the _raw_, un-parsed front-matter string
- `file.stringify` **{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and appending it to `file.content`.
- `file.stringify` **{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and prepending it to `file.content`.


## Run the examples
Expand All @@ -157,6 +159,8 @@ Then run any of the [examples](./examples) to see how gray-matter works:
$ node examples/<example_name>
```

**Links to examples**

{%= examples() %}


Expand All @@ -168,26 +172,60 @@ $ node examples/<example_name>

### options.excerpt

**Type**: `Object`
**Type**: `Boolean|Function`

**Default**: `undefined`

Extract an excerpt that directly follows front-matter, or is the first thing in the string if no front-matter exists.

If set to `excerpt: true`, it will look for the frontmatter delimiter, `---` by default and grab everything leading up to it.

**Example**

```js
var str = '--\ntitle: Home\n---\nAn excerpt\n---\nOther stuff';
console.log(matter(str, {excerpt: true}));
const str = '---\nfoo: bar\n---\nThis is an excerpt.\n---\nThis is content';
const file = matter(str, { excerpt: true });
```

Results in:

```js
{
content: 'This is an excerpt.\n---\nThis is content',
data: { foo: 'bar' },
excerpt: 'This is an excerpt.\n'
}
```

You can also set `excerpt` to a function. This function uses the 'file' and 'options' that were initially passed to gray-matter as parameters, so you can control how the excerpt is extracted from the content.

**Example**

```js
// returns the first 4 lines of the contents
function firstFourLines(file, options) {
file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}

const file = matter([
'---',
'foo: bar',
'---',
'Only this',
'will be',
'in the',
'excerpt',
'but not this...'
].join('\n'), {excerpt: firstFourLines});
```

Results in:

```js
{
data: { title: 'Home'},
excerpt: '\nAn excerpt',
content: '\nAn excerpt\n---\nOther stuff'
content: 'Only this\nwill be\nin the\nexcerpt\nbut not this...',
data: { foo: 'bar' },
excerpt: 'Only this will be in the excerpt'
}
```

Expand Down Expand Up @@ -242,13 +280,13 @@ Engines may either be an object with `parse` and (optionally) `stringify` method
**Examples**

```js
var toml = require('toml');
const toml = require('toml');

/**
* defined as a function
*/

var file = matter(str, {
const file = matter(str, {
engines: {
toml: toml.parse.bind(toml),
}
Expand All @@ -258,7 +296,7 @@ var file = matter(str, {
* Or as an object
*/

var file = matter(str, {
const file = matter(str, {
engines: {
toml: {
parse: toml.parse.bind(toml),
Expand Down
21 changes: 15 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Release history

## Unreleased
## 4.0.0 - 2018-04-01

### Breaking changes

- Now requires node v4 or higher.


## 3.0.0 - 2017-06-30

### Breaking changes
* `toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.

- `toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.

### Added
* Support for [excerpts](README.md#optionsexcerpt).
* The returned object now has non-enumerable `matter` and `stringify` properties.

- Support for [excerpts](README.md#optionsexcerpt).
- The returned object now has non-enumerable `matter` and `stringify` properties.

### Changed
* Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
* `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)

- Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
- `options.parsers` was renamed to [`options.engines`](README.md#optionsengines)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2017, Jon Schlinkert.
Copyright (c) 2014-2018, Jon Schlinkert.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down