Skip to content

Sharing variables between plugins #170

Answered by wooorm
robinmetral asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it is possible.
Note that rehype-meta is much more powerful than rehype-document and supports this example! You can also use both rehype-document and rehype-meta — the first is more about the document structure coming from markdown, the second is about all your SEO/OG/etc needs.

// ...
.use(remarkFrontmatter, ["yaml"])
.use(() => (tree, file) => {
  const head = tree.children[0]
  if (head && head.type === 'yaml') {
    file.data.matter = yaml.load(yamlFrontmatter);
  }
})
// ...
.use(rehypeMeta) // It works!

This is done by sharing metadata on the file. The convention for parsed frontmatter is to go into file.data.matter. And rehype-meta accepts that!

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@robinmetral
Comment options

@wooorm
Comment options

@robinmetral
Comment options

Answer selected by robinmetral

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants