UNPKG

pyseoa-ts

Version:

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

34 lines (33 loc) 803 B
// src/analyzer/title.ts import * as cheerio from "cheerio"; export function analyzeTitle(html) { const $ = cheerio.load(html); const titleTag = $("title").first(); const titleText = titleTag.text().trim(); if (!titleText) { return { score: 0, message: "Missing or empty <title> tag.", }; } const length = titleText.length; if (length < 20) { return { score: 1, message: "Title is to short.", title: titleText, }; } if (length > 70) { return { score: 2, message: "Title is too long.", title: titleText, }; } return { score: 3, message: "Title length is optimal.", title: titleText, }; }