Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ function updateHandler(data, matter) {
editor.read(filePath).data(updateHandler);
```

You can use the optional third parameter `fileSystemInfo` to access information about the file itself:

```
let extend = require('util')._extend;

function updateHandler(data, matter, fileSystemInfo) {
const d = fileSystemInfo.status.mtime;
data.last_updated = [d.getFullYear(), d.getMonth()+1, d.getDate()].join('-');
matter.data = data;
}

editor.read(filePath).data(updateHandler);
```

## .content()
This method update content in file.
```
Expand All @@ -84,6 +98,8 @@ function updateHandler(content, matter) {
editor.read(filePath).content(updateHandler);
```

This method also supports the optional third parameter `fileSystemInfo` for the callback.

## .save(destDirPath, options, callback)

this method save to file. if this method have not options, save file by default options. default options is same filename with source file.
Expand Down
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class FrontMatterService {
}

extend(func) {
func(this.matter.data, this.matter.content, this.matter);
func(this.matter.data, this.matter.content, this.matter, this.fileSystemInfo);
return this;
}

data(func) {
// this.matter = extend(this.matter, obj);
func(this.matter.data, this.matter);
func(this.matter.data, this.matter, this.fileSystemInfo);
return this;
}

content(func) {
func(this.matter.content, this.matter);
func(this.matter.content, this.matter, this.fileSystemInfo);
return this;
}

Expand Down Expand Up @@ -79,4 +79,3 @@ module.exports = new FrontMatterService();
// module.exports.prototype.show = function(){
// console.log(this.)
// }