This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-website.git

commit 16c711dba7f048b3311b1f9552b0a87d2320b21a
Author: Zoran Regvart <zregv...@apache.org>
AuthorDate: Mon Jul 29 20:10:01 2019 +0200

    chore: add HTML title validation
    
    Ref CAMEL-13798
---
 .htmlvalidate.json |  7 ++++++-
 package.json       |  2 +-
 rules.js           | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/.htmlvalidate.json b/.htmlvalidate.json
index a2b5ef7..7d21cd6 100644
--- a/.htmlvalidate.json
+++ b/.htmlvalidate.json
@@ -2,12 +2,17 @@
   "extends": [
     "htmlvalidate:recommended"
   ],
+  "plugins": [
+    "./rules.js"
+  ],
   "rules": {
     "attr-quotes": "off",
     "wcag/h30": "off",
     "no-inline-style": "off",
     "element-required-attributes": "off",
-    "prefer-tbody": "off"
+    "prefer-tbody": "off",
+    "long-title": "off",
+    "camel/title": "error"
   }
 }
 
diff --git a/package.json b/package.json
index 8d82049..64b9b9b 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
     "preview": "hugo server -D",
     "check:xref": "antora --generator @antora/xref-validator site.yml",
     "check:links": "link-checker --disable-external --mkdocs --allow-hash-href 
public",
-    "check:html": "html-validate 'public/**/*.html'",
+    "check:html": "html-validate 'public/*/**/*.html' 
'public/!(google)*.html'",
     "checks": "run-s check:*"
   },
   "devDependencies": {
diff --git a/rules.js b/rules.js
new file mode 100644
index 0000000..3dce28d
--- /dev/null
+++ b/rules.js
@@ -0,0 +1,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: {
+    "camel/title": HtmlTitle
+  }
+};

Reply via email to