UNPKG

pyseoa-ts

Version:

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

33 lines (32 loc) 897 B
import * as cheerio from 'cheerio'; export function analyzeMetaDescription(html) { const $ = cheerio.load(html); const metaTag = $('meta[name="description"]').attr("content"); if (!metaTag || metaTag.trim() === '') { return { score: 0, message: "Missing or empty meta description.", }; } const description = metaTag.trim(); const length = description.length; if (length < 50) { return { score: 1, message: "Meta description is too short.", description: description, }; } if (length > 160) { return { score: 2, message: "Meta description is too long.", description: description, }; } return { score: 3, message: "Meta description length is optimal.", description: description, }; }