diff --git a/sass/_nav.scss b/sass/_nav.scss index 71e89f6..c6b5c0d 100644 --- a/sass/_nav.scss +++ b/sass/_nav.scss @@ -171,7 +171,6 @@ } a, - #search button, #language-switcher summary, #theme-switcher summary, #theme-switcher button, @@ -264,15 +263,6 @@ } } - #search .icon { - -webkit-mask-image: var(--icon-search); - mask-image: var(--icon-search); - - :root[dir*="rtl"] & { - transform: scaleX(-1); - } - } - #feed .icon { -webkit-mask-image: var(--icon-feed); mask-image: var(--icon-feed); @@ -336,108 +326,4 @@ } } } - - #search-container { - transform: scale(0.5) translateY(-2.75rem); - opacity: 0; - transition: var(--transition); - padding: 0 0.5rem 0; - height: 0; - pointer-events: none; - - &.active { - transform: none; - opacity: 1; - padding: 0 0.5rem 0.5rem; - height: 2.75rem; - pointer-events: all; - } - } - - #search-bar { - box-shadow: var(--edge-highlight); - border: none; - border-radius: 999px; - background: var(--fg-muted-1); - padding: 0 0.75rem; - width: 100%; - height: 2.25rem; - color: inherit; - font-size: var(--font-size-medium); - - &::placeholder { - opacity: 1; - color: var(--fg-muted-4); - } - } - - #search-results-container { - -webkit-backdrop-filter: var(--blur); - display: flex; - position: absolute; - backdrop-filter: var(--blur); - inset-block-start: calc(100% + 0.5rem); - inset-inline-start: 0; - box-shadow: var(--edge-highlight), var(--shadow-glass); - border-radius: calc(var(--rounded-corner) + 0.5rem); - background-color: var(--glass-bg); - width: 100%; - max-height: 50vh; - } - - #search-results { - --mask: linear-gradient(to bottom, - transparent, - black 1rem, - black calc(100% - 1rem), - transparent); - -webkit-mask-image: var(--mask); - display: none; - flex: 1; - flex-direction: column; - gap: 0.5rem; - mask-image: var(--mask); - padding: 0.5rem; - overflow: auto; - - .item { - display: inline-flex; - flex-direction: column; - box-shadow: var(--edge-highlight); - border-radius: var(--rounded-corner); - background-color: var(--fg-muted-1); - padding: 0.5rem; - - a { - width: fit-content; - - &::after { - content: " →"; - - :root[dir*="rtl"] & { - content: " ←"; - } - } - } - - span { - color: var(--fg-muted-5); - - &:first-of-type, - &.more-matches { - margin-block-start: 0.5rem; - border-block-start: max(1px, 0.0625rem) solid var(--fg-muted-2); - padding-block-start: 0.25rem; - } - - &.more-matches { - font-size: var(--font-size-small); - } - - strong { - color: var(--fg-color); - } - } - } - } } diff --git a/sass/_normalize.scss b/sass/_normalize.scss index e76e63c..ae583c5 100644 --- a/sass/_normalize.scss +++ b/sass/_normalize.scss @@ -154,16 +154,6 @@ margin: 0; } -// -// 1. Correct the odd appearance in Chrome, Edge, and Safari. -// 2. Correct the outline style in Safari. -// - -:where(input[type="search" i]) { - -webkit-appearance: textfield; // 1 - outline-offset: -2px; // 2 -} - // // Correct the cursor style of increment and decrement buttons in Safari. // @@ -182,14 +172,6 @@ color: inherit; } -// -// Remove the inner padding in Chrome, Edge, and Safari on macOS. -// - -::-webkit-search-decoration { - -webkit-appearance: none; -} - // // 1. Correct the inability to style upload buttons in iOS and Safari. // 2. Change font properties to `inherit` in Safari. diff --git a/sass/_variables.scss b/sass/_variables.scss index 890f0c5..f01a4b5 100644 --- a/sass/_variables.scss +++ b/sass/_variables.scss @@ -189,7 +189,6 @@ --icon-poop: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M8.963 1.514A4 4 0 0 1 5 5H4c-1.108 0-2 .892-2 2s.892 2 2 2H3c-1.662 0-3 1.338-3 3s1.338 3 3 3h10c1.662 0 3-1.338 3-3s-1.338-3-3-3h-1c1.108 0 2-.892 2-2s-.892-2-2-2h-1a4 4 0 0 0-2.037-3.486'/%3E%3C/svg%3E"); --icon-previous: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='m9.293 13.707-5-5a1 1 0 0 1 0-1.414l5-5a1 1 0 1 1 1.414 1.414L6.414 8l4.293 4.293a1 1 0 1 1-1.414 1.414m0 0'/%3E%3C/svg%3E"); --icon-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='m5.707 1.293 6 6a1 1 0 0 1 0 1.414l-6 6a1 1 0 1 1-1.414-1.414L9.586 8 4.293 2.707a1 1 0 1 1 1.414-1.414m0 0'/%3E%3C/svg%3E"); - --icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M6.57.063c-3.578 0-6.5 2.921-6.5 6.5 0 3.578 2.922 6.5 6.5 6.5a6.46 6.46 0 0 0 3.83-1.256l2.975 2.974c.957.938 2.363-.5 1.406-1.437l-2.96-2.961a6.46 6.46 0 0 0 1.25-3.82c0-3.579-2.923-6.5-6.5-6.5m0 2c2.5 0 4.5 2.003 4.5 4.5 0 2.5-2 4.5-4.5 4.5-2.496 0-4.5-2-4.5-4.5 0-2.497 2.004-4.5 4.5-4.5'/%3E%3C/svg%3E"); --icon-share: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M8 1a1 1 0 0 0-.5.135 1 1 0 0 0-.207.158l-3 3a1 1 0 0 0 0 1.414 1 1 0 0 0 1.414 0L7 4.414V10a1 1 0 0 0 1 1 1 1 0 0 0 1-1V4.414l1.293 1.293a1 1 0 0 0 1.414 0 1 1 0 0 0 0-1.414L8.738 1.326 8.7 1.287a1 1 0 0 0-.195-.15l-.008-.004a1 1 0 0 0-.236-.098h-.004A1 1 0 0 0 8 1M4 7c-1.645 0-3 1.355-3 3v2c0 1.645 1.355 3 3 3h8c1.645 0 3-1.355 3-3v-2c0-1.645-1.355-3-3-3a1 1 0 0 0 0 2c.564 0 1 .436 1 1v2c0 .564-.436 1-1 1H4c-.564 0-1-.436-1-1v-2c0-.564.436-1 1-1a1 1 0 0 0 0-2'/%3E%3C/svg%3E"); --icon-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M8 0a1 1 0 0 0-.95.684l-1.448 4.34-4.59-.016C.032 5.004-.371 6.266.43 6.828l3.625 2.555-1.5 4.285c-.317.902.687 1.691 1.492 1.172l4.004-2.594 3.894 2.586c.801.531 1.817-.258 1.5-1.16l-1.504-4.29 3.645-2.577c.789-.563.394-1.809-.574-1.813l-4.66-.015L8.949.69A1 1 0 0 0 8 0m0 0'/%3E%3C/svg%3E"); --icon-theme-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M.918 8.004a7.072 7.072 0 0 0 14.102.793 1.01 1.01 0 0 0-.457-.957 1 1 0 0 0-1.063-.004 3.9 3.9 0 0 1-2.031.578 3.89 3.89 0 0 1-3.883-3.883c0-.715.203-1.422.578-2.031a1 1 0 0 0-.004-1.062c-.207-.32-.578-.5-.957-.458A7.07 7.07 0 0 0 .918 8.004M5.586 4.53a5.877 5.877 0 0 0 8.965 5.004l-1.52-.96a5.09 5.09 0 0 1-5.035 4.507 5.09 5.09 0 0 1-5.078-5.078 5.09 5.09 0 0 1 4.508-5.035l-.961-1.52a5.9 5.9 0 0 0-.88 3.082m0 0'/%3E%3C/svg%3E"); diff --git a/sass/mods/_classic-nav.scss b/sass/mods/_classic-nav.scss index a6f023e..b76f142 100644 --- a/sass/mods/_classic-nav.scss +++ b/sass/mods/_classic-nav.scss @@ -10,8 +10,7 @@ border-radius: 0; } - nav, - #search-container { + nav { margin: 0 auto; width: min(var(--container-width), 90%); } @@ -19,7 +18,6 @@ nav ul li { a, summary, - &#search button, &#language-switcher details summary, &#theme-switcher details summary { border-radius: var(--rounded-corner); @@ -33,10 +31,4 @@ .divider { display: none; } - - #search-container { - #search-bar { - border-radius: var(--rounded-corner); - } - } } diff --git a/static/count.js b/static/count.js index 88c5dfb..8daf28c 100644 --- a/static/count.js +++ b/static/count.js @@ -29,7 +29,6 @@ e: !!(vars.event || goatcounter.event), s: [window.screen.width, window.screen.height, (window.devicePixelRatio || 1)], b: is_bot(), - q: location.search, } var rcb, pcb, tcb // Save callbacks to apply later. @@ -99,7 +98,7 @@ if (a.hostname.replace(/^www\./, '') === location.hostname.replace(/^www\./, '')) loc = a } - return (loc.pathname + loc.search) || '/' + return (loc.pathname) || '/' } // Run function after DOM is loaded. @@ -167,14 +166,6 @@ } } - // Get a query parameter. - window.goatcounter.get_query = function(name) { - var s = location.search.substr(1).split('&') - for (var i = 0; i < s.length; i++) - if (s[i].toLowerCase().indexOf(name.toLowerCase() + '=') === 0) - return s[i].substr(name.length + 1) - } - // Track click events. window.goatcounter.bind_events = function() { if (!document.querySelectorAll) // Just in case someone uses an ancient browser. diff --git a/static/fuse.js b/static/fuse.js deleted file mode 100644 index 1f534ad..0000000 --- a/static/fuse.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Fuse.js v7.0.0 - Lightweight fuzzy-search (http://fusejs.io) - * - * Copyright (c) 2023 Kiro Risk (http://kiro.me) - * All Rights Reserved. Apache Software License 2.0 - * - * http://www.apache.org/licenses/LICENSE-2.0 - */ -var e,t;e=this,t=function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{},n=t.getFn,i=void 0===n?$.getFn:n,o=t.fieldNormWeight,c=void 0===o?$.fieldNormWeight:o;r(this,e),this.norm=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,n=new Map,r=Math.pow(10,t);return{get:function(t){var i=t.match(F).length;if(n.has(i))return n.get(i);var o=1/Math.pow(i,.5*e),c=parseFloat(Math.round(o*r)/r);return n.set(i,c),c},clear:function(){n.clear()}}}(c,3),this.getFn=i,this.isCreated=!1,this.setIndexRecords()}return o(e,[{key:"setSources",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.docs=e}},{key:"setIndexRecords",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.records=e}},{key:"setKeys",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.keys=t,this._keysMap={},t.forEach((function(t,n){e._keysMap[t.id]=n}))}},{key:"create",value:function(){var e=this;!this.isCreated&&this.docs.length&&(this.isCreated=!0,m(this.docs[0])?this.docs.forEach((function(t,n){e._addString(t,n)})):this.docs.forEach((function(t,n){e._addObject(t,n)})),this.norm.clear())}},{key:"add",value:function(e){var t=this.size();m(e)?this._addString(e,t):this._addObject(e,t)}},{key:"removeAt",value:function(e){this.records.splice(e,1);for(var t=e,n=this.size();t2&&void 0!==arguments[2]?arguments[2]:{},r=n.getFn,i=void 0===r?$.getFn:r,o=n.fieldNormWeight,c=void 0===o?$.fieldNormWeight:o,a=new R({getFn:i,fieldNormWeight:c});return a.setKeys(e.map(A)),a.setSources(t),a.create(),a}function N(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.errors,r=void 0===n?0:n,i=t.currentLocation,o=void 0===i?0:i,c=t.expectedLocation,a=void 0===c?0:c,s=t.distance,u=void 0===s?$.distance:s,h=t.ignoreLocation,l=void 0===h?$.ignoreLocation:h,f=r/e.length;if(l)return f;var d=Math.abs(a-o);return u?f+d/u:d?1:f}var W=32;function T(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=r.location,o=void 0===i?$.location:i,c=r.distance,a=void 0===c?$.distance:c,s=r.threshold,u=void 0===s?$.threshold:s,h=r.findAllMatches,l=void 0===h?$.findAllMatches:h,f=r.minMatchCharLength,d=void 0===f?$.minMatchCharLength:f,v=r.includeMatches,g=void 0===v?$.includeMatches:v,y=r.ignoreLocation,p=void 0===y?$.ignoreLocation:y;if(t.length>W)throw new Error("Pattern length exceeds max of ".concat(W,"."));for(var m,k=t.length,M=e.length,b=Math.max(0,Math.min(o,M)),x=u,w=b,S=d>1||g,L=S?Array(M):[];(m=e.indexOf(t,w))>-1;){var _=N(t,{currentLocation:m,expectedLocation:b,distance:a,ignoreLocation:p});if(x=Math.min(_,x),w=m+k,S)for(var O=0;O=P;D-=1){var K=D-1,q=n[e.charAt(K)];if(S&&(L[K]=+!!q),z[D]=(z[D+1]<<1|1)&q,E&&(z[D]|=(j[D+1]|j[D])<<1|1|j[D+1]),z[D]&C&&(A=N(t,{errors:E,currentLocation:K,expectedLocation:b,distance:a,ignoreLocation:p}))<=x){if(x=A,(w=K)<=b)break;P=Math.max(1,2*b-w)}}if(N(t,{errors:E+1,currentLocation:b,expectedLocation:b,distance:a,ignoreLocation:p})>x)break;j=z}var B={isMatch:w>=0,score:Math.max(.001,A)};if(S){var J=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:$.minMatchCharLength,n=[],r=-1,i=-1,o=0,c=e.length;o=t&&n.push([r,i]),r=-1)}return e[o-1]&&o-r>=t&&n.push([r,o-1]),n}(L,d);J.length?g&&(B.indices=J):B.isMatch=!1}return B}function z(e){for(var t={},n=0,r=e.length;n1&&void 0!==arguments[1]?arguments[1]:{},o=i.location,c=void 0===o?$.location:o,a=i.threshold,s=void 0===a?$.threshold:a,u=i.distance,h=void 0===u?$.distance:u,l=i.includeMatches,f=void 0===l?$.includeMatches:l,d=i.findAllMatches,v=void 0===d?$.findAllMatches:d,g=i.minMatchCharLength,y=void 0===g?$.minMatchCharLength:g,p=i.isCaseSensitive,m=void 0===p?$.isCaseSensitive:p,k=i.ignoreLocation,M=void 0===k?$.ignoreLocation:k;if(r(this,e),this.options={location:c,threshold:s,distance:h,includeMatches:f,findAllMatches:v,minMatchCharLength:y,isCaseSensitive:m,ignoreLocation:M},this.pattern=m?t:t.toLowerCase(),this.chunks=[],this.pattern.length){var b=function(e,t){n.chunks.push({pattern:e,alphabet:z(e),startIndex:t})},x=this.pattern.length;if(x>W){for(var w=0,S=x%W,L=x-S;w1&&void 0!==arguments[1]?arguments[1]:{},c=o.location,a=void 0===c?$.location:c,s=o.threshold,u=void 0===s?$.threshold:s,h=o.distance,l=void 0===h?$.distance:h,f=o.includeMatches,d=void 0===f?$.includeMatches:f,v=o.findAllMatches,g=void 0===v?$.findAllMatches:v,y=o.minMatchCharLength,p=void 0===y?$.minMatchCharLength:y,m=o.isCaseSensitive,k=void 0===m?$.isCaseSensitive:m,M=o.ignoreLocation,b=void 0===M?$.ignoreLocation:M;return r(this,n),(i=t.call(this,e))._bitapSearch=new D(e,{location:a,threshold:u,distance:l,includeMatches:d,findAllMatches:g,minMatchCharLength:p,isCaseSensitive:k,ignoreLocation:b}),i}return o(n,[{key:"search",value:function(e){return this._bitapSearch.searchIn(e)}}],[{key:"type",get:function(){return"fuzzy"}},{key:"multiRegex",get:function(){return/^"(.*)"$/}},{key:"singleRegex",get:function(){return/^(.*)$/}}]),n}(K),X=function(e){a(n,e);var t=l(n);function n(e){return r(this,n),t.call(this,e)}return o(n,[{key:"search",value:function(e){for(var t,n=0,r=[],i=this.pattern.length;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,r.push([t,n-1]);var o=!!r.length;return{isMatch:o,score:o?0:1,indices:r}}}],[{key:"type",get:function(){return"include"}},{key:"multiRegex",get:function(){return/^'"(.*)"$/}},{key:"singleRegex",get:function(){return/^'(.*)$/}}]),n}(K),Y=[B,X,U,V,H,G,J,Q],Z=Y.length,ee=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,te=new Set([Q.type,X.type]),ne=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=n.isCaseSensitive,o=void 0===i?$.isCaseSensitive:i,c=n.includeMatches,a=void 0===c?$.includeMatches:c,s=n.minMatchCharLength,u=void 0===s?$.minMatchCharLength:s,h=n.ignoreLocation,l=void 0===h?$.ignoreLocation:h,f=n.findAllMatches,d=void 0===f?$.findAllMatches:f,v=n.location,g=void 0===v?$.location:v,y=n.threshold,p=void 0===y?$.threshold:y,m=n.distance,k=void 0===m?$.distance:m;r(this,e),this.query=null,this.options={isCaseSensitive:o,includeMatches:a,minMatchCharLength:u,findAllMatches:d,ignoreLocation:l,location:g,threshold:p,distance:k},this.pattern=o?t:t.toLowerCase(),this.query=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e.split("|").map((function(e){for(var n=e.trim().split(ee).filter((function(e){return e&&!!e.trim()})),r=[],i=0,o=n.length;i2&&void 0!==arguments[2]?arguments[2]:{}).auto,r=void 0===n||n;return ue(e)||(e=he(e)),function e(n){var i=Object.keys(n),o=function(e){return!!e[ae]}(n);if(!o&&i.length>1&&!ue(n))return e(he(n));if(function(e){return!g(e)&&b(e)&&!ue(e)}(n)){var c=o?n[ae]:i[0],a=o?n[se]:n[c];if(!m(a))throw new Error(function(e){return"Invalid value for key ".concat(e)}(c));var s={keyId:C(c),pattern:a};return r&&(s.searcher=ie(a,t)),s}var u={children:[],operator:i[0]};return i.forEach((function(t){var r=n[t];g(r)&&r.forEach((function(t){u.children.push(e(t))}))})),u}(e)}function fe(e,t){var n=e.matches;t.matches=[],x(n)&&n.forEach((function(e){if(x(e.indices)&&e.indices.length){var n={indices:e.indices,value:e.value};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)}}))}function de(e,t){t.score=e.score}var ve=function(){function e(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;r(this,e),this.options=t(t({},$),i),this.options.useExtendedSearch,this._keyStore=new j(this.options.keys),this.setCollection(n,o)}return o(e,[{key:"setCollection",value:function(e,t){if(this._docs=e,t&&!(t instanceof R))throw new Error("Incorrect 'index' type");this._myIndex=t||P(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}},{key:"add",value:function(e){x(e)&&(this._docs.push(e),this._myIndex.add(e))}},{key:"remove",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return!1},t=[],n=0,r=this._docs.length;n1&&void 0!==arguments[1]?arguments[1]:{}).limit,n=void 0===t?-1:t,r=this.options,i=r.includeMatches,o=r.includeScore,c=r.shouldSort,a=r.sortFn,s=r.ignoreFieldNorm,u=m(e)?m(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return function(e,t){var n=t.ignoreFieldNorm,r=void 0===n?$.ignoreFieldNorm:n;e.forEach((function(e){var t=1;e.matches.forEach((function(e){var n=e.key,i=e.norm,o=e.score,c=n?n.weight:null;t*=Math.pow(0===o&&c?Number.EPSILON:o,(c||1)*(r?1:i))})),e.score=t}))}(u,{ignoreFieldNorm:s}),c&&u.sort(a),k(n)&&n>-1&&(u=u.slice(0,n)),function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.includeMatches,i=void 0===r?$.includeMatches:r,o=n.includeScore,c=void 0===o?$.includeScore:o,a=[];return i&&a.push(fe),c&&a.push(de),e.map((function(e){var n=e.idx,r={item:t[n],refIndex:n};return a.length&&a.forEach((function(t){t(e,r)})),r}))}(u,this._docs,{includeMatches:i,includeScore:o})}},{key:"_searchStringList",value:function(e){var t=ie(e,this.options),n=this._myIndex.records,r=[];return n.forEach((function(e){var n=e.v,i=e.i,o=e.n;if(x(n)){var c=t.searchIn(n),a=c.isMatch,s=c.score,u=c.indices;a&&r.push({item:n,idx:i,matches:[{score:s,value:n,norm:o,indices:u}]})}})),r}},{key:"_searchLogical",value:function(e){var t=this,n=le(e,this.options),r=function e(n,r,i){if(!n.children){var o=n.keyId,c=n.searcher,a=t._findMatches({key:t._keyStore.get(o),value:t._myIndex.getValueForItemAtKeyId(r,o),searcher:c});return a&&a.length?[{idx:i,item:r,matches:a}]:[]}for(var s=[],u=0,h=n.children.length;u1&&void 0!==arguments[1]?arguments[1]:{},n=t.getFn,r=void 0===n?$.getFn:n,i=t.fieldNormWeight,o=void 0===i?$.fieldNormWeight:i,c=e.keys,a=e.records,s=new R({getFn:r,fieldNormWeight:o});return s.setKeys(c),s.setIndexRecords(a),s},ve.config=$,function(){re.push.apply(re,arguments)}(ne),ve},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Fuse=t(); \ No newline at end of file diff --git a/static/search-elasticlunr.js b/static/search-elasticlunr.js deleted file mode 100644 index d7d3578..0000000 --- a/static/search-elasticlunr.js +++ /dev/null @@ -1,209 +0,0 @@ -// Based on https://github.com/getzola/zola/blob/1ac1231de1e342bbaf4d7a51a8a9a40ea152e246/docs/static/search.js -function debounce(func, wait) { - var timeout; - - return function () { - var context = this; - var args = arguments; - clearTimeout(timeout); - - timeout = setTimeout(function () { - timeout = null; - func.apply(context, args); - }, wait); - }; -} - -// Taken from mdbook -// The strategy is as follows: -// First, assign a value to each word in the document: -// Words that correspond to search terms (stemmer aware): 40 -// Normal words: 2 -// First word in a sentence: 8 -// Then use a sliding window with a constant number of words and count the -// sum of the values of the words within the window. Then use the window that got the -// maximum sum. If there are multiple maximas, then get the last one. -// Enclose the terms in . -function makeTeaser(body, terms) { - var TERM_WEIGHT = 40; - var NORMAL_WORD_WEIGHT = 2; - var FIRST_WORD_WEIGHT = 8; - var TEASER_MAX_WORDS = 30; - - var stemmedTerms = terms.map(function (w) { - return elasticlunr.stemmer(w.toLowerCase()); - }); - var termFound = false; - var index = 0; - var weighted = []; // contains elements of ["word", weight, index_in_document] - - // split in sentences, then words - var sentences = body.toLowerCase().split(". "); - - for (var i in sentences) { - var words = sentences[i].split(" "); - var value = FIRST_WORD_WEIGHT; - - for (var j in words) { - var word = words[j]; - - if (word.length > 0) { - for (var k in stemmedTerms) { - if (elasticlunr.stemmer(word).startsWith(stemmedTerms[k])) { - value = TERM_WEIGHT; - termFound = true; - } - } - weighted.push([word, value, index]); - value = NORMAL_WORD_WEIGHT; - } - - index += word.length; - index += 1; // ' ' or '.' if last word in sentence - } - - index += 1; // because we split at a two-char boundary '. ' - } - - if (weighted.length === 0) { - return body; - } - - var windowWeights = []; - var windowSize = Math.min(weighted.length, TEASER_MAX_WORDS); - // We add a window with all the weights first - var curSum = 0; - for (var i = 0; i < windowSize; i++) { - curSum += weighted[i][1]; - } - windowWeights.push(curSum); - - for (var i = 0; i < weighted.length - windowSize; i++) { - curSum -= weighted[i][1]; - curSum += weighted[i + windowSize][1]; - windowWeights.push(curSum); - } - - // If we didn't find the term, just pick the first window - var maxSumIndex = 0; - if (termFound) { - var maxFound = 0; - // backwards - for (var i = windowWeights.length - 1; i >= 0; i--) { - if (windowWeights[i] > maxFound) { - maxFound = windowWeights[i]; - maxSumIndex = i; - } - } - } - - var teaser = []; - var startIndex = weighted[maxSumIndex][2]; - for (var i = maxSumIndex; i < maxSumIndex + windowSize; i++) { - var word = weighted[i]; - if (startIndex < word[2]) { - // missing text from index to start of `word` - teaser.push(body.substring(startIndex, word[2])); - startIndex = word[2]; - } - - // add around search terms - if (word[1] === TERM_WEIGHT) { - teaser.push(""); - } - startIndex = word[2] + word[0].length; - teaser.push(body.substring(word[2], startIndex)); - - if (word[1] === TERM_WEIGHT) { - teaser.push(""); - } - } - teaser.push("…"); - return teaser.join(""); -} - -function formatSearchResultItem(item, terms) { - return '
' - + `${item.doc.title}` - + `${makeTeaser(item.doc.body, terms)}` - + '
'; -} - -function initSearch() { - var searchBar = document.getElementById("search-bar"); - var searchContainer = document.getElementById("search-container"); - var searchResults = document.getElementById("search-results"); - var MAX_ITEMS = 10; - - var options = { - bool: "AND", - fields: { - title: { boost: 2 }, - body: { boost: 1 }, - } - }; - var currentTerm = ""; - var index; - - var initIndex = async function () { - if (index === undefined) { - let searchIndex = document.getElementById("search-index").textContent; - index = fetch(searchIndex) - .then( - async function (response) { - return await elasticlunr.Index.load(await response.json()); - } - ); - } - let res = await index; - return res; - } - - searchBar.addEventListener("keyup", debounce(async function () { - var term = searchBar.value.trim(); - if (term === currentTerm) { - return; - } - searchResults.style.display = term === "" ? "none" : "flex"; - searchResults.innerHTML = ""; - currentTerm = term; - if (term === "") { - return; - } - - var results = (await initIndex()).search(term, options); - if (results.length === 0) { - searchResults.style.display = "none"; - return; - } - - for (var i = 0; i < Math.min(results.length, MAX_ITEMS); i++) { - searchResults.innerHTML += formatSearchResultItem(results[i], term.split(" ")); - } - }, 150)); - - document.addEventListener("keydown", function (event) { - if (event.key === "/") { - event.preventDefault(); - toggleSearch(); - } - }); - - document.getElementById("search-toggle").addEventListener("click", toggleSearch); -} - -function toggleSearch() { - var searchContainer = document.getElementById("search-container"); - var searchBar = document.getElementById("search-bar"); - searchContainer.classList.toggle("active"); - searchBar.toggleAttribute("disabled"); - searchBar.focus(); -} - -if (document.readyState === "complete" || - (document.readyState !== "loading" && !document.documentElement.doScroll) -) { - initSearch(); -} else { - document.addEventListener("DOMContentLoaded", initSearch); -} diff --git a/static/search-fuse.js b/static/search-fuse.js deleted file mode 100644 index adecf08..0000000 --- a/static/search-fuse.js +++ /dev/null @@ -1,127 +0,0 @@ - // Based on https://codeberg.org/daudix/duckquill/issues/101#issuecomment-2377169 - let searchSetup = false; - let fuse; - - async function initIndex() { - if (searchSetup) return; - - const url = document.getElementById("search-index").textContent; - const response = await fetch(url); - - if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); - - const options = { - includeScore: false, - includeMatches: true, - ignoreLocation: true, - threshold: 0.15, - keys: [ - { name: "title", weight: 3 }, - { name: "description", weight: 2 }, - { name: "body", weight: 1 } - ] - }; - - fuse = new Fuse(await response.json(), options); - searchSetup = true; - - console.log("Search index initialized successfully"); - } - - function toggleSearch() { - initIndex(); - const searchBar = document.getElementById("search-bar"); - const searchContainer = document.getElementById("search-container"); - const searchResults = document.getElementById("search-results"); - searchContainer.classList.toggle("active"); - searchBar.toggleAttribute("disabled"); - searchBar.focus(); - } - - function debounce(actual_fn, wait) { - let timeoutId; - - return (...args) => { - clearTimeout(timeoutId); - - timeoutId = setTimeout(() => { - actual_fn(...args); - }, wait); - }; - }; - - function initSearch() { - const searchBar = document.getElementById("search-bar"); - const searchResults = document.getElementById("search-results"); - const searchContainer = document.getElementById("search-container"); - const MAX_ITEMS = 10; - const MAX_RESULTS = 4; - - let currentTerm = ""; - - searchBar.addEventListener("keyup", (e) => { - const searchVal = searchBar.value.trim(); - const results = fuse.search(searchVal, { limit: MAX_ITEMS }); - - let html = ""; - for (const result of results) { - html += makeTeaser(result, searchVal); - } - searchResults.innerHTML = html; - - if (html) { - searchResults.style.display = "flex"; - } else { - searchResults.style.display = "none"; - } - }); - - function makeTeaser(result, searchVal) { - const TEASER_SIZE = 20; - let output = `
${result.item.title}`; - - for (const match of result.matches) { - if (match.key === "title") continue; - - const indices = match.indices.sort((a, b) => Math.abs(a[1] - a[0] - searchVal.length) - Math.abs(b[1] - b[0] - searchVal.length)).slice(0, MAX_RESULTS); - const value = match.value; - - for (const ind of indices) { - const start = Math.max(0, ind[0] - TEASER_SIZE); - const end = Math.min(value.length - 1, ind[1] + TEASER_SIZE); - output += "" - + value.substring(start, ind[0]) - + `${value.substring(ind[0], ind[1] + 1)}` - + value.substring(ind[1] + 1, end) - + ""; - } - - if (match.indices.length > 4) { - const moreMatchesText = document.getElementById("more-matches-text").textContent; - output += `${moreMatchesText}`.replace("$MATCHES", `+${match.indices.length - MAX_RESULTS}`); - } - } - return output + "
"; - } - - /*window.addEventListener("click", function (event) { - if (searchSetup && searchBar.getAttribute("disabled") === null && !searchContainer.contains(event.target)) { - toggleSearch(); - } - }, { passive: true });*/ - - document.addEventListener("keydown", function(event) { - if (event.key === "/") { - event.preventDefault(); - toggleSearch(); - } - }); - - document.getElementById("search-toggle").addEventListener("click", toggleSearch); - } - - if (document.readyState === "complete" || - (document.readyState !== "loading" && !document.documentElement.doScroll)) - initSearch(); - else - document.addEventListener("DOMContentLoaded", initSearch); diff --git a/templates/macros/translate.html b/templates/macros/translate.html index 20a89e6..f4529e1 100644 --- a/templates/macros/translate.html +++ b/templates/macros/translate.html @@ -12,11 +12,7 @@ Parameters: The macro supports special pluralization rules for: - Arabic (`ar`): Has unique forms for zero, one, two, few, and many. -- Slavic languages: Pluralization depends on the last digit of the number, with exceptions for numbers ending in 11-14. - -NOTE: If the logic for pluralization is modified, it needs to be replicated on the JavaScript search. -Files: static/js/searchElasticlunr.js and its minified version at static/js/searchElasticlunr.min.js -Function name: getPluralizationKey -#} +- Slavic languages: Pluralization depends on the last digit of the number, with exceptions for numbers ending in 11-14.#} {% macro translate(key, number=-1, language_strings="", default="", replace=true) %} {%- set slavic_plural_languages = ["uk", "be", "bs", "hr", "ru", "sr"] -%}