Skip to content

Commit 9d2317a

Browse files
cjyabrahamTim Bannister
authored andcommitted
Replace Bing with PageFind search for users in China
1 parent 4c7acca commit 9d2317a

File tree

11 files changed

+122
-68
lines changed

11 files changed

+122
-68
lines changed

assets/js/search.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ limitations under the License.
3232
}
3333

3434
var query = $(this).val();
35-
document.location = "{{ "search/" | absURL }}?q=" + query;
35+
var searchPage = $(this).data('search-page') + "?q=" + query;
36+
document.location = searchPage;
3637

3738
return false;
3839
});

assets/scss/_custom.scss

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,29 +1318,6 @@ div.alert > em.javascript-required {
13181318
background: #326de6;
13191319
}
13201320

1321-
// Adjust Bing search result page
1322-
#bing-results-container {
1323-
padding: 1em;
1324-
}
1325-
.bing-result {
1326-
margin-bottom: 1em;
1327-
}
1328-
.bing-result-url {
1329-
font-size: 14px;
1330-
}
1331-
.bing-result-snippet {
1332-
color: #666666;
1333-
font-size: 14px;
1334-
}
1335-
#bing-pagination-container {
1336-
padding: 1em;
1337-
margin-bottom: 1em;
1338-
1339-
a.bing-page-anchor {
1340-
padding: 0.5em;
1341-
margin: 0.25em;
1342-
}
1343-
}
13441321

13451322
// Adjust Search-bar search-icon
13461323
.search-bar {
@@ -1372,6 +1349,65 @@ div.alert > em.javascript-required {
13721349
padding: .5em 0 .5em 0;
13731350
}
13741351

1352+
// PageFind Styles
1353+
1354+
#search .pagefind-ui form input {
1355+
background-color: #fff;
1356+
border: 1px solid #4c4c4c;
1357+
border-radius: 20px;
1358+
overflow-x: hidden;
1359+
width: auto;
1360+
padding: 6px 10px;
1361+
margin: 20px 10px 20px 0;
1362+
1363+
&:focus-within {
1364+
outline: 1.5px solid rgba(47, 135, 223, 0.7);
1365+
border: 1px solid rgba(47, 135, 223, 0.7);
1366+
}
1367+
}
1368+
1369+
#search .pagefind-ui ol.pagefind-ui__results {
1370+
padding-left: 0;
1371+
}
1372+
1373+
#search .pagefind-ui .pagefind-ui__result-nested {
1374+
padding-left: 2em;
1375+
}
1376+
1377+
#search .pagefind-ui.pagefind-ui__result-nested::before {
1378+
content: "\2937 ";
1379+
color: $blue;
1380+
}
1381+
1382+
#search .pagefind-ui ol > li {
1383+
list-style-type: none;
1384+
border-top: 1.5px solid rgba(47, 135, 223, 0.7);
1385+
padding: 10px;
1386+
}
1387+
1388+
#search .pagefind-ui button {
1389+
color: #fff;
1390+
background-color: $blue;
1391+
border-radius: 0.2em;
1392+
border: 0.1rem solid $medium-grey;
1393+
padding: 0.3em;
1394+
}
1395+
1396+
#search .pagefind-ui__result-tags {
1397+
font-size: 14px;
1398+
font-weight: 400;
1399+
}
1400+
1401+
#search a.pagefind-ui__result-link {
1402+
font-weight: 700;
1403+
font-size: 1.15rem;
1404+
}
1405+
1406+
body.td-search #search {
1407+
margin-top: 1rem;
1408+
margin-bottom: 3rem;
1409+
}
1410+
13751411
/* CSS for 'figure' full-screen display */
13761412

13771413
/* Define styles for full-screen overlay */

layouts/_default/baseof.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h1>{{ block "hero-title" . }}{{ .Params.bigheader | default .Title }}{{ end }}<
3232
{{ end }}
3333
{{ end }}
3434
<div class="td-outer">
35-
<main role="main" class="td-main">
35+
<main role="main" class="td-main" {{ if (or (ne .FirstSection "case-studies") (not .IsSection) ) }}data-pagefind-body{{ end }}>
3636
{{ block "main" . }}{{ end }}
3737
</main>
3838
</div>

