github.com/jbramsden/hugo@v0.47.1/docs/themes/gohugoioTheme/src/js/anchorforid.js (about)

     1  /**
     2  * Anchor for ID BPNY
     3  **/
     4  var anchorForId = function (id) {
     5    var anchor = document.createElement("a");
     6    anchor.className = "header-link";
     7    anchor.href      = "#" + id;
     8    anchor.innerHTML = '  <svg class="fill-current o-60 hover-accent-color-light" height="22px" viewBox="0 0 24 24" width="22px" xmlns="http://www.w3.org/2000/svg"><path d="M0 0h24v24H0z" fill="none"/><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/></svg>';
     9    return anchor;
    10  };
    11  
    12  var linkifyAnchors = function (level, containingElement) {
    13    var headers = containingElement.getElementsByTagName("h" + level);
    14    for (var h = 0; h < headers.length; h++) {
    15      var header = headers[h];
    16  
    17      if (typeof header.id !== "undefined" && header.id !== "") {
    18        header.appendChild(anchorForId(header.id));
    19      }
    20    }
    21  };
    22  
    23  
    24  document.onreadystatechange = function () {
    25    if (this.readyState === "complete") {
    26      var contentBlock = document.getElementsByClassName("prose")[0]
    27      if (!contentBlock) {
    28        return;
    29      }
    30      for (var level = 2; level <= 4; level++) {
    31        linkifyAnchors(level, contentBlock);
    32      }
    33    }
    34  };