From e8635a52be4f170b9fe3487a076c6bd4a606e383 Mon Sep 17 00:00:00 2001
From: Tim Wickberg <tim@schedmd.com>
Date: Thu, 31 Aug 2017 12:22:08 -0600
Subject: [PATCH] Docs - add canonical url to html doc pages.

---
 doc/html/header.txt    |  2 ++
 doc/html/shtml2html.py | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/doc/html/header.txt b/doc/html/header.txt
index ec20350be60..75fc1f40853 100644
--- a/doc/html/header.txt
+++ b/doc/html/header.txt
@@ -6,6 +6,8 @@
 
 	<title>Slurm Workload Manager</title>
 
+	<!--#canonical-->
+
 	<link rel="shortcut icon" href="favicon.ico" />
 
 	<link rel="stylesheet" type="text/css" href="fonts.css" />
diff --git a/doc/html/shtml2html.py b/doc/html/shtml2html.py
index 2c7e5cdbab0..0b03182b807 100755
--- a/doc/html/shtml2html.py
+++ b/doc/html/shtml2html.py
@@ -5,9 +5,14 @@ import sys
 import os
 import codecs
 
+canonical_url = 'https://slurm.schedmd.com/'
+
 include_pat = r'(<!--\s*#include\s*virtual\s*=\s*"([^"]+)"\s*-->)'
 include_regex = re.compile(include_pat)
 
+canonical_pat = r'(<!--\s*#canonical\s*-->)'
+canonical_regex = re.compile(canonical_pat)
+
 url_pat = r'(\s+href\s*=\s*")([^"#]+)(#[^"]+)?(")'
 url_regex = re.compile(url_pat)
 
@@ -15,6 +20,7 @@ version_pat = r'(@SLURM_VERSION@)'
 version_regex = re.compile(version_pat)
 
 dirname = ''
+newfilename = ''
 
 def include_virtual(matchobj):
     global dirname
@@ -30,6 +36,10 @@ def include_virtual(matchobj):
     else:
         return matchobj.group(0)
 
+def canonical_rewrite(matchobj):
+    global newfilename
+    return '<link rel="canonical" href="' + canonical_url + newfilename + '" />'
+
 def url_rewrite(matchobj):
     global dirname
     if dirname:
@@ -73,6 +83,7 @@ for filename in files:
     for line in shtml.readlines():
         line = include_regex.sub(include_virtual, line)
         line = version_regex.sub(version_rewrite, line)
+        line = canonical_regex.sub(canonical_rewrite, line)
         line = url_regex.sub(url_rewrite, line)
         html.write(line)
 
-- 
GitLab