43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import Rule from './Rule.js'
|
|
import { extensionFilter, getContent } from '../helpers.js'
|
|
import { getTitle } from '../parser.js'
|
|
|
|
export default class TitleUnique extends Rule {
|
|
initialize() {
|
|
this.filenames = extensionFilter(this.filenames, 'html');
|
|
}
|
|
|
|
report() {
|
|
return {
|
|
...super.report(),
|
|
...{
|
|
issueTitle: `The <title> should be unique for every page, ${this.issueCount} pages are concerned.`,
|
|
issueDescription: `You should change title on:`,
|
|
issueReferences: ['https://moz.com/learn/seo/title-tag']
|
|
}
|
|
}
|
|
}
|
|
|
|
check() {
|
|
let titles = {}
|
|
for (const filename of this.filenames) {
|
|
const content = getContent(filename);
|
|
const title = getTitle(content)
|
|
titles[title] = titles[title] ? [...titles[title], ...[filename]] : [filename]
|
|
}
|
|
|
|
for (const title in titles) {
|
|
if (titles[title].length > 1) {
|
|
this.issueCount += titles[title].length
|
|
const issue = {
|
|
title: title,
|
|
url: titles[title]
|
|
}
|
|
this.issues = [...this.issues, ...[issue]]
|
|
}
|
|
}
|
|
|
|
return this.report()
|
|
}
|
|
}
|