Skip to content

Commit 5595d6a

Browse files
committed
first setup for algolia search
1 parent 2464b83 commit 5595d6a

File tree

4 files changed

+464
-1
lines changed

4 files changed

+464
-1
lines changed

layouts/index.html

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,139 @@
1010

1111
{{ partial "overview_block.html" .}}
1212

13+
<style>
14+
.algolia-search {
15+
.header {
16+
display: flex;
17+
align-items: center;
18+
min-height: 50px;
19+
padding: 0.5rem 1rem;
20+
background-image: linear-gradient(284deg, #fedd4e, #fcb43a);
21+
color: #fff;
22+
margin-bottom: 1rem;
23+
}
24+
25+
.header a {
26+
color: #fff;
27+
text-decoration: none;
28+
}
29+
30+
.header-title {
31+
font-size: 1.2rem;
32+
font-weight: normal;
33+
}
34+
35+
.header-title::after {
36+
content: ' ▸ ';
37+
padding: 0 0.5rem;
38+
}
39+
40+
.header-subtitle {
41+
font-size: 1.2rem;
42+
}
43+
44+
.container {
45+
max-width: 1200px;
46+
margin: 0 auto;
47+
padding: 1rem;
48+
}
49+
50+
.search-panel {
51+
display: flex;
52+
}
53+
54+
.search-panel__filters {
55+
flex: 1;
56+
}
57+
58+
.search-panel__results {
59+
flex: 3;
60+
}
61+
62+
.ais-Highlight-highlighted {
63+
color: inherit;
64+
font-size: inherit;
65+
}
66+
67+
#searchbox {
68+
margin-bottom: 2rem;
69+
}
70+
71+
#pagination {
72+
margin: 2rem auto;
73+
text-align: center;
74+
}
75+
76+
.ais-Hits-item article {
77+
display: flex;
78+
}
79+
80+
.ais-Hits-item img {
81+
max-height: 125px;
82+
padding-right: 16px;
83+
}
84+
}
85+
</style>
86+
<!-- Search -->
87+
<div class="container algolia-search">
88+
<div class="search-panel">
89+
<div class="search-panel__filters">
90+
</div>
91+
92+
<div class="search-panel__results">
93+
<div id="searchbox"></div>
94+
<div id="hits"></div>
95+
<div id="pagination"></div>
96+
</div>
97+
</div>
98+
</div>
99+
100+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js"></script>
101+
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
102+
<script>
103+
const { algoliasearch, instantsearch } = window;
104+
105+
const searchClient = algoliasearch(
106+
'R5LXP5NUID',
107+
'4b504b6988d05a7631d6a330fb7afa58'
108+
);
109+
110+
const search = instantsearch({
111+
indexName: 'website_pages',
112+
searchClient,
113+
future: { preserveSharedStateOnUnmount: true },
114+
});
115+
116+
search.addWidgets([
117+
instantsearch.widgets.searchBox({
118+
container: '#searchbox',
119+
}),
120+
instantsearch.widgets.hits({
121+
container: '#hits',
122+
templates: {
123+
item: (hit, { html, components }) => html`
124+
<article>
125+
<img src=${hit.image} alt=${hit.title} />
126+
<div>
127+
<h1>${components.Highlight({ hit, attribute: 'title' })}</h1>
128+
<p>${components.Highlight({ hit, attribute: 'subtitle' })}</p>
129+
</div>
130+
</article>
131+
`,
132+
},
133+
}),
134+
instantsearch.widgets.configure({
135+
hitsPerPage: 8,
136+
}),
137+
instantsearch.widgets.pagination({
138+
container: '#pagination',
139+
}),
140+
]);
141+
142+
search.start();
143+
</script>
144+
<!-- /Search -->
145+
13146
{{ partial "landingpage/activityfeed.html" . }}
14147

15148
<!-- Areas of expertise -->

layouts/partials/head.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
4444
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
4545

46+
47+
<!-- search -->
48+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css@8/themes/satellite-min.css">
49+
4650
<!-- 100% privacy-first analytics -->
4751
<script async src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
4852

0 commit comments

Comments
 (0)