rehype-extract-meta

Rehype plugin to extract meta data from an HTML document

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
rehype-extract-meta
304.0.0a month ago3 years agoMinified + gzip package size for rehype-extract-meta in KB

Readme

rehype-extract-meta
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Typestypes-badgetypes !Sizesize-badgesize
Rehyperehype 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.data.meta)

Running the above code with a valid htmlString will return a VFilevfile containing the extracted contents in its data.meta property, conforming to the type Meta.

API

This package exports a single plugin function.

unified().use(rehypeExtractMeta)

Extract meta data from HTML.
Returns
Transform (Transformerunified-transformer).

Meta

Data property (TypeScript type).
Fields
  • lang (string) - Language string
  • date (string) - Document date
  • title (string) - Document title
  • description (string) - Document description
  • keywords (string[]) - Document keywords
  • author (string) - Document author
  • publisher (string) - Document publisher
  • copyright (string) - Document copyright
  • pageUrl (string) - Page URL
  • imageUrl (string) - Image URL
  • feedUrl (string) - Feed URL

Types

This package is fully typed with TypeScript. It exports the additional type Meta.
Rehyperehype plugin to extract meta data from an HTML document.

License

MITlicense © Goran Spasojevicauthor