pyseoa-ts
Version:
SEO analysis tools for the web, ported from pyseoa (Python) to TypeScript
33 lines (32 loc) • 889 B
JavaScript
import * as cheerio from 'cheerio';
export function analyzeKeywords(html) {
const $ = cheerio.load(html);
const content = $('meta[name="keywords"]').attr('content');
if (!content || content.trim() === '')
return {
score: 0,
message: "Missing or empty keywords meta tag.",
keywords: [],
};
const keywords = content
.split(",")
.map(k => k.trim())
.filter(k => k.length > 0);
if (keywords.length < 3)
return {
score: 1,
message: "Too few keywords.",
keywords: keywords,
};
if (keywords.length > 10)
return {
score: 2,
message: "Too many keywords.",
keywords: keywords,
};
return {
score: 3,
message: "Keywords count is optimal.",
keywords: keywords,
};
}