How to use the unist-util-select function in unist-util-select

To help you get started, we’ve selected a few unist-util-select examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gatsbyjs / gatsby / packages / gatsby / lib / schema / markdown.js View on Github external
_.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
github storybookjs / SBNext / server / src / components / doc.js View on Github external
return () => /* attacher */ tree => {
    /* transformer */
    tree.children = select(tree, selector);
    return tree;
  };
};
github remarkjs / remark-external-links / src / index.js View on Github external
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},
          },
        }
      }
    })
  }
}
github gatsbyjs / gatsby / packages / gatsby / lib / schema / markdown.js View on Github external
page.headings = select(ast, `heading`).map(heading => ({
          value: _.first(select(heading, `text`).map(text => text.value)),
          depth: heading.depth,
        }))
        const parsedFrontmatter = _.first(

unist-util-select

unist utility to select nodes with CSS-like selectors

MIT
Latest version published 6 months ago

Package Health Score

73 / 100
Full package analysis