You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+32-20Lines changed: 32 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ is shown on Slack or certain other services.
49
49
## Install
50
50
51
51
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
52
-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
52
+
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
53
53
54
54
```sh
55
55
npm install rehype-infer-reading-time-meta
@@ -82,25 +82,21 @@ import rehypeMeta from 'rehype-meta'
82
82
importrehypeFormatfrom'rehype-format'
83
83
importrehypeStringifyfrom'rehype-stringify'
84
84
85
-
main()
86
-
87
-
asyncfunctionmain() {
88
-
constfile=awaitunified()
89
-
.use(rehypeParse, {fragment:true})
90
-
.use(rehypeInferReadingTimeMeta)
91
-
.use(rehypeDocument)
92
-
.use(rehypeMeta, {twitter:true})
93
-
.use(rehypeFormat)
94
-
.use(rehypeStringify)
95
-
.process(
96
-
'<h1>Build</h1><p><strong>We provide the building blocks</strong>: from tiny, focussed, modular utilities to plugins that combine them to perform bigger tasks. And much, much more. You can build on unified, mixing and matching building blocks together, to make all kinds of interesting new things.</p>'
97
-
)
98
-
99
-
console.log(String(file))
100
-
}
85
+
constfile=awaitunified()
86
+
.use(rehypeParse, {fragment:true})
87
+
.use(rehypeInferReadingTimeMeta)
88
+
.use(rehypeDocument)
89
+
.use(rehypeMeta, {twitter:true})
90
+
.use(rehypeFormat)
91
+
.use(rehypeStringify)
92
+
.process(
93
+
'<h1>Build</h1><p><strong>We provide the building blocks</strong>: from tiny, focussed, modular utilities to plugins that combine them to perform bigger tasks. And much, much more. You can build on unified, mixing and matching building blocks together, to make all kinds of interesting new things.</p>'
94
+
)
95
+
96
+
console.log(String(file))
101
97
```
102
98
103
-
Now running `node example.js` yields:
99
+
…now running `node example.js` yields:
104
100
105
101
```html
106
102
<!doctype html>
@@ -152,13 +148,29 @@ other random stuff, by focussing on one element.
152
148
## Types
153
149
154
150
This package is fully typed with [TypeScript][].
155
-
The extra type `Options` is exported.
151
+
The additional type `Options` is exported.
152
+
153
+
It also registers the `file.data.meta` fields with `vfile`.
154
+
If you’re working with the file, make sure to import this plugin somewhere in
155
+
your types, as that registers the new fields on the file.
156
+
157
+
```js
158
+
/**
159
+
* @typedef{import('rehype-infer-title-meta')}
160
+
*/
161
+
162
+
import {VFile} from'vfile'
163
+
164
+
constfile=newVFile()
165
+
166
+
console.log(file.data.meta.readingTime) //=> TS now knows that this is a `(number | [number, number])?`.
167
+
```
156
168
157
169
## Compatibility
158
170
159
171
Projects maintained by the unified collective are compatible with all maintained
160
172
versions of Node.js.
161
-
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
173
+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
162
174
Our projects sometimes work with older versions, but this is not guaranteed.
163
175
164
176
This plugin works with `rehype-parse` version 3+, `rehype-stringify` version 3+,
0 commit comments