diff options
author | Jan Raasch <jan@janraasch.com> | 2020-09-07 15:23:19 +0300 |
---|---|---|
committer | Jan Raasch <jan@janraasch.com> | 2020-09-07 15:23:19 +0300 |
commit | f483bbaea465e1f450b3811c8f7aefa22f0f430b (patch) | |
tree | 0f5219410642f19feb0b30655cbda949850cfd1c | |
parent | f9332ad4f4292af14ff9b57a1165bb43da6278d1 (diff) |
fix(site-menu): use anchorized title
fixes https://github.com/janraasch/hugo-scroll/pull/6.
This way we put less burden on JavaScript / jQuery, which is always good :-D.
-rw-r--r-- | layouts/index.html | 4 | ||||
-rw-r--r-- | static/js/index.js | 3 |
2 files changed, 3 insertions, 4 deletions
diff --git a/layouts/index.html b/layouts/index.html index edea3f3..676b727 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -9,7 +9,7 @@ {{ with .Params.header_subheadline }}<h2 class="blog-description">{{ . }}</h2>{{ end }} {{ range where $sections ".Params.header_menu" "eq" true }} - <a class='btn site-menu' data-title='{{ .Title }}'>{{ .Title }}</a> + <a class='btn site-menu' data-title-anchor='{{ anchorize .Title }}'>{{ .Title }}</a> {{ end }} <i id='header-arrow' class="fa fa-angle-down"></i> </div> @@ -22,7 +22,7 @@ </div> {{ range $index_val, $elem_val := $sections }} <div class='post-holder'> - <article class='post {{ if eq $index_val 0 }}first{{ else }}{{ if eq (add $index_val 1) (len $sections) }}last{{ end }}{{ end }}'> + <article id='{{ anchorize .Title }}' class='post {{ if eq $index_val 0 }}first{{ else }}{{ if eq (add $index_val 1) (len $sections) }}last{{ end }}{{ end }}'> <header class="post-header"> <h2 class="post-title">{{ .Title }}</h2> </header> diff --git a/static/js/index.js b/static/js/index.js index 3a31efd..ac7641e 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -41,7 +41,7 @@ var $sitehead = $('#site-head'); }); $('a.btn.site-menu').click(function (e) { - srcToAnchorWithTitle($(e.target).data('title').toLowerCase().split(' ').join('-')); + srcToAnchorWithTitle($(e.target).data('title-anchor')); }); $('#header-arrow').click(function () { srcTo($first); @@ -51,7 +51,6 @@ var $sitehead = $('#site-head'); var t = $(this).text(); var index = $(this).parents('.post-holder').index(); $fnav.append("<a class='fn-item' item_index='"+index+"'>"+t+"</a>") - $(this).parents('article').attr('id',t.toLowerCase().split(' ').join('-')); $('.fn-item').click(function () { var i = $(this).attr('item_index'); var s = $(".post[item_index='"+i+"']"); |