feed.ts

view source

Declarations
#

7 declarations

compare_feed_items
#

feed.ts view source

(a: { id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; }, b: { id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; }): number import {compare_feed_items} from '@fuzdev/fuz_blog/feed.js';

Compares feed items newest first: by date_published descending, then by id descending with numeric collation (so https://example.com/blog/10 sorts before https://example.com/blog/9), then by id code units. For valid FeedDatetime values it's a total order, so the sort is deterministic for any input order. create_atom_feed and BlogPostList both order items with it.

a

b

returns

number

create_atom_feed
#

feed.ts view source

(data: { id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { ...; }[]; atom: { ...; }; }): string import {create_atom_feed} from '@fuzdev/fuz_blog/feed.js';

Renders a feed as Atom XML, entries newest first (see compare_feed_items). The feed-level <updated> is the latest date_modified or date_published across the items. Atom requires the element, so a feed with no items gets the Unix epoch, 1970-01-01T00:00:00.000Z - a fixed value keeps the generated feed.xml deterministic, where the current time would change it on every gro gen. Expects parsed Feed data; an unparseable date throws.

data

type Feed

returns

string

Feed
#

feed.ts view source

value + type

{ id: string; title: string; home_page_url: string; description: string; icon: string; favicon: string; author: { name: string; url?: string | undefined; email?: string | undefined; }; items: { id: string; ... 5 more ...; tags?: string[] | undefined; }[]; atom: { ...; }; } import {Feed} from '@fuzdev/fuz_blog/feed.js';

A blog's feed data, rendered to Atom by create_atom_feed. Field names follow JSON Feed 1.1 where the two overlap, but the shape is not a conformant JSON Feed: it has a feed-level id (Atom's), a single author with email, the Atom feed_url under an unprefixed atom key, no version, and items with a summary but no content_html or content_text. Publishing feed.json means mapping to the spec, not serializing this as is. https://www.jsonfeed.org/version/1.1/

id

type string

title

type string

home_page_url

type string

description

type string

icon

type string

favicon

type string

author

type { name: string; url?: string | undefined; email?: string | undefined; }

items

type FeedItem[]

atom

type { feed_url: string; }

FeedDatetime
#

feed.ts view source

value + type

string import {FeedDatetime} from '@fuzdev/fuz_blog/feed.js';

An ISO 8601 UTC datetime string like 2024-07-15T00:00:00.000Z, the form Date.prototype.toISOString writes. The date must exist on the calendar, seconds are required, fractional seconds take any number of digits, and the offset must be Z. The output is the input unchanged.

FeedItem
#

feed.ts view source

value + type

{ id: string; title: string; url: string; date_published: string; date_modified: string; summary: string; tags?: string[] | undefined; } import {FeedItem} from '@fuzdev/fuz_blog/feed.js';

id

type string

title

type string

url

type string

date_published

type string

date_modified

type string

summary

type string

tags?

type string[]

FeedUrl
#

feed.ts view source

value + type

string import {FeedUrl} from '@fuzdev/fuz_blog/feed.js';

An absolute URL as fuz_util's Url takes it, with no surrounding whitespace: the text is kept as written, so padding would reach the generated feed, where it fails here instead.

sort_feed_items
#

feed.ts view source

<T extends FeedItem>(items: readonly T[]): T[] import {sort_feed_items} from '@fuzdev/fuz_blog/feed.js';

Returns a copy of items sorted newest first by compare_feed_items.

items

type readonly T[]

returns

T[]

generics

sort_feed_items<T extends FeedItem>
T
constraint FeedItem

Imported by
#