Skip to content

Commit

Permalink
feature(tag-tree-data-provider): Add support for yaml frontmatter (#42)
Browse files Browse the repository at this point in the history
* feat(yaml): Add yaml frontmatter support

* docs(readme): Add yaml frontmatter documentation
  • Loading branch information
blakedietz authored Apr 22, 2019
1 parent 7b2188f commit 615e932
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 31 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ View your notes without being limited by your file system's hierarchy.
Markdown files with the directive

```markdown
<!--@nested-tags:topic,example-->
<!--@nested-tags:topic,here/is/a/nested/example-->
```

Will be visible from the file tab under a "Tag Tree" view.
or yaml frontmatter with a tags property

```
---
title: Hello nested tags
tags: topic,here/is/a/nested/example
---
```

will be visible from the file tab under a "Tag Tree" view.

## Requirements

Expand Down
58 changes: 50 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"vscode": "^1.1.25"
},
"dependencies": {
"debounce": "^1.2.0"
"debounce": "^1.2.0",
"gray-matter": "4.0.2"
},
"activationEvents": [
"onView:tagTreeView"
Expand Down Expand Up @@ -94,25 +95,25 @@
},
"release": {
"plugins": [
[
"@semantic-release/release-notes-generator",
{
"preset": "angular",
"parserOpts": {
"noteKeywords": [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
]
},
"writerOpts": {
"commitsSort": [
"subject",
"scope"
]
}
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "angular",
"parserOpts": {
"noteKeywords": [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
]
},
"writerOpts": {
"commitsSort": [
"subject",
"scope"
]
}
}
],
[
"@semantic-release/changelog",
{
Expand Down
11 changes: 10 additions & 1 deletion src/tag-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { setsAreEqual } from "./sets";
import { FileNode, fileNodeSort } from "./tag-tree/file-node";
import { TagNode, tagNodeSort } from "./tag-tree/tag-node";
import { TagTree } from "./tag-tree/tag-tree";
import * as grayMatter from "gray-matter";

interface IFileInfo {
tags: Set<string>;
Expand Down Expand Up @@ -184,6 +185,14 @@ class TagTreeDataProvider
* @param filePath The local filesystem path
*/
private getTagsFromFileText(fileContents: string, filePath: string): IFileInfo {

// Parse any yaml frontmatter and check for tags within that frontmatter
const { data }= grayMatter(fileContents) ;
let yamlTags = new Set();
if (data.tags) {
yamlTags = new Set([data.tags.split(',')]);
}

return fileContents
.split("\n")
.reduce((accumulator, currentLine) => {
Expand All @@ -198,7 +207,7 @@ class TagTreeDataProvider
}

return accumulator;
}, { tags: new Set(), filePath });
}, { tags: new Set(...yamlTags), filePath });
}

/**
Expand Down

0 comments on commit 615e932

Please sign in to comment.