Skip to content

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

ParameterTypeDescription
inputUrlstringThe feed URL to canonicalize
optionsobjectOptional configuration

Options

OptionTypeDefaultDescription
parserParserAdapterdefaultParserCustom feed parser. See Feed Parsing
fetchFnFetchFndefaultFetchCustom fetch function. See Data Fetching
existsFnExistsFnDatabase lookup function. See Using Callbacks
tiersTier[]defaultTiersURL normalization tiers. See URL Tiers
rewritesRewrite[][]URL rewrites. See URL Rewrites
probesProbe[]URL probes for testing alternate URL forms. See URL Probes
stripQueryParamsstring[]defaultStrippedParamsQuery params to strip
onFetchOnFetchFnCallback after each fetch. See Using Callbacks
onMatchOnMatchFnCallback when URL matches. See Using Callbacks
onExistsOnExistsFnCallback 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'