-
Notifications
You must be signed in to change notification settings - Fork 168
/
rules.js
57 lines (52 loc) · 1.62 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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");
}
});
}
}
class RelativeLinks extends Rule {
documentation(context) {
return {
description: "Within the Camel site we should use only relative links"
};
}
setup() {
this.on("dom:ready", event => {
const anchors = event.document.querySelectorAll('a');
if (anchors === null) {
return;
}
anchors.forEach(a => {
const href = a.getAttribute("href");
if (href && href.value.startsWith("https://camel.apache.org")) {
this.report(a, `For links within camel.apache.org use relative links, found: ${href}`);
}
});
});
}
}
module.exports = {
rules: {
"camel/title": HtmlTitle,
"camel/relative-links": RelativeLinks
}
};