Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.each(files, file => {
const page = {}
page.src = fs.readFileSync(file, `utf-8`)
const ast = remark.parse(page.src)
page.ast = ast
page.bodyHTML = thing.Compiler.prototype.compile(page.ast)
page.headings = select(ast, `heading`).map(heading => ({
value: _.first(select(heading, `text`).map(text => text.value)),
depth: heading.depth,
}))
const parsedFrontmatter = _.first(
select(ast, `yaml`).map(heading => yaml.load(heading.value))
)
const relativeDirectory = parseFilepath(
path.relative(`${directory}/pages/`, file)
).dirname
// Create path.
let filePath
if (_.includes(relativeDirectory, `---`)) {
// This is for my blog bricolage.io. This will be moved out soonish.
filePath = `/${relativeDirectory.split(`---`)[1]}/`
} else {
filePath = createPath(path.join(directory, `pages`), file)
}
// TODO put linkPrefix in gatsby.config.js and somehow get certain
// context stuff into gatsby-helpers.js
// TODO post issue for why manifest paths wrong
return () => /* attacher */ tree => {
/* transformer */
tree.children = select(tree, selector);
return tree;
};
};
return (ast) => {
select(ast, "link").forEach((node) => {
if (!isRelativeUrlRegex.test(node.url)) {
node.data = {
hProperties: {
...options.target !== null &&
{target: options.target || defaultTarget},
...options.rel !== null &&
{rel: options.rel || defaultRel},
},
}
}
})
}
}
page.headings = select(ast, `heading`).map(heading => ({
value: _.first(select(heading, `text`).map(text => text.value)),
depth: heading.depth,
}))
const parsedFrontmatter = _.first(