diff options
author | Ian Lewis <ianmlewis@gmail.com> | 2019-11-12 19:00:30 -0500 |
---|---|---|
committer | Zach Koopmans <zkoopmans@gmail.com> | 2019-11-18 22:09:48 -0800 |
commit | a253368f7695c33ce88a2363426c710f0069500e (patch) | |
tree | 3f0787932ef3195fd2f4c2f041c53328cba96aca | |
parent | d9f1d86286a2a376f554d43a69c9ee849f1b83ab (diff) |
Add fragment links only on docs pages
Add fragment links only on docs pages and only when there is an 'id'
attribute.
-rw-r--r-- | layouts/partials/scripts.html | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 52c7c327f..08f400598 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -12,8 +12,12 @@ {{ partial "hooks/body-end.html" . }} <script type="text/javascript"> - $("body.td-page,body.td-section").find("main h2,h3,h4").each(function() { - var fragment = $(this).attr('id'); - $(this).append(' <a href="#'+fragment+'" class="header-link"><i class="fas fa-link"></i></a>'); - }); + if (location.pathname == "/docs" || location.pathname.startsWith("/docs/")) { + $("body.td-page,body.td-section").find("main h2,h3,h4").each(function() { + var fragment = $(this).attr('id'); + if (fragment !== undefined && fragment !== "") { + $(this).append(' <a href="#'+fragment+'" class="header-link"><i class="fas fa-link"></i></a>'); + } + }); + } </script> |