import Rule from './Rule.js' import { extensionFilter, getContent } from '../helpers.js' import { getTitle } from '../parser.js' export default class TitleLength extends Rule { initialize() { this.minLength = 30 this.maxLength = 70 this.filenames = extensionFilter(this.filenames, 'html'); } report() { return { ...super.report(), ...{ issueDescription: `The should contain between ${this.minLength} and ${this.maxLength} characters.`, issueReferences: ['https://moz.com/learn/seo/title-tag', 'https://www.authorityhacker.com/seo-title-tags/', 'https://www.codeur.com/blog/seo-optimiser-title/'] } } } check() { for (const filename of this.filenames) { const content = getContent(filename); const title = getTitle(content) if (this.test(title)) { this.issueCount++ const issue = { url: filename.replace(this.options.directory, ''), title: title } this.issues = [...this.issues, ...[issue]] } } return this.report() } }