Skip to content

Commit

Permalink
Add _meta.resourcePath attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
hmsk committed Jun 9, 2019
1 parent b18220f commit 2dd5cca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ module.exports = function (source) {
fm.html = md.render(fm.body);
}

const attributes = {
...fm.attributes,
_meta: {
resourcePath: this.resourcePath
}
};

let output = `
body: ${stringify(fm.body)},
html: ${stringify(fm.html)},
attributes: ${stringify(fm.attributes)}`;
attributes: ${stringify(attributes)}`;

if (!!options.vue && vueCompiler && vueCompilerStripWith) {
const rootClass = options.vue.root || "frontmatter-markdown"
Expand Down
14 changes: 9 additions & 5 deletions test/frontmatter-markdown-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import nodeEval from "node-eval";
let loaded;

const defaultContext = {
cachable: false
cachable: false,
resourcePath: "/somewhere/frontmatter.md"
};

const load = (source, context = defaultContext) => {
Expand Down Expand Up @@ -67,11 +68,14 @@ describe("frontmatter-markdown-loader", () => {
});

it("returns frontmatter object for 'attributes' property", () => {
expect(loaded.attributes).toEqual({
subject: "Hello",
tags: ["tag1", "tag2"]
});
expect(loaded.attributes).toEqual({
subject: "Hello",
tags: ["tag1", "tag2"],
_meta: {
resourcePath: "/somewhere/frontmatter.md"
}
});
});

it("doesn't returns 'vue' property", () => {
expect(loaded.vue).toBeUndefined();
Expand Down

0 comments on commit 2dd5cca

Please sign in to comment.