From 314e744ac43dc8ddfee7d25c07918e4a66ec89c2 Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Mon, 18 Mar 2024 19:40:00 +0700 Subject: [PATCH 1/6] Implement PageFind search Signed-off-by: Chris Abraham --- assets/js/search.js | 44 ++++++++++++++++++++++++++++ assets/scss/_search.scss | 11 +++++++ config.toml | 2 +- layouts/_default/content.html | 2 +- layouts/_default/search.html | 47 ++++++++++++++++++++++-------- layouts/partials/search-input.html | 31 -------------------- 6 files changed, 92 insertions(+), 45 deletions(-) create mode 100644 assets/js/search.js diff --git a/assets/js/search.js b/assets/js/search.js new file mode 100644 index 0000000000..47a71fa15a --- /dev/null +++ b/assets/js/search.js @@ -0,0 +1,44 @@ +/* +Copyright 2018 Google LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +(function($) { + + 'use strict'; + + var Search = { + init: function() { + $(document).ready(function() { + $(document).on('keypress', '.td-search-input', function(e) { + if (e.keyCode !== 13) { + return + } + + var query = $(this).val(); + var searchPage = "{{ "search/" | relLangURL }}?q=" + query; + console.log(searchPage); + document.location = searchPage; + + return false; + }); + + }); + }, + }; + + Search.init(); + + +}(jQuery)); diff --git a/assets/scss/_search.scss b/assets/scss/_search.scss index 11748925a9..50bb155ab8 100644 --- a/assets/scss/_search.scss +++ b/assets/scss/_search.scss @@ -100,3 +100,14 @@ } } + +.pagefind-ui__result-link { + color: $link-color !important; +} +.pagefind-ui__search-clear { + padding-left: 20px !important; + padding-right: 20px !important; +} +#search { + margin-top: 40px; +} diff --git a/config.toml b/config.toml index e37e0d679d..36c1b16c62 100644 --- a/config.toml +++ b/config.toml @@ -226,7 +226,7 @@ github_repo = "https://github.com/cncf/glossary" github_branch = "main" # Google Custom Search Engine ID. Remove or comment out to disable search. -gcs_engine_id = "eda0239a7d3fd0d90" +# gcs_engine_id = "eda0239a7d3fd0d90" # Enable Algolia DocSearch algolia_docsearch = false diff --git a/layouts/_default/content.html b/layouts/_default/content.html index 85cb48e4b6..c900d77e70 100644 --- a/layouts/_default/content.html +++ b/layouts/_default/content.html @@ -1,4 +1,4 @@ -
+

{{ .Title }}

{{ with .Params.description }}
{{ . | markdownify }}
{{ end }}