Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gorango/rehype-extract-meta
Extract meta data from an HTML document
https://github.com/gorango/rehype-extract-meta
extract hast html meta metadata rehype rehype-plugin unist
Last synced: 3 months ago
JSON representation
Extract meta data from an HTML document
- Host: GitHub
- URL: https://github.com/gorango/rehype-extract-meta
- Owner: gorango
- License: mit
- Created: 2021-09-07T05:06:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-06T00:12:20.000Z (10 months ago)
- Last Synced: 2024-09-17T13:53:04.286Z (4 months ago)
- Topics: extract, hast, html, meta, metadata, rehype, rehype-plugin, unist
- Language: JavaScript
- Homepage:
- Size: 1.05 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# rehype-extract-meta
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Types][types-badge]][types]
[![Size][size-badge]][size][Rehype][rehype] plugin to extract meta data from an HTML document.
## Install
```
npm install rehype-extract-meta
```## Use
```js
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 = `...`
const vfile = processor.processSync(htmlString)
console.log(vfile.data.meta)
```Running the above code with a valid `htmlString` will return a [VFile][vfile]
containing the extracted contents in its `data.meta` property, conforming to
the type [`Meta`](#meta).## API
This package exports a single plugin function.
### `unified().use(rehypeExtractMeta)`
Extract meta data from HTML.
###### Returns
Transform ([`Transformer`][unified-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](https://www.typescriptlang.org).
It exports the additional type [`Meta`](#meta).[Rehype][rehype] plugin to extract meta data from an HTML document.
## License
[MIT][license] © [Goran Spasojevic][author]
[build-badge]: https://github.com/gorango/rehype-extract-meta/workflows/main/badge.svg
[build]: https://github.com/gorango/rehype-extract-meta/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/gorango/rehype-extract-meta.svg
[coverage]: https://codecov.io/github/gorango/rehype-extract-meta
[types-badge]: https://badgen.net/npm/types/rehype-extract-meta
[types]: https://www.npmjs.com/package/rehype-extract-meta
[size-badge]: https://badgen.net/packagephobia/publish/rehype-extract-meta
[size]: https://packagephobia.com/result?p=rehype-extract-meta
[rehype]: https://github.com/rehypejs/rehype
[unified-transformer]: https://github.com/unifiedjs/unified#transformer
[vfile]: https://github.com/vfile/vfile
[fixtures]: https://github.com/gorango/rehype-extract-meta/tree/main/fixtures
[bcp47Normalize]: https://github.com/wooorm/bcp-47-normalize
[license]: license
[author]: https://github.com/gorango