-
Notifications
You must be signed in to change notification settings - Fork 23
/
rules.js
33 lines (30 loc) · 1006 Bytes
/
rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Rule = require("html-validate").Rule;
class HtmlTitle extends Rule {
documentation(context) {
return {
description: "Title of the page must be defined"
};
}
setup() {
this.on("dom:ready", event => {
const title = event.document.querySelector('html head title');
if (title === null) {
this.report(event.document.querySelector('html'), "Missing <title> tag in the <head>");
}
else if (!title.textContent || title.textContent.trim().length === 0) {
this.report(title, "No title specified");
}
else if (title.textContent[0] === '-') {
this.report(title, "Title starts with the dash `-`, add the `title` front matter to the Hugo content");
}
else if (title.textContent.startsWith('Untitled')) {
this.report(title, "Title starts with the `Untitled` make sure that the Asciidoc file starts with level 1 heading");
}
});
}
}
module.exports = {
rules: {
"hop/title": HtmlTitle
}
};