layouts/_default/search.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
</form>
2525
</div>
2626
<div class="col-12 col-md-8 offset-md-2">
27-
<h2 class="search-title ml-3">{{ .Title }}</h2>
2827
{{ if .Site.Params.gcs_engine_id }}
2928
<script>
3029
(function() {
@@ -40,9 +39,9 @@ <h2 class="search-title ml-3">{{ .Title }}</h2>
4039
<gcse:searchresults-only></gcse:searchresults-only>
4140
{{ else if .Site.Params.k8s_search }}
4241
<script src="{{ "js/search.js" | relURL }}"></script>
42+
<script src="/pagefind/pagefind-ui.js"></script>
4343
<gcse:searchresults-only linktarget="_parent">
44-
<div id="bing-results-container">{{ T "layouts_docs_search_fetching" }}</div>
45-
<div id="bing-pagination-container"></div>
44+
<div id="search" style="display:none"></div>
4645
</gcse:searchresults-only>
4746
{{ end }}
4847
</div>

layouts/blog/baseof.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
<div class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
3030
{{ partial "blog-sidebar.html" . }}
3131
</div>
32-
<main class="col-12 col-md-9 col-xl-8 pl-md-5 pr-md-4" role="main">
32+
<main class="col-12 col-md-9 col-xl-8 pl-md-5 pr-md-4" role="main"
33+
{{ if .IsPage }}data-pagefind-body data-pagefind-meta="date:{{ $.Date.Format "2006-01-02" }}"{{ end }}
34+
><!-- inside main element -->
3335
{{ block "deprecated" . }}
3436
{{ partial "deprecation-warning.html" . }}
3537
{{ end }}

layouts/case-studies/single-baseof.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<body>
77
{{ partial "navbar.html" . }}
88
{{ partial "deprecation-warning.html" . }}
9+
<div data-pagefind-body>
910
{{ block "main" . }}{{ end }}
11+
</div>
1012
{{ partialCached "footer.html" . }}
1113
{{ partialCached "scripts.html" . }}
1214

layouts/docs/baseof.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
<div id="maindoc" class="split pl-md-5 row">
2424
<!--main class="col-12 col-md-9 col-xl-8 pl-md-5" role="main"-->
25-
<main role="main" class="col-xl-8">
25+
<main role="main" class="col-xl-8" {{ if ne .Params.cid "docsHome" }}data-pagefind-body{{ end }}{{ if (and .IsPage .Params.description ) }} data-pagefind-meta="description:{{ .Params.description }}"{{ end }}>
2626
{{ if not .Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" . }}{{ end }}
2727
{{ block "deprecated" . }}
2828
{{ partial "deprecation-warning.html" . }}

layouts/docs/glossary.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h1>{{ .Title }}</h1>
4141
<li class="{{ $.Scratch.Get "tag_classes" }} hide" data-show-count="0">
4242
<div id="{{ $term_identifier }}" class="term-anchor"></div>
4343
<div>
44-
<div class="term-name"><b>{{ .Title }}</b><a href="{{ printf "#%s" $term_identifier }}" class="permalink hide">LINK</a></div>
44+
<div class="term-name" term="{{ .Title}}" data-pagefind-index-attrs="term"><b>{{ .Title }}</b><a href="{{ printf "#%s" $term_identifier }}" class="permalink hide">LINK</a></div>
4545
{{ with .Params.aka }}
4646
{{ T "layouts_docs_glossary_aka" }}: <i>{{ delimit . ", " }}</i>
4747
<br>

layouts/partials/search-input.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@
2222
>
2323
</div>
2424
{{ else if .Site.Params.k8s_search }}
25+
26+
{{ $lang := .Site.Language.Lang }}
27+
{{ $searchFile := printf "content/%s/search.md" $lang }}
28+
2529
<div class="search-bar">
2630
<i class="search-icon fas fa-search"></i>
2731
<input
2832
type="search"
2933
name="q"
34+
{{ if fileExists $searchFile }}
35+
data-search-page="{{ "search/" | relLangURL }}"
36+
{{ else }}
37+
data-search-page="{{ "search/" | relURL }}"
38+
{{ end }}
3039
class="search-input td-search-input"
3140
placeholder="{{ T "ui_search_placeholder" }}"
3241
aria-label="{{ T "ui_search_placeholder" }}"

netlify.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# DO NOT REMOVE THIS (contact @kubernetes/sig-docs-leads)
55
publish = "public"
66
functions = "functions"
7-
command = "git submodule update --init --recursive --depth 1 && make non-production-build"
7+
command = "git submodule update --init --recursive --depth 1 && make non-production-build && npx -y pagefind --site public"
88

99
[build.environment]
1010
NODE_VERSION = "20.11.0"
@@ -16,13 +16,13 @@ HUGO_ENV = "production"
1616
HUGO_ENABLEGITINFO = "true"
1717

1818
[context.deploy-preview]
19-
command = "git submodule update --init --recursive --depth 1 && make deploy-preview"
19+
command = "git submodule update --init --recursive --depth 1 && make deploy-preview && npx -y pagefind --site public"
2020

2121
[context.branch-deploy]
22-
command = "git submodule update --init --recursive --depth 1 && make non-production-build"
22+
command = "git submodule update --init --recursive --depth 1 && make non-production-build && npx -y pagefind --site public"
2323

2424
[context.main]
2525
# This context is triggered by the `main` branch and allows search indexing
2626
# DO NOT REMOVE THIS (contact @kubernetes/sig-docs-leads)
2727
publish = "public"
28-
command = "git submodule update --init --recursive --depth 1 && make production-build"
28+
command = "git submodule update --init --recursive --depth 1 && make production-build && npx -y pagefind --site public"

0 commit comments

Comments
 (0)