Add fragment links only on docs pages

Add fragment links only on docs pages and only when there is an 'id'
attribute.
This commit is contained in:
Ian Lewis
2019-11-18 22:09:48 -08:00
committed by Zach Koopmans
parent d9f1d86286
commit a253368f76
+8 -4
View File
@@ -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('&nbsp;<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('&nbsp;<a href="#'+fragment+'" class="header-link"><i class="fas fa-link"></i></a>');
}
});
}
</script>