Skip to content

Commit 3984cc3

Browse files
committed
feat: AlgoliaSearch
1 parent 31fc2db commit 3984cc3

File tree

7 files changed

+333
-13
lines changed

7 files changed

+333
-13
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ URL_BASE=https://vue-a11y.com
44
# blog
55
PAGINATION_PER_PAGE=8
66

7+
# Algólia key
8+
ALGOLIA_KEY=
9+
710
# Newsletter
811
MAILCHIMP_ENDPOINT=
912

package-lock.json

Lines changed: 178 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"vuepress-plugin-canonical": "^1.0.0"
5959
},
6060
"dependencies": {
61+
"@docsearch/css": "^1.0.0-alpha.28",
62+
"@docsearch/js": "^1.0.0-alpha.28",
6163
"@vue-a11y/announcer": "^2.1.0",
6264
"@vue-a11y/dark-mode": "^1.1.1",
6365
"@vue-a11y/focus-loop": "^0.1.2",

src/.vuepress/config/themeConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ module.exports = {
77
searchPlaceholder: 'Search (Press "s" to focus)',
88
url: process.env.URL_BASE,
99
mailchimp: process.env.MAILCHIMP_ENDPOINT,
10+
algolia: {
11+
indexName: 'vue-a11y',
12+
apiKey: process.env.ALGOLIA_KEY
13+
},
1014
webmentions: {
1115
active: true,
1216
endpoint: 'https://webmention.io/api/mentions.jf2?target=#URLPOST#'

src/.vuepress/theme/components/TheHeader.vue

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
itemprop="sameAs"
1515
:content="social.link"
1616
>
17-
<div class="flex flex-wrap w-full px-0">
17+
<div class="flex flex-wrap w-full">
1818
<div
1919
class="flex items-center justify-end w-1/5 h-16 md:pl-0 md:w-1/12 lg:w-3/12"
2020
:class="{'header-logo--bg': bgSidebar, 'container-layout-pl lg:w-2/7': hasSidebar }"
@@ -27,16 +27,15 @@
2727
class="flex items-center flex-grow-0 w-3/5 h-16 md:pl-4 lg:pl-0 md:pr-0 md:w-auto md:flex-grow"
2828
:class="{ 'w-4/5': !hasSidebar }"
2929
>
30-
<form class="relative w-full lg:pl-10">
31-
<vp-icon
32-
name="search"
33-
class="absolute z-20 ml-3 pin-c-y"
34-
/>
35-
<SearchBox
36-
role="search"
37-
class="w-full"
30+
<div
31+
class="w-full"
32+
:class="{ 'md:ml-8': hasSidebar }"
33+
>
34+
<AlgoliaSearch
35+
v-if="isAlgoliaSearch"
36+
:options="$themeConfig.algolia"
3837
/>
39-
</form>
38+
</div>
4039
</div>
4140
<div
4241
v-if="hasSidebar"
@@ -71,14 +70,14 @@ import { watch, computed } from '@vue/composition-api'
7170
7271
import Logo from '@/theme/components/Logo'
7372
import TheNavigation from '@/theme/components/TheNavigation'
74-
import SearchBox from '@SearchBox'
73+
// import SearchBox from '@SearchBox'
7574
7675
export default {
7776
name: 'TheHeader',
7877
7978
components: {
8079
Logo,
81-
SearchBox,
80+
// SearchBox,
8281
TheNavigation
8382
},
8483
@@ -102,10 +101,12 @@ export default {
102101
setup (props, { root, emit }) {
103102
const labels = root.$themeLocaleConfig.a11y.labels
104103
const menuButtonAriaLabel = labels.menuButton ? computed(() => props.isSidebarOpen ? labels.menuButton.close : labels.menuButton.open) : 'Menu sidebar button'
104+
const isAlgoliaSearch = computed(() => root.$themeConfig.algolia && root.$themeConfig.algolia.indexName && root.$themeConfig.algolia.apiKey)
105105
106106
watch(() => root.$route.fullPath, () => props.isSidebarOpen && emit('toggle-sidebar'))
107107
108108
return {
109+
isAlgoliaSearch,
109110
menuButtonAriaLabel
110111
}
111112
}

0 commit comments

Comments
 (0)