Skip to content

Commit b160b04

Browse files
authored
Merge pull request #94 from tighten/gc/remove-vue
Drops Vue search widget
2 parents 9f6f2f1 + 21f88df commit b160b04

8 files changed

Lines changed: 118 additions & 151 deletions

File tree

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
"postcss": "^8.4.21",
1919
"postcss-import": "^14.0.2",
2020
"tailwindcss": "^3.2.4",
21-
"vue": "^2.6.12",
22-
"vue-loader": "^15.9.6",
23-
"vue-template-compiler": "^2.6.12"
21+
"alpinejs": "^3.14.1"
2422
}
2523
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This starter template includes samples of common page types, and comes pre-confi
2222
- A custom 404 page
2323
- A component for accepting signups for a [Mailchimp](https://mailchimp.com/) newsletter
2424
- A sample contact form
25-
- A search bar powered by [Fuse.js](http://fusejs.io/) and [Vue.js](https://vuejs.org/), which indexes your content automatically and requires zero configuration
25+
- A search bar powered by [Fuse.js](http://fusejs.io/) and [Alpine.js](https://alpinejs.dev/), which indexes your content automatically and requires zero configuration
2626

2727
---
2828

source/_assets/css/base.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,5 @@ pre {
143143
@apply text-white;
144144
@apply bg-blue-400;
145145
}
146+
147+
[x-cloak] { display: none !important; }

source/_assets/js/components/Search.vue

Lines changed: 0 additions & 135 deletions
This file was deleted.

source/_assets/js/main.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
window.axios = require('axios');
2-
import Vue from 'vue';
3-
import Search from './components/Search.vue';
2+
import Alpine from "alpinejs";
3+
import Fuse from "fuse.js";
4+
5+
window.Fuse = Fuse;
6+
window.Alpine = Alpine;
7+
8+
Alpine.start();
9+
410
import hljs from 'highlight.js/lib/core';
511

612
// Syntax highlighting
@@ -18,11 +24,3 @@ document.querySelectorAll('pre code').forEach((block) => {
1824
hljs.highlightElement(block);
1925
});
2026

21-
Vue.config.productionTip = false;
22-
23-
new Vue({
24-
components: {
25-
Search,
26-
},
27-
}).$mount('#vue-search');
28-
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<div x-data="{
2+
init(){
3+
window.axios('/index.json')
4+
.then(response => {
5+
this.fuse = new window.Fuse(response.data, {
6+
minMatchCharLength: 6,
7+
keys: ['title', 'snippet', 'categories'],
8+
});
9+
});
10+
},
11+
get results() {
12+
return this.query ? this.fuse.search(this.query) : [];
13+
},
14+
get isQuerying() {
15+
return Boolean( this.query );
16+
},
17+
fuse: null,
18+
searching: false,
19+
query: '',
20+
showInput() {
21+
this.searching = true;
22+
this.$nextTick(() => {
23+
this.$refs.search.focus();
24+
})
25+
},
26+
reset() {
27+
this.query = '';
28+
this.searching = false;
29+
},
30+
}"
31+
x-cloak
32+
class="flex flex-1 justify-end items-center text-right px-4"
33+
>
34+
<div
35+
class="absolute md:relative w-full justify-end bg-white left-0 top-0 z-10 mt-7 md:mt-0 px-4 md:px-0"
36+
:class="{'hidden md:flex': ! searching}"
37+
>
38+
<label for="search" class="hidden">Search</label>
39+
40+
<input
41+
id="search"
42+
x-model="query"
43+
x-ref="search"
44+
class="relative block h-10 w-full lg:w-1/2 lg:focus:w-3/4 bg-gray-100 border border-gray-500 focus:border-blue-400 outline-none cursor-pointer text-gray-700 px-4 pb-0 pt-px transition-all duration-200 ease-out bg-[url('/assets/img/magnifying-glass.svg')] bg-no-repeat bg-[0.8rem] indent-[1.2em]"
45+
:class="{ 'rounded-b-none rounded-t-lg': query, 'rounded-3xl': !query }"
46+
autocomplete="off"
47+
name="search"
48+
placeholder="Search"
49+
type="text"
50+
@keyup.esc="reset"
51+
@blur="reset"
52+
>
53+
54+
<button
55+
x-show="query || searching"
56+
class="absolute top-0 right-0 leading-snug font-400 text-3xl text-blue-500 hover:text-blue-600 focus:outline-none pr-7 md:pr-3"
57+
@click="reset"
58+
>&times;</button>
59+
60+
<div
61+
x-show="isQuerying"
62+
x-cloak
63+
x-transition:enter="transition ease-out duration-300"
64+
x-transition:enter-start="opacity-0"
65+
x-transition:enter-end="opacity-100"
66+
x-transition:leave="transition-none"
67+
x-transition:leave-start="opacity-100"
68+
x-transition:leave-end="opacity-0"
69+
class="absolute left-0 right-0 md:inset-auto w-full lg:w-3/4 text-left mb-4 md:mt-10"
70+
>
71+
<div class="flex flex-col bg-white border border-b-0 border-t-0 border-blue-400 rounded-b-lg shadow-search mx-4 md:mx-0">
72+
<template x-for="(result, index) in results">
73+
<a
74+
class="bg-white hover:bg-blue-100 border-b border-blue-400 text-xl cursor-pointer p-4"
75+
:class="{ 'rounded-b-lg': (index === results.length - 1) }"
76+
:href="result.item.link"
77+
:title="result.item.title"
78+
:key="result.link"
79+
@mousedown.prevent
80+
>
81+
<span x-html="result.item.title"></span>
82+
83+
<span class="block font-normal text-gray-700 text-sm my-1" x-html="result.item.snippet"></span>
84+
</a>
85+
</template>
86+
<div
87+
x-show="! results.length"
88+
class="bg-white w-full hover:bg-blue-100 border-b border-blue-400 rounded-b-lg shadow cursor-pointer p-4"
89+
>
90+
<p class="my-0">No results for <strong x-html="query"></strong></p>
91+
</div>
92+
</div>
93+
</div>
94+
</div>
95+
96+
<button
97+
title="Start searching"
98+
type="button"
99+
class="flex md:hidden bg-gray-100 hover:bg-blue-100 justify-center items-center border border-gray-500 rounded-full focus:outline-none h-10 px-3"
100+
@click.prevent="showInput"
101+
>
102+
<img src="/assets/img/magnifying-glass.svg" alt="search icon" class="h-4 w-4 max-w-none">
103+
</button>
104+
</div>

source/_layouts/main.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</div>
3838

3939
<div id="vue-search" class="flex flex-1 justify-end items-center">
40-
<search></search>
40+
@include('_components.search')
4141

4242
@include('_nav.menu')
4343

webpack.mix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mix.disableSuccessNotifications();
55
mix.setPublicPath('source/assets/build');
66

77
mix.jigsaw()
8-
.js('source/_assets/js/main.js', 'js').vue()
8+
.js('source/_assets/js/main.js', 'js')
99
.css('source/_assets/css/main.css', 'css/main.css', [
1010
require('postcss-import'),
1111
require('tailwindcss/nesting'),

0 commit comments

Comments
 (0)