Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://github.com/github/markup/blob/cf74e842dfd082d8001417c1bb94edd2ae06d61b/lib/github/markup/markdown.rb#L28
const extensions = [
"md",
"rmd",
"mkd",
"mkdn",
"mdwn",
"mdown",
"litcoffee",
"markdown",
]
if (!_.includes(extensions, node.extension)) {
return
}
const content = await loadNodeContents(node)
const data = grayMatter(content)
const markdownNode = {
_sourceNodeId: node.id,
parent: node.id,
type: `MarkdownRemark`,
id: `${node.id} >> MarkdownRemark`,
children: [],
src: data.content,
}
markdownNode.frontmatter = {
_sourceNodeId: node.id,
...data.data,
}
node.children = node.children.concat([markdownNode.id])
updateNode(node)
async function onNodeCreate({ node, actionCreators }) {
const { createNode, updateNode } = actionCreators
if (node.extension === `json`) {
const content = await loadNodeContents(node)
// TODO validate that the JSON object has an id field?
// Or just add an id if one isn't set?
const JSONArray = JSON.parse(content).map(obj => ({
...obj,
_sourceNodeId: node.id,
parent: node.id,
type: _.capitalize(node.name),
children: [],
}))
node.children = node.children.concat(JSONArray.map(n => n.id))
updateNode(node)
_.each(JSONArray, j => createNode(j))
}
}
async function onNodeCreate({ node, actionCreators }) {
const { createNode, updateNode } = actionCreators
if (node.extension === `yaml` || node.extension === `yml`) {
const content = await loadNodeContents(node)
// TODO validate that yaml object has an id field?
// Or just add an id if one isn't set?
const yamlArray = jsYaml.load(content).map(obj => ({
...obj,
parent: node.id,
_sourceNodeId: node.id,
type: _.capitalize(node.name),
children: [],
}))
node.children = node.children.concat(yamlArray)
updateNode(node)
_.each(yamlArray, y => createNode(y))
}
}