findCanonical
The main function to find the canonical URL for a feed.
findCanonical()
Finds the canonical URL for a given feed URL by fetching, parsing, and testing URL candidates.
Parameters
| Parameter | Type | Description |
|---|---|---|
inputUrl | string | The feed URL to canonicalize |
options | object | Optional configuration |
Options
| Option | Type | Default | Description |
|---|---|---|---|
parser | ParserAdapter | defaultParser | Custom feed parser. See Feed Parsing |
fetchFn | FetchFn | defaultFetch | Custom fetch function. See Data Fetching |
existsFn | ExistsFn | — | Database lookup function. See Using Callbacks |
tiers | Tier[] | defaultTiers | URL normalization tiers. See URL Tiers |
rewrites | Rewrite[] | [] | URL rewrites. See URL Rewrites |
probes | Probe[] | — | URL probes for testing alternate URL forms. See URL Probes |
stripQueryParams | string[] | defaultStrippedParams | Query params to strip |
onFetch | OnFetchFn | — | Callback after each fetch. See Using Callbacks |
onMatch | OnMatchFn | — | Callback when URL matches. See Using Callbacks |
onExists | OnExistsFn | — | Callback when URL exists. See Using Callbacks |
Returns
Promise<string | undefined> — The canonical URL, or undefined if the feed is invalid or unreachable.
Example
typescript
import { findCanonical } from 'feedcanon'
const url = await findCanonical('https://www.example.com/feed/?utm_source=rss')
// 'https://example.com/feed'