Skip to content

Commit a87d028

Browse files
committed
Integrate experimental in-browser search #1165
@sabine Integrate experimental in-browser search #1165 fa8f8e4
1 parent caff977 commit a87d028

File tree

11 files changed

+481
-58
lines changed

11 files changed

+481
-58
lines changed

LICENSE-3RD-PARTY

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ URL: https://swiperjs.com/
112112
License: MIT License
113113
Copyright: Copyright 2014-2021 Vladimir Kharlampidi
114114

115+
asset/vendors/minisearch.min.js:
116+
117+
Name: Minisearch
118+
Version: 6.0.1
119+
URL: https://github.com/lucaong/minisearch
120+
License: MIT License
121+
Copyright: Copyright 2022 Luca Ongaro
122+
115123
--------------------------------------------------------------------------
116124
Licenses
117125
--------------------------------------------------------------------------

asset/vendors/minisearch.min.js

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

src/global/url.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module Package : sig
1212

1313
val file :
1414
?hash:string -> ?version:string -> filepath:string -> string -> string
15+
16+
val search_index : ?version:string -> digest:string -> string -> string
1517
end = struct
1618
let with_hash = Option.fold ~none:"/p" ~some:(( ^ ) "/u/")
1719
let with_version = Option.fold ~none:"/latest" ~some:(( ^ ) "/")
@@ -25,6 +27,7 @@ end = struct
2527
base ?hash ?version ("/doc/" ^ page)
2628

2729
let file ?hash ?version ~filepath = base ?hash ?version ("/" ^ filepath)
30+
let search_index ?version ~digest = base ?version ("/search-index/" ^ digest)
2831
end
2932

3033
let sitemap = "/sitemap.xml"

src/ocamlorg_frontend/components/header.eml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let render
4545
<%s! Packages_autocomplete_fragment.form_attributes %>
4646
action="/packages/search" method="GET">
4747
<div class="header__search relative flex items-center justify-center">
48-
<input type="search" name="q" class="header__search__input focus:border-gray-800 text-gray-800 border-primary-600 h-10 rounded-l-md appearance-none px-4 py-1 lg:w-56 xl:w-80"
48+
<input @keydown.stop type="search" name="q" class="header__search__input focus:border-gray-800 text-gray-800 border-primary-600 h-10 rounded-l-md appearance-none px-4 py-1 lg:w-56 xl:w-80"
4949
autocomplete="off"
5050
placeholder="Search OCaml Packages"
5151
<%s! Packages_autocomplete_fragment.input_attributes ~target_sel:"#header-search-results" ~indicator_sel:"#header-search-indicator" %>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#in-package-search-results ol {
2+
@apply m-0 p-0 list-none text-sm;
3+
}
4+
5+
#in-package-search-results li {
6+
@apply m-0 p-0 border-b;
7+
}
8+
9+
#in-package-search-results br {
10+
@apply hidden;
11+
}
12+
13+
#in-package-search-results .search-entry {
14+
@apply px-4 py-1 font-normal text-body-600 flex flex-col;
15+
--entry-color: gray;
16+
}
17+
18+
#in-package-search-results li:first-child .search-entry {
19+
@apply pt-2;
20+
}
21+
22+
#in-package-search-results li:last-child .search-entry {
23+
@apply pb-2;
24+
}
25+
26+
#in-package-search-results .search-entry:hover {
27+
text-decoration: none;
28+
background: #f4f4f4;
29+
}
30+
31+
/*
32+
@media (min-width: 64em) {
33+
#in-package-search-results .search-entry {
34+
@apply flex-row;
35+
}
36+
37+
#in-package-search-results .search-entry .entry-title {
38+
@apply shrink-0 w-1/2;
39+
}
40+
}
41+
*/
42+
43+
#in-package-search-results .search-entry .entry-kind {
44+
@apply py-0.5 px-1 bg-body-600 text-white rounded mr-2 text-sm;
45+
}
46+
47+
#in-package-search-results .search-entry .entry-kind {
48+
background: var(--entry-color);
49+
}
50+
51+
#in-package-search-results .search-entry.mod {
52+
--entry-color: rgb(204, 78, 12);
53+
}
54+
55+
#in-package-search-results .search-entry.mty {
56+
--entry-color: #027491;
57+
}
58+
59+
#in-package-search-results .search-entry.mtd {
60+
--entry-color: #327d8e;
61+
}
62+
63+
#in-package-search-results .search-entry.typ {
64+
--entry-color: rgb(42, 84, 183);
65+
}
66+
67+
#in-package-search-results .search-entry.val {
68+
--entry-color: green;
69+
}
70+
71+
#in-package-search-results .search-entry.par {
72+
--entry-color: green;
73+
}
74+
75+
#in-package-search-results .search-entry.cls {
76+
--entry-color: rgb(163, 34, 34);
77+
}
78+
79+
#in-package-search-results .search-entry.cty {
80+
--entry-color: rgb(32, 68, 165);
81+
}
82+
83+
#in-package-search-results .search-entry.exc {
84+
--entry-color: #370c62;
85+
}
86+
87+
#in-package-search-results .search-entry.man {
88+
--entry-color: #47424b;
89+
}
90+
91+
#in-package-search-results .search-entry .entry-title {
92+
overflow-wrap: anywhere;
93+
}
94+
95+
#in-package-search-results .search-entry .entry-name {
96+
@apply font-bold;
97+
color: var(--entry-color);
98+
}
99+
100+
#in-package-search-results .search-entry .prefix-name {
101+
@apply font-semibold;
102+
}
103+
104+
@media (min-width: 40em) {
105+
#in-package-search-results .search-entry:not(.active):not(.open) .entry-comment {
106+
@apply whitespace-nowrap overflow-hidden text-ellipsis;
107+
}
108+
}
109+
110+
#in-package-search-results .active {
111+
@apply bg-primary-100;
112+
}
113+
114+
#in-package-search #in-package-search-results {
115+
@apply hidden;
116+
}
117+
118+
#in-package-search:focus-within #in-package-search-results {
119+
@apply block;
120+
}

src/ocamlorg_frontend/css/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@import "./partials/cards.css";
77
@import "./partials/forms.css";
88
@import "./partials/grid_logos.css";
9+
@import "./partials/in_package_search.css";
910
@import "./partials/search.css";
1011
@import "./partials/package_breadcrumbs.css";
1112
@import "./partials/shadows.css";

0 commit comments

Comments
 (0)