Browse Source

config for hide header links

zwbetz-gh 5 years ago
parent
commit
e9a24f95ec
2 changed files with 23 additions and 21 deletions
  1. 22 21
      assets/js/template-dom-scripts.js
  2. 1 0
      exampleSite/config.yaml

+ 22 - 21
assets/js/template-dom-scripts.js

@@ -50,34 +50,35 @@
   })
 }());
 
-/* Add "link here" links to <h2> headings */
-(function () {
-  var headings = document.querySelectorAll('main > h2');
+{{ if not .Site.Params.hideHeaderLinks }}
+  /* Add "link here" links to <h2> headings */
+  (function () {
+    var headings = document.querySelectorAll('main > h2');
 
-  Array.prototype.forEach.call(headings, function (heading) {
-    var id = heading.getAttribute('id');
+    Array.prototype.forEach.call(headings, function (heading) {
+      var id = heading.getAttribute('id');
 
-    if (id) {
-      var newHeading = heading.cloneNode(true);
-      newHeading.setAttribute('tabindex', '-1');
+      if (id) {
+        var newHeading = heading.cloneNode(true);
+        newHeading.setAttribute('tabindex', '-1');
 
-      var container = document.createElement('div');
-      container.setAttribute('class', 'h2-container');
-      container.appendChild(newHeading);
+        var container = document.createElement('div');
+        container.setAttribute('class', 'h2-container');
+        container.appendChild(newHeading);
 
-      heading.parentNode.insertBefore(container, heading);
+        heading.parentNode.insertBefore(container, heading);
 
-      var link = document.createElement('a');
-      link.setAttribute('href', '#' + id);
-      var headingText = heading.textContent;
-      link.innerHTML = '<svg aria-hidden="true" class="link-icon" viewBox="0 0 50 50" focusable="false"> <use xlink:href="#link"></use> </svg>';
+        var link = document.createElement('a');
+        link.setAttribute('href', '#' + id);
+        link.innerHTML = '<svg aria-hidden="true" class="link-icon" viewBox="0 0 50 50" focusable="false"> <use xlink:href="#link"></use> </svg>';
 
-      container.appendChild(link);
+        container.appendChild(link);
 
-      heading.parentNode.removeChild(heading);
-    }
-  })
-}());
+        heading.parentNode.removeChild(heading);
+      }
+    })
+  }());
+{{ end }}
 
 /* Enable scrolling by keyboard of code samples */
 (function () {

+ 1 - 0
exampleSite/config.yaml

@@ -25,6 +25,7 @@ params:
   codePenUser: someUser
   katex: true
   darkThemeAsDefault: false
+  hideHeaderLinks: false
   # A list of custom css files can be provided, which must be placed inside
   # 'static/'.
   # This is useful to override just specific css classes, instead of copying