38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import Rule from './Rule.js'
|
|
import { extensionFilter, getContent, getTitle } from '../helpers.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 <title> 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()
|
|
}
|
|
}
|