Skip to content

Commit 52f0e48

Browse files
committed
Add improved docs
1 parent 166be58 commit 52f0e48

File tree

2 files changed

+139
-65
lines changed

2 files changed

+139
-65
lines changed

lib/types.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/**
22
* @typedef Author
3-
* An author object
3+
* Author object
44
* @property {string} name
5-
* Example: `'Acme, Inc.'` or `'Jane Doe'`
5+
* Name (example: `'Acme, Inc.'` or `'Jane Doe'`).
66
* @property {string | null | undefined} [email]
7-
* Example: `john@example.org`
7+
* Email address (example: `john@example.org`).
88
* @property {string | null | undefined} [url]
9-
* Example: `'https://example.org/john'`.
9+
* URL to author (example: `'https://example.org/john'`).
10+
*
1011
* `url` is used in `atom`, not in `rss`.
1112
*
1213
* @typedef Enclosure
13-
* Media
14+
* Media.
1415
* @property {string} url
1516
* Full URL to the resource (example:
1617
* `'http://dallas.example.com/joebob_050689.mp3'`).
@@ -29,39 +30,52 @@
2930
* @property {string | null | undefined} [feedUrl]
3031
* Full URL to this channel (example:
3132
* `'https://www.adweek.com/feed/'`).
33+
*
3234
* Make sure to pass different ones to `rss` and `atom`!
35+
*
3336
* You *should* define this.
3437
* @property {string | null | undefined} [description]
3538
* Short description of the channel (example: `Album Reviews`).
39+
*
3640
* You *should* define this.
3741
* @property {string | null | undefined} [lang]
3842
* BCP 47 language tag representing the language of the whole channel (example:
3943
* `'fr-BE'`).
44+
*
4045
* You *should* define this.
41-
* @property {string | Author | null | undefined} [author] Optional author of the whole channel.
46+
* @property {string | Author | null | undefined} [author]
47+
* Optional author of the whole channel.
48+
*
4249
* Either `string`, in which case it’s as passing `{name: string}`.
4350
* Or an author object.
44-
* @property {Array<string> | null | undefined} [tags] Categories of the channel (example:
45-
* `['JavaScript', 'React']`).
51+
* @property {Array<string> | null | undefined} [tags]
52+
* Categories of the channel (example: `['JavaScript', 'React']`).
4653
*
4754
* @typedef Entry
4855
* Data on a single item.
4956
* @property {string | null | undefined} [title]
5057
* Title of the item (example: `'Playboi Carti: Whole Lotta Red'`).
58+
*
5159
* Either `title`, `description`, or `descriptionHtml` must be set.
5260
* @property {string | null | undefined} [description]
5361
* Either the whole post or an excerpt of it (example: `'Lorem'`).
62+
*
5463
* Should be plain text.
5564
* `descriptionHtml` is preferred over plain text `description`.
65+
*
5666
* Either `title`, `description`, or `descriptionHtml` must be set.
5767
* @property {string | null | undefined} [descriptionHtml]
5868
* Either the whole post or an excerpt of it (example: `'<p>Lorem</p>'`).
69+
*
5970
* Should be serialized HTML.
6071
* `descriptionHtml` is preferred over plain text `description`.
72+
*
6173
* Either `title`, `description`, or `descriptionHtml` must be set.
6274
* @property {string | Author | null | undefined} [author]
6375
* Entry version of `channel.author`.
76+
*
6477
* You *should* define this.
78+
*
6579
* For `atom`, it is required to either set `channel.author` or set `author`
6680
* on all entries.
6781
* @property {string | null | undefined} [url]

readme.md

Lines changed: 117 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[xast][] utility to build (web) feeds ([RSS][], [Atom][]).
11+
[xast][] utility to build (web) feeds ([RSS][rss-spec], [Atom][atom-spec]).
1212

1313
## Contents
1414

@@ -17,9 +17,11 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`rss(channel, data)`](#rsschannel-data)
2120
* [`atom(channel, data)`](#atomchannel-data)
22-
* [`Channel`](#channel-1)
21+
* [`rss(channel, data)`](#rsschannel-data)
22+
* [`Author`](#author)
23+
* [`Channel`](#channel)
24+
* [`Enclosure`](#enclosure)
2325
* [`Entry`](#entry)
2426
* [Types](#types)
2527
* [Compatibility](#compatibility)
@@ -52,7 +54,7 @@ Just using either RSS or Atom is probably fine: no need to do both.
5254
## Install
5355

5456
This package is [ESM only][esm].
55-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
57+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
5658

5759
```sh
5860
npm install xast-util-feed
@@ -165,142 +167,194 @@ Yields (pretty printed):
165167

166168
## API
167169

168-
This package exports the identifiers `atom` and `rss`.
170+
This package exports the identifiers [`atom`][atom] and [`rss`][rss].
169171
There is no default export.
170172

171-
### `rss(channel, data)`
173+
### `atom(channel, data)`
172174

173-
Build an RSS feed.
175+
Build an [Atom][atom-spec] feed.
174176

175-
###### `channel`
177+
###### Parameters
176178

177-
See [`Channel`][channel].
179+
* `channel` ([`Channel`][channel])
180+
— data on the feed (the group of items)
181+
* `data` ([`Array<Entry>`][entry], optional)
182+
— list of entries
178183

179-
###### `data`
184+
###### Returns
185+
186+
Atom feed ([`Root`][root]).
180187

181-
List of [`Entry`][entry] objects.
188+
### `rss(channel, data)`
189+
190+
Build an [RSS][rss-spec] feed.
191+
192+
###### Parameters
193+
194+
* `channel` ([`Channel`][channel])
195+
— data on the feed (the group of items)
196+
* `data` ([`Array<Entry>`][entry], optional)
197+
— list of entries
182198

183199
###### Returns
184200

185-
[xast][] root ([`Root`][root]).
201+
RSS feed ([`Root`][root]).
186202

187-
### `atom(channel, data)`
203+
### `Author`
204+
205+
Author object (TypeScript type).
206+
207+
##### Fields
188208

189-
Build an Atom feed.
190-
Same API as `rss` otherwise.
209+
###### `name`
210+
211+
Name (`string`, **required**, example: `'Acme, Inc.'` or `'Jane Doe'`).
212+
213+
###### `email`
214+
215+
Email address (`string`, optional, ,example: `john@example.org`)
216+
217+
###### `url`
218+
219+
URL to author (`string`, optional, example: `'https://example.org/john'`).
220+
221+
`url` is used in `atom`, not in `rss`.
191222

192223
### `Channel`
193224

194-
Data on the feed (the group of items).
225+
Data on the feed (the group of items) (TypeScript type).
195226

196-
###### `channel.title`
227+
##### Fields
228+
229+
###### `title`
197230

198231
Title of the channel (`string`, **required**, example: `Zimbabwe | The
199232
Guardian`).
200233

201-
###### `channel.url`
234+
###### `url`
202235

203236
Full URL to the *site* (`string`, **required**, example:
204237
`'https://www.theguardian.com/world/zimbabwe'`).
205238

206-
###### `channel.feedUrl`
239+
###### `feedUrl`
207240

208241
Full URL to this channel (`string?`, example: `'https://www.adweek.com/feed/'`).
242+
209243
Make sure to pass different ones to `rss` and `atom` when you build both!
244+
210245
You *should* define this.
211246

212-
###### `channel.description`
247+
###### `description`
213248

214249
Short description of the channel (`string?`, example: `Album Reviews`).
250+
215251
You *should* define this.
216252

217-
###### `channel.lang`
253+
###### `lang`
218254

219255
[BCP 47][bcp47] language tag representing the language of the whole channel
220256
(`string?`, example: `'fr-BE'`).
221-
You *should* define this.
222257

223-
###### `channel.author`
258+
You *should* define this.
224259

225-
Optional author of the whole channel.
226-
Either `string`, in which case it’s as passing `{name: string}`.
227-
Or an object with the following fields:
260+
###### `author`
228261

229-
* `name` (`string`, example: `'Acme, Inc.'` or `'Jane Doe'`)
230-
* `email` (`string?`, example: `john@example.org`)
231-
* `url` (`string?`, example: `'https://example.org/john'`)
262+
Optional author of the whole channel (`string` or [`Author`][author]).
232263

233-
`url` is used in `atom`, not in `rss`.
264+
Either `string`, in which case it’s as passing `{name: string}`.
265+
Or an author object.
234266

235-
###### `channel.tags`
267+
###### `tags`
236268

237269
Categories of the channel (`Array<string>?`, example: `['JavaScript',
238270
'React']`).
239271

272+
### `Enclosure`
273+
274+
Media (TypeScript type).
275+
276+
##### Fields
277+
278+
###### `url`
279+
280+
Full URL to the resource (`string`, **required**, example:
281+
`'http://dallas.example.com/joebob_050689.mp3'`).
282+
283+
###### `size`
284+
285+
Resource size in bytes (`number`, **required**, example: `24986239`).
286+
287+
###### `type`
288+
289+
Mime type of the resource (`string`, **required**, example: `'audio/mpeg'`).
290+
240291
### `Entry`
241292

242-
Data on a single item.
293+
Data on a single item (TypeScript type).
294+
295+
##### Fields
243296

244-
###### `entry.title`
297+
###### `title`
245298

246299
Title of the item (`string?`, example: `'Playboi Carti: Whole Lotta Red'`).
300+
247301
Either `title`, `description`, or `descriptionHtml` must be set.
248302

249-
###### `entry.description`
303+
###### `description`
250304

251305
Either the whole post or an excerpt of it (`string?`, example: `'Lorem'`).
306+
252307
Should be plain text.
253308
`descriptionHtml` is preferred over plain text `description`.
309+
254310
Either `title`, `description`, or `descriptionHtml` must be set.
255311

256-
###### `entry.descriptionHtml`
312+
###### `descriptionHtml`
257313

258314
Either the whole post or an excerpt of it (`string?`, example: `'<p>Lorem</p>'`).
315+
259316
Should be serialized HTML.
260317
`descriptionHtml` is preferred over plain text `description`.
318+
261319
Either `title`, `description`, or `descriptionHtml` must be set.
262320

263-
###### `entry.author`
321+
###### `author`
322+
323+
Entry version of `channel.author`.
264324

265-
Entry version of [`channel.author`][channel-author].
266325
You *should* define this.
326+
267327
For `atom`, it is required to either set `channel.author` or set `author` on all
268328
entries.
269329

270-
###### `entry.url`
330+
###### `url`
271331

272332
Full URL of this entry on the *site* (`string?`, example:
273333
`'https://pitchfork.com/reviews/albums/roberta-flack-first-take'`).
274334

275-
###### `entry.published`
335+
###### `published`
276336

277337
When the entry was first published (`Date` or value for `new Date(x)`,
278338
optional).
279339

280-
###### `entry.modified`
340+
###### `modified`
281341

282342
When the entry was last modified (`Date` or value for `new Date(x)`, optional).
283343

284-
###### `entry.tags`
344+
###### `tags`
285345

286346
Categories of the entry (`Array<string>?`, example: `['laravel',
287347
'debugging']`).
288348

289-
###### `entry.enclosure`
349+
###### `enclosure`
290350

291-
An enclosure, such as an image or audio, is an object with the following fields:
292-
293-
* `url` (`string`, example: `'http://dallas.example.com/joebob_050689.mp3'`)
294-
— full URL to the resource
295-
* `size` (`number`, example: `24986239`)
296-
— resource size in bytes
297-
* `type` (`string`, example: `'audio/mpeg'`)
298-
— mime type of the resource
351+
Attached media ([`Enclosure?`][enclosure]).
299352

300353
## Types
301354

302355
This package is fully typed with [TypeScript][].
303-
It exports the additional types `Author`, `Enclosure`, `Channel`, and `Entry`.
356+
It exports the additional types [`Author`][author], [`Channel`][channel],
357+
[`Enclosure`][enclosure], and [`Entry`][entry].
304358

305359
## Compatibility
306360

@@ -334,7 +388,7 @@ abide by its terms.
334388

335389
## License
336390

337-
[MIT][license] © [Titus Wormer][author]
391+
[MIT][license] © [Titus Wormer][wooorm]
338392

339393
<!-- Definitions -->
340394

@@ -374,7 +428,7 @@ abide by its terms.
374428

375429
[license]: license
376430

377-
[author]: https://wooorm.com
431+
[wooorm]: https://wooorm.com
378432

379433
[health]: https://github.com/syntax-tree/.github
380434

@@ -388,14 +442,20 @@ abide by its terms.
388442

389443
[root]: https://github.com/syntax-tree/xast#root
390444

391-
[rss]: https://www.rssboard.org/rss-specification
445+
[rss-spec]: https://www.rssboard.org/rss-specification
392446

393-
[atom]: https://tools.ietf.org/html/rfc4287
447+
[atom-spec]: https://tools.ietf.org/html/rfc4287
394448

395449
[bcp47]: https://github.com/wooorm/bcp-47
396450

451+
[atom]: #atomchannel-data
452+
453+
[rss]: #rsschannel-data
454+
455+
[author]: #author
456+
397457
[channel]: #channel
398458

399-
[entry]: #entry
459+
[enclosure]: #enclosure
400460

401-
[channel-author]: #channelauthor
461+
[entry]: #entry

0 commit comments

Comments
 (0)