From 7eca2db6fe7ded3bc6a3a85d1881134edb1bc4ff Mon Sep 17 00:00:00 2001 From: John Bowdre Date: Tue, 16 Jan 2024 14:12:57 -0600 Subject: [PATCH] add scroll-to-top button --- assets/js/back-to-top.js | 1 + config/_default/hugo.toml | 2 +- layouts/_default/index.json | 7 ------- layouts/partials/footer.html | 12 ++++++++++++ 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 assets/js/back-to-top.js delete mode 100644 layouts/_default/index.json diff --git a/assets/js/back-to-top.js b/assets/js/back-to-top.js new file mode 100644 index 0000000..6be04a7 --- /dev/null +++ b/assets/js/back-to-top.js @@ -0,0 +1 @@ +"use strict";function addBackToTop(){var o,t,e,n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=i.backgroundColor,d=void 0===r?"#000":r,a=i.cornerOffset,c=void 0===a?20:a,s=i.diameter,l=void 0===s?56:s,u=i.ease,p=void 0===u?function(o){return.5*(1-Math.cos(Math.PI*o))}:u,m=i.id,h=void 0===m?"back-to-top":m,b=i.innerHTML,v=void 0===b?'':b,f=i.onClickScrollTo,x=void 0===f?0:f,w=i.scrollContainer,g=void 0===w?document.body:w,k=i.scrollDuration,y=void 0===k?100:k,T=i.showWhenScrollTopIs,M=void 0===T?1:T,z=i.size,E=void 0===z?l:z,C=i.textColor,L=void 0===C?"#fff":C,N=i.zIndex,I=void 0===N?1:N,A=g===document.body,B=A&&document.documentElement;o=Math.round(.43*E),t=Math.round(.29*E),e="#"+h+"{background:"+d+";-webkit-border-radius:50%;-moz-border-radius:50%;border-radius:50%;bottom:"+c+"px;-webkit-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);-moz-box-shadow:0 2px 5px 0 rgba(0,0,0,.26);box-shadow:0 2px 5px 0 rgba(0,0,0,.26);color:"+L+";cursor:pointer;display:block;height:"+E+"px;opacity:1;outline:0;position:fixed;right:"+c+"px;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-transition:bottom .2s,opacity .2s;-o-transition:bottom .2s,opacity .2s;-moz-transition:bottom .2s,opacity .2s;transition:bottom .2s,opacity .2s;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:"+E+"px;z-index:"+I+"}#"+h+" svg{display:block;fill:currentColor;height:"+o+"px;margin:"+t+"px auto 0;width:"+o+"px}#"+h+".hidden{bottom:-"+E+"px;opacity:0}",(n=document.createElement("style")).appendChild(document.createTextNode(e)),document.head.insertAdjacentElement("afterbegin",n);var D=function(){var o=document.createElement("div");return o.id=h,o.className="hidden",o.innerHTML=v,o.addEventListener("click",function(o){o.preventDefault(),function(){var o="function"==typeof x?x():x,t=window,e=t.performance,n=t.requestAnimationFrame;if(y<=0||void 0===e||void 0===n)return q(o);var i=e.now(),r=j(),d=r-o;n(function o(t){var e=Math.min((t-i)/y,1);q(r-Math.round(p(e)*d)),e<1&&n(o)})}()}),document.body.appendChild(o),o}(),H=!0;function S(){j()>=M?function(){if(!H)return;D.className="",H=!1}():function(){if(H)return;D.className="hidden",H=!0}()}function j(){return g.scrollTop||B&&document.documentElement.scrollTop||0}function q(o){g.scrollTop=o,B&&(document.documentElement.scrollTop=o)}(A?window:g).addEventListener("scroll",S),S()} \ No newline at end of file diff --git a/config/_default/hugo.toml b/config/_default/hugo.toml index 7d181e6..e85d6cf 100644 --- a/config/_default/hugo.toml +++ b/config/_default/hugo.toml @@ -11,7 +11,7 @@ enableInlineShortcodes = true # sectionPagesMenu = "main" [outputs] - home = ['html', 'rss', 'json'] + home = ['html', 'rss'] section = ['html'] taxonomy = ['html',] term = ['html', 'rss'] diff --git a/layouts/_default/index.json b/layouts/_default/index.json deleted file mode 100644 index fdb9ebc..0000000 --- a/layouts/_default/index.json +++ /dev/null @@ -1,7 +0,0 @@ -{{- $.Scratch.Add "index" slice -}} -{{- range .Site.Pages -}} - {{- if ne .Type "search" -}} - {{- $.Scratch.Add "index" (dict "title" .Title "body" .Plain "link" .Permalink "section" .Section "tags" .Params.tags) -}} - {{- end -}} -{{- end -}} -{{- jsonify (uniq ($.Scratch.Get "index")) -}} \ No newline at end of file diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 45819fd..0b70a07 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -3,7 +3,19 @@

{"powered_by": [{{- range $i, $link := .Site.Params.powerLinks }}{{ if $i }}, {{ end }}"{{ $link.title }}"{{ end }}]}
<view source>

+ +{{ $jsToTop := resources.Get "js/back-to-top.js" | minify }} + + + + {{ partial "search-index.html" .}} + + {{ if (findRE "