From 2164c5d6cfdbd823a293457b26ebea7144ef55fd Mon Sep 17 00:00:00 2001 From: Yochem van Rosmalen Date: Mon, 28 Oct 2024 13:36:00 +0100 Subject: [PATCH] Use instant.page instead of instantclick via hugo modules --- .gitignore | 1 + assets/instantclick.min.js | 13 ------------- go.mod | 5 +++++ go.sum | 3 +++ hugo.yml | 4 ++++ layouts/_default/baseof.html | 6 ++---- 6 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 assets/instantclick.min.js create mode 100644 go.mod create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index 586d5b9..4d36787 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.hugo_build.lock /public/ /resources/_gen/ +/vendor/ diff --git a/assets/instantclick.min.js b/assets/instantclick.min.js deleted file mode 100644 index a2539d8..0000000 --- a/assets/instantclick.min.js +++ /dev/null @@ -1,13 +0,0 @@ -/* InstantClick 3.1.0 | (C) 2014 Alexandre Dieulot | http://instantclick.io/license */ -var InstantClick=function(d,e){function w(a){var b=a.indexOf("#");return 0>b?a:a.substr(0,b)}function z(a){for(;a&&"A"!=a.nodeName;)a=a.parentNode;return a}function A(a){var b=e.protocol+"//"+e.host;if(!(b=a.target||a.hasAttribute("download")||0!=a.href.indexOf(b+"/")||-1+new Date-500||(a=z(a.target))&&A(a)&&x(a.href)}function N(a){G>+new Date-500||(a=z(a.target))&&A(a)&&(a.addEventListener("mouseout",T),H?(O=a.href,l=setTimeout(x,H)):x(a.href))}function U(a){G=+new Date;(a=z(a.target))&&A(a)&&(D?a.removeEventListener("mousedown", -M):a.removeEventListener("mouseover",N),x(a.href))}function V(a){var b=z(a.target);!b||!A(b)||1p.readyState)&&0!=p.status){q.ready=+new Date-q.start;if(p.getResponseHeader("Content-Type").match(/\/(x|ht|xht)ml/)){var a=d.implementation.createHTMLDocument("");a.documentElement.innerHTML=p.responseText.replace(//gi,"");y=a.title; -u=a.body;var b=t("receive",r,u,y);b&&("body"in b&&(u=b.body),"title"in b&&(y=b.title));b=w(r);h[b]={body:u,title:y,scrollY:b in h?h[b].scrollY:0};for(var a=a.head.children,b=0,c,g=a.length-1;0<=g;g--)if(c=a[g],c.hasAttribute("data-instant-track")){c=c.getAttribute("href")||c.getAttribute("src")||c.innerHTML;for(var e=E.length-1;0<=e;e--)E[e]==c&&b++}b!=E.length&&(F=!0)}else F=!0;m&&(m=!1,P(r))}}function L(a){d.body.addEventListener("touchstart",U,!0);D?d.body.addEventListener("mousedown",M,!0):d.body.addEventListener("mouseover", -N,!0);d.body.addEventListener("click",V,!0);if(!a){a=d.body.getElementsByTagName("script");var b,c,g,e;i=0;for(j=a.length;i+new Date-(q.start+q.display)||(l&&(clearTimeout(l),l=!1),a||(a=O),v&&(a==r||m))||(v=!0,m=!1,r=a,F=u=!1,q={start:+new Date},t("fetch"), -p.open("GET",a),p.send())}function P(a){"display"in q||(q.display=+new Date-q.start);l||!v?l&&r&&r!=a?e.href=a:(x(a),C.start(0,!0),t("wait"),m=!0):m?e.href=a:F?e.href=r:u?(h[k].scrollY=pageYOffset,m=v=!1,K(y,u,r)):(C.start(0,!0),t("wait"),m=!0)}var I=navigator.userAgent,S=-1b;b++)a[b]+"Transform"in h.style&&(k=a[b]+"Transform");var c="transition";if(!(c in h.style))for(b=0;3>b;b++)a[b]+"Transition"in -h.style&&(c="-"+a[b].toLowerCase()+"-"+c);a=d.createElement("style");a.innerHTML="#instantclick{position:"+(Q?"absolute":"fixed")+";top:0;left:0;width:100%;pointer-events:none;z-index:2147483647;"+c+":opacity .25s .1s}.instantclick-bar{background:#29d;width:100%;margin-left:-100%;height:2px;"+c+":all .25s}";d.head.appendChild(a);Q&&(m(),addEventListener("resize",m),addEventListener("scroll",m))},start:a,done:e}}(),R="pushState"in history&&(!I.match("Android")||I.match("Chrome/"))&&"file:"!=e.protocol; -return{supported:R,init:function(){if(!k)if(R){for(var a=arguments.length-1;0<=a;a--){var b=arguments[a];!0===b?J=!0:"mousedown"==b?D=!0:"number"==typeof b&&(H=b)}k=w(e.href);h[k]={body:d.body,title:d.title,scrollY:pageYOffset};for(var b=d.head.children,c,a=b.length-1;0<=a;a--)c=b[a],c.hasAttribute("data-instant-track")&&(c=c.getAttribute("href")||c.getAttribute("src")||c.innerHTML,E.push(c));p=new XMLHttpRequest;p.addEventListener("readystatechange",W);L(!0);C.init();t("change",!0);addEventListener("popstate", -function(){var a=w(e.href);a!=k&&(a in h?(h[k].scrollY=pageYOffset,k=a,K(h[a].title,h[a].body,!1,h[a].scrollY)):e.href=e.href)})}else t("change",!0)},on:function(a,b){B[a].push(b)}}}(document,location); diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5c26054 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/yochem/yochem.github.io + +go 1.23.1 + +require github.com/gohugoio/hugo-mod-jslibs/instantpage v0.5.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8d8c7ed --- /dev/null +++ b/go.sum @@ -0,0 +1,3 @@ +github.com/gohugoio/hugo-mod-jslibs/instantpage v0.5.1 h1:Aig+0MOPXiuQNZpnxOMS4uwUsnyq41JnQzGW4Gk3o7Y= +github.com/gohugoio/hugo-mod-jslibs/instantpage v0.5.1/go.mod h1:N4EUbbL7Cw4Yq+GHeK3MUSiOJQbzfuUFRyvBKvnVBR8= +github.com/instantpage/instant.page v5.1.0+incompatible/go.mod h1:GXVDktwI+K4T9o5mcK2NYDqPFxAUrB9U9goR9oG1SaI= diff --git a/hugo.yml b/hugo.yml index f832a65..b80bade 100644 --- a/hugo.yml +++ b/hugo.yml @@ -33,3 +33,7 @@ menus: - name: Contact pageRef: /contact weight: 4 + +module: + imports: + - path: github.com/gohugoio/hugo-mod-jslibs/instantpage diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 450c52e..4c40d44 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -33,6 +33,7 @@

{{- block "content" . -}} {{- end -}} +

- {{ with resources.Get "instantclick.min.js" }} - - - {{ end }} + {{ partialCached "jslibs/instantpage/script-src.html" "-" }}