diff --git a/assets/js/custom.js b/assets/js/custom.js index 7930eec..ccf9873 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -11,75 +11,3 @@ Array.from(myLabels).forEach(label => { }; }); }); - -// Search helpers from https://github.com/onweru/compose -const rootURL = window.location.protocol + "//" + window.location.host; -const searchFieldClass = '.search_field'; -const searchClass = '.search'; -const quickLinks = '{{ T "quick_links" }}'; -const searchResultsLabel = '{{ T "search_results_label" }}'; -const shortSearchQuery = '{{ T "short_search_query" }}' -const typeToSearch = '{{ T "type_to_search" }}'; -const noMatchesFound = '{{ T "no_matches" }}'; - -function createEl(element = 'div') { - return document.createElement(element); -} - -function emptyEl(el) { - while(el.firstChild) - el.removeChild(el.firstChild); -} - -function wrapText(text, context, wrapper = 'mark') { - let open = `<${wrapper}>`; - let close = `${wrapper}>`; - let escapedOpen = `%3C${wrapper}%3E`; - let escapedClose = `%3C/${wrapper}%3E`; - function wrap(context) { - let c = context.innerHTML; - let pattern = new RegExp(text, "gi"); - let matches = text.length ? c.match(pattern) : null; - - if(matches) { - matches.forEach(function(matchStr){ - c = c.replaceAll(matchStr, `${open}${matchStr}${close}`); - context.innerHTML = c; - }); - - const images = elems('img', context); - - if(images) { - images.forEach(image => { - image.src = image.src.replaceAll(open, '').replaceAll(close, '').replaceAll(escapedOpen, '').replaceAll(escapedClose, ''); - }); - } - } - } - - const contents = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "code", "td"]; - - contents.forEach(function(c){ - const cs = elems(c, context); - if(cs.length) { - cs.forEach(function(cx, index){ - if(cx.children.length >= 1) { - Array.from(cx.children).forEach(function(child){ - wrap(child); - }) - wrap(cx); - } else { - wrap(cx); - } - // sanitize urls and ids - }); - } - }); - - const hyperLinks = elems('a'); - if(hyperLinks) { - hyperLinks.forEach(function(link){ - link.href = link.href.replaceAll(encodeURI(open), "").replaceAll(encodeURI(close), ""); - }); - } -} diff --git a/assets/sass/_custom.sass b/assets/sass/_custom.sass index 1473aa5..35c305c 100644 --- a/assets/sass/_custom.sass +++ b/assets/sass/_custom.sass @@ -7,13 +7,6 @@ html, body &_brand img max-height: 2rem - // search box - &_search - display: grid - align-items: center - .search - @media screen and (min-width: 992px) - margin-right: 1.5rem .sidebar &_badge @@ -77,58 +70,3 @@ code word-break: normal &.noClass line-break: normal - - -// search from https://github.com/onweru/compose -.search - flex: 1 - display: flex - justify-content: flex-end - position: relative - &_field - padding: 0.5rem 1.5rem 0.5rem 2.5rem - border-radius: 1.5rem - width: 13.5rem - outline: none - border: none - background: transparent - color: var(--text) - box-shadow: 0 1rem 4rem rgba(0,0,0,0.17) - font-size: 1rem - &_label - width: 1rem - height: 1rem - position: absolute - left: 0.33rem - top: 0.25rem - opacity: 0.33 - svg - width: 100% - height: 100% - fill: var(--text) - &_result - padding: 0.5rem 1rem - &:not(.passive):hover - background-color: var(--theme) - color: var(--light) - &.passive - display: grid - &s - width: 13.5rem - background-color: var(--bg) - border-radius: 0 0 0.25rem 0.25rem - box-shadow: 0 1rem 4rem rgba(0,0,0,0.17) - position: absolute - top: 125% - display: grid - overflow: hidden - z-index: 5 - &:empty - display: none - &_title - padding: 0.5rem 1rem 0.5rem 1rem - background: var(--theme) - color: var(--light) - font-size: 0.9rem - opacity: 0.87 - text-transform: uppercase diff --git a/assets/sass/_override.sass b/assets/sass/_override.sass index 61e6230..b7800d1 100644 --- a/assets/sass/_override.sass +++ b/assets/sass/_override.sass @@ -31,4 +31,13 @@ html background: hsl(41, 100%, 36%) &.tip border-color: hsl(93, 85%, 32%) - background: hsl(93, 100%, 21%) \ No newline at end of file + background: hsl(93, 100%, 21%) + + // search + .search + max-width: 20rem + margin: 0.4rem 0 0.4rem 0 + &_field + background: var(--translucent-light) + color: var(--light) + diff --git a/config/_default/params.toml b/config/_default/params.toml index ae72584..ab9b2d8 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -30,6 +30,7 @@ numberOfRelatedPosts = 6 numberOfFeaturedPosts = 4 toc = true timeless = false +enableSearch = true ## Website author [author] diff --git a/layouts/_default/index.json b/layouts/_default/index.json deleted file mode 100644 index 5642b61..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) -}} - {{- end -}} -{{- end -}} -{{- jsonify (uniq ($.Scratch.Get "index")) -}} \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 8aec3ac..9c60b0b 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -30,8 +30,8 @@ {{- if $centerLogo }} {{- partial "logo" (dict "logo" $logo "class" "nav_center") }} {{- end }} -