Expand description
Decide whether a link on a served page is actually followed.
Three separate signals answer that question and they have to be read together:
- the link’s own
relattribute —nofollow,ugcandsponsoredall withhold the follow; - the page’s
<meta name="robots">content, whosenofollowapplies to every link on the page; - the
X-Robots-Tagresponse header, which says the same things from outside the HTML and may be scoped to a named user agent.
Reading only the first is the common mistake: a link with no rel at all is still not
followed if the response carried X-Robots-Tag: nofollow. This crate parses all three
and combines them most-restrictive-wins, then tells you which signal withheld the follow.
§Example
use followability::{PageDirectives, Reason, audit_link};
// rel is absent, but the header withholds the follow anyway
let page = PageDirectives::new()
.with_x_robots_tag("nofollow");
let verdict = audit_link(None, &page, None);
assert!(!verdict.followed());
assert_eq!(verdict.reason, Some(Reason::XRobotsTagNofollow));
// rel="noopener noreferrer" is still a followed link
let clean = PageDirectives::new();
assert!(audit_link(Some("noopener noreferrer"), &clean, None).followed());
// ugc and sponsored withhold it just as nofollow does
assert_eq!(
audit_link(Some("ugc"), &clean, None).reason,
Some(Reason::RelUgc)
);Parsing rules follow the HTML rel token grammar (ASCII case-insensitive,
whitespace-separated; commas are also tolerated because real pages use them) and the
documented robots directives, including none as shorthand for noindex, nofollow
and the optional user-agent prefix on X-Robots-Tag.
No dependencies, no I/O, no unsafe. Fetching the page is your job; this crate reads what came back.
Written for the link pipeline at https://handsofflinks.com/, which re-fetches every published page and reads the attribute off the served HTML before a row may say LIVE.
Structs§
- Link
Audit - The combined verdict for one link on one page.
- Page
Directives - Everything the page itself says, from its meta tag and its response headers.
- Rel
- A parsed
relattribute. - Robots
Directives - Directives parsed from a robots meta content string or an
X-Robots-Tagvalue. - XRobots
Tag - One
X-Robots-Tagheader value, with its optional user-agent scope.
Enums§
- Reason
- Why a link was not followed.
Functions§
- audit_
link - Audit one link: its
rel, the page’s directives, and the crawler you care about.