unified

Project: gorango/rehype-extract-meta

Package: rehype-extract-meta@2.0.4

  1. Dependents: 0
  2. Rehype plugin to extract meta data from an HTML document
  1. unist 132
  2. html 124
  3. rehype 88
  4. hast 74
  5. meta 10
  6. nlp 6
  7. extract 2

rehype-extract-meta

Build Coverage Size

Rehype plugin to extract meta data from an HTML document.

Install

npm install rehype-extract-meta

Use

import { unified } from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import rehypeExtractMeta from 'rehype-extract-meta'

const processor = unified()
  .use(rehypeParse)
  .use(rehypeExtractMeta)
  .use(rehypeStringify)

const htmlString = `<html>...</html>`
const vfile = processor.processSync(htmlString)
console.log(vfile)

Running the above code with a valid htmlString will return a VFile containing the extracted contents in its data property.

VFile {
  data: {
    meta: {
      lang: '...',
      title: '...',
      description: '...',
      publisher: '...',
      author: '...',
      copyright: '...',
      keywords: ['...'],
      updatedAt: '...',
      url: '...',
      altUrl: '...',
      imageUrl: '...',
    }
  },
  messages: [],
  history: [],
  cwd: '...',
  value: '...'
}

API

This package exports a single plugin function.

unified().use(rehypeExtractMeta)

Rehype plugin to extract meta data from an HTML document.

License

MIT © Goran Spasojevic