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
function processContentTree(tree: Node[], file: File, indexName: string): void {
const modify = modifyChildren(modifier);
// We first modify the tree to get slugified ids from headings to all text nodes
// This is done to be able to link to a certain section in a doc after clicking a search suggestion
modify(tree);
// Get all text nodes. I.e. 'heading', 'paragraph', 'list' all can have (nested) child text nodes
const textNodes = selectAll('text', tree);
if (textNodes) {
// Combines text nodes that exist on the same line. I.e. if a paragraph contains 7 text nodes it combines them into 1. This makes text snippets in algolia more descriptive.
const formattedTextNodes = formatTextNodes(textNodes);
// Adds meta and formats information on all formatted text nodes
const content = getContent(file, formattedTextNodes);
const algoliaIndex = adminClient.initIndex(searchIndices[indexName]);
const algoliaSettings = settings[indexName];
setIndexSettings(algoliaIndex, algoliaSettings);
void pushObjectsToAlgoliaAsync(algoliaIndex, content);
}
}
return () => /* attacher */ (tree) => {
/* transformer */
if (excerpt) {
return select(selector, tree)
}
return tree
}
}
return () => /* attacher */ tree => {
/* transformer */
tree.children = select(tree, selector);
return tree;
};
};
export const parse = ({ content, filePath }: ParserArgs): ParsedResults => {
const markdownAST = attachParents(remark.parse(content));
const codeBlocks = [].concat(
select.selectAll(`code[lang="js"]`, markdownAST),
select.selectAll(`code[lang="javascript"]`, markdownAST)
);
return codeBlocks.map((codeBlock: UnistNode) => {
const codeValue: string = (codeBlock.value as string | undefined) || "";
const comments = getComments(codeBlock.parent, codeBlock);
const docTestController = new DocTestController(comments);
const state = docTestController.state;
const doctestOptions = docTestController.doctestOptions;
const expectedError = docTestController.expectedErrorName;
const metadata = docTestController.doctestMetadata;
return {
code: codeValue,
location: codeBlock.position ? {
start: {
line: codeBlock.position.start.line,
column: codeBlock.position.start.column
tester.has = (selector) => {
assert.ok(select.select(selector, node), `Markdown AST does not include node matching selector "${selector}"
${inspect(node)}`);
return tester;
};
tester.equals = (selector, value) => {
export const getProperties = headline => {
const drawer = selectAll(`drawer`, headline).find(d => d.name === `PROPERTIES`)
if (!drawer) return {}
const regex = /\s*:(.+):\s*(.+)\s*$/
return drawer.value.split(`\n`).reduce((accu, current) => {
const m = current.match(regex)
return { ...accu, [m[1].toLowerCase()]: m[2] }
}, {})
}
return (tree, file) => {
const heading = select('heading', tree)
file.data.title = heading ? toString(heading) : ''
visit(tree, ['yaml'], node => {
file.data = {
...file.data,
...yaml(node.value)
}
})
visit(tree, ['toml'], node => {
file.data = {
...file.data,
...toml(node.value)
}
})
}
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},
},
}
}
})
}
}
pathnames.forEach(function (pathname) {
var fileBaseName = path.basename(pathname, '.md');
var tree = mdCache[pathname].mdOutTree;
var className = ngHelpers.ngNameToClassName(fileBaseName, aggData.config.typeNameExceptions);
var classInfo = aggData.classInfo[className];
if (!classInfo) {
if (!filterFilepath(filters, pathname)) {
classlessDocs.push(pathname);
}
}
else {
var linkElems = unist_util_select_1.selectAll('link', tree);
linkElems.forEach(function (linkElem) {
var normUrl = normaliseLinkPath(pathname, linkElem.url);
multiSetAdd(linkRefs, normUrl, pathname);
});
}
var imageElems = unist_util_select_1.selectAll('image', tree);
imageElems.forEach(function (imageElem) {
var normUrl = normaliseLinkPath(pathname, imageElem.url);
multiSetAdd(imageRefs, normUrl, pathname);
if (!fs.existsSync(normUrl)) {
brokenImageRefs[normUrl] = pathname;
}
});
});
classlessDocs.forEach(function (docPath) {