Skip to contents

Analyses a `rel=canonical` data frame and returns a diagnostic report covering chain lengths, loops, conflicting sources (a page declaring multiple distinct canonicals), self-referencing canonicals, and terminal destinations. Mirrors [audit_redirects()] for the canonical signal; useful as a pre-flight check before passing `canonicals_df` to [pagerank()].

Declared canonicals are an **advisory** signal, distinct from enforced 3xx redirects. To see how the two interact – which one wins on a shared source, and which canonicals are ignored because their source also redirects – use [audit_fold()].

Usage

audit_canonicals(
  canonicals_df,
  edge_list_df = NULL,
  canonical_from_col = "from",
  canonical_to_col = "to",
  edge_from_col = "from",
  edge_to_col = "to"
)

Arguments

canonicals_df

A data frame of declared canonical links, pairing a source URL with the canonical it declares.

edge_list_df

Optional data frame of edges. If provided, orphaned canonicals (sources not present in the edge list) are identified.

canonical_from_col, canonical_to_col

From/to columns in `canonicals_df`. Default `"from"` / `"to"`.

edge_from_col, edge_to_col

From/to columns in `edge_list_df`. Default `"from"` / `"to"`.

Value

A list with class `"canonical_audit"` mirroring the structure of [audit_redirects()]: `n_rules`, `n_self_refs`, `self_refs`, `n_conflicts`, `conflicts`, `n_loops`, `loops`, `chains`, `max_chain_length`, and (when `edge_list_df` is given) `orphaned_redirects` (orphaned canonical sources).

See also

[audit_redirects()], [audit_fold()], [build_fold_map()]

Examples

canonicals <- data.frame(
  from = c("http://a?x=1", "http://b", "http://c"),
  to = c("http://a", "http://canon", "http://c")
)
audit_canonicals(canonicals)
#> === Canonical Audit Report ===
#> 
#> Total rules (after NA removal): 3 
#> Self-referencing canonicals:     1 
#> Conflicting sources:             0 
#> Canonical loops:                 0 
#> Max chain length:                1 
#> 
#> --- Self-referencing canonicals ---
#>      from       to
#>  http://c http://c