gatsby-transformer-javascript-frontmatter
Advanced tools
Comparing version 1.1.0-alpha.067e672c to 1.1.0-alpha.12622d64
@@ -19,9 +19,9 @@ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator"); | ||
getNode, | ||
boundActionCreators, | ||
actions, | ||
loadNodeContent | ||
}) { | ||
const createNode = boundActionCreators.createNode, | ||
createParentChildLink = boundActionCreators.createParentChildLink; // This only processes javascript files. | ||
const createNode = actions.createNode, | ||
createParentChildLink = actions.createParentChildLink; // This only processes javascript & jsx files. | ||
if (node.internal.mediaType !== `application/javascript`) { | ||
if (node.internal.mediaType !== `application/javascript` && node.internal.mediaType !== `text/jsx`) { | ||
return; | ||
@@ -36,3 +36,3 @@ } | ||
}; | ||
let exportsData, frontmatter; | ||
let exportsData, frontmatter, error; | ||
@@ -64,2 +64,3 @@ try { | ||
frontmatter = {}; | ||
error = false; | ||
traverse(ast, { | ||
@@ -87,40 +88,41 @@ AssignmentExpression: function AssignmentExpression(astPath) { | ||
}); | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: false | ||
}); | ||
} catch (e) { | ||
// stick the error on the query so the user can | ||
// react to an error as they see fit | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: { | ||
err: true, | ||
code: e.code, | ||
message: e.message, | ||
stack: e.stack | ||
} | ||
}); | ||
error = { | ||
err: true, | ||
code: e.code, | ||
message: e.message, | ||
stack: e.stack | ||
}; | ||
} finally { | ||
const objStr = JSON.stringify(node); | ||
const contentDigest = crypto.createHash(`md5`).update(objStr).digest(`hex`); | ||
const nodeData = { | ||
id: `${node.id} >>> JavascriptFrontmatter`, | ||
children: [], | ||
parent: node.id, | ||
node: Object.assign({}, node), | ||
internal: { | ||
contentDigest, | ||
type: `JavascriptFrontmatter` | ||
// only create node if frontmatter is not empty | ||
if (!_.isEmpty(frontmatter)) { | ||
exportsData = Object.assign({}, frontmatter, { | ||
error: error | ||
}); | ||
const objStr = JSON.stringify(node); | ||
const contentDigest = crypto.createHash(`md5`).update(objStr).digest(`hex`); | ||
const nodeData = { | ||
id: `${node.id} >>> JavascriptFrontmatter`, | ||
children: [], | ||
parent: node.id, | ||
node: Object.assign({}, node), | ||
internal: { | ||
contentDigest, | ||
type: `JavascriptFrontmatter` | ||
} | ||
}; | ||
nodeData.frontmatter = Object.assign({}, exportsData); | ||
if (node.internal.type === `File`) { | ||
nodeData.fileAbsolutePath = node.absolutePath; | ||
} | ||
}; | ||
nodeData.frontmatter = Object.assign({}, exportsData); | ||
if (node.internal.type === `File`) { | ||
nodeData.fileAbsolutePath = node.absolutePath; | ||
createNode(nodeData); | ||
createParentChildLink({ | ||
parent: node, | ||
child: nodeData | ||
}); | ||
} | ||
createNode(nodeData); | ||
createParentChildLink({ | ||
parent: node, | ||
child: nodeData | ||
}); | ||
} | ||
@@ -127,0 +129,0 @@ }); |
{ | ||
"name": "gatsby-transformer-javascript-frontmatter", | ||
"description": "Gatsby transformer plugin for JavaScript to extract exports.frontmatter statically.", | ||
"version": "1.1.0-alpha.067e672c", | ||
"version": "1.1.0-alpha.12622d64", | ||
"author": "Jacob Bolda <me@jacobbolda.com>", | ||
"bugs": { | ||
"url": "https://github.com/gatsbyjs/gatsby/issues" | ||
}, | ||
"dependencies": { | ||
@@ -16,7 +13,6 @@ "babel-runtime": "^6.26.0", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.38", | ||
"@babel/core": "^7.0.0-beta.38", | ||
"cross-env": "^5.0.5" | ||
"@babel/cli": "^7.0.0-beta.42", | ||
"@babel/core": "^7.0.0-beta.42", | ||
"cross-env": "^5.1.4" | ||
}, | ||
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter#readme", | ||
"keywords": [ | ||
@@ -28,6 +24,3 @@ "gatsby", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gatsbyjs/gatsby.git" | ||
}, | ||
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-javascript-frontmatter", | ||
"scripts": { | ||
@@ -34,0 +27,0 @@ "build": "babel src --out-dir . --ignore __tests__", |
@@ -7,3 +7,3 @@ # gatsby-transformer-javascript-frontmatter | ||
`npm install --save gatsby-transformer-frontmatter` | ||
`npm install --save gatsby-transformer-javascript-frontmatter` | ||
@@ -10,0 +10,0 @@ ## How to use |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111
7415
1
2
5