UNPKG

pyseoa-ts

Version:

SEO analysis tools for the web, ported from pyseoa (Python) to TypeScript

22 lines (21 loc) 578 B
import * as cherrio from 'cheerio'; export function analyzeCanonical(html) { const $ = cherrio.load(html); const link = $('link[rel="canonical"]').attr("href"); if (link === undefined) return { score: 0, message: "Missing canonical link.", }; const canonicalUrl = link.trim(); if (!canonicalUrl) return { score: 1, message: "Canonical link is empty.", }; return { score: 3, message: "Canonical link is present.", canonicalUrl: canonicalUrl, }; }