Skip to content

Commit 5bd5c31

Browse files
committed
fix search
1 parent 9e07a02 commit 5bd5c31

File tree

14 files changed

+929
-4524
lines changed

14 files changed

+929
-4524
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
run: |
5151
poetry check
5252
poetry install
53+
python -m nltk.downloader punkt
5354
5455
- name: Linter
5556
if: ${{ github.event_name == 'pull_request' }}

conda/dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dependencies:
66
- python <3.12
77
- pip
88
- poetry
9+
- nodejs

mkdocs.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ extra_css:
2828
- css/utilities.css
2929

3030
extra_javascript:
31-
- js/bundle.js
32-
- js/search.js
33-
- js/index.json
3431
- js/theme.js
32+
- js/osl-search.js
33+
- js/vendor/lunr.min.js
34+
- js/vendor/lunr.stemmer.support.min.js
35+
- js/vendor/lunr.multi.min.js
36+
- js/vendor/lunr.es.min.js
37+
- js/vendor/lunr.pt.min.js
3538

3639
nav:
3740
- Blog: "blog/index.md"
@@ -141,3 +144,10 @@ plugins:
141144
enabled: true
142145
enable_creation_date: false
143146
type: iso_date
147+
148+
- search:
149+
lang:
150+
- en
151+
- es
152+
- pt
153+
prebuild_index: true

poetry.lock

Lines changed: 180 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dependencies = [
2323
"beautifulsoup4 (>=4.12.3,<5.0.0)",
2424
"mkdocs-git-revision-date-localized-plugin (>=1.3)",
2525
"mdx-truly-sane-lists (>=1.3,<2.0)",
26+
"lunr[languages] (>=0.8.0)",
27+
"nltk (>=3.9.1)",
2628
]
2729

2830

theme/base.html

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
<link rel="manifest" href="/icons/site.webmanifest">
5959

6060
<link rel="alternate" type="application/rss+xml" href="/feed_rss_created.xml" title="Open Science Labs">
61-
<link rel="alternate" type="application/json" href="/js/index.json" title="Open Science Labs">
6261

6362
<!-- Bootstrap -->
6463
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
@@ -106,25 +105,20 @@
106105
<img src="/images/logos/osl-color-horizontal.png" class="logo" alt="{{ config.site_name }}">
107106
</a>
108107

109-
<!-- Desktop search -->
110-
<div class="mk-search order-lg-2 d-none d-md-block ms-auto me-2">
111-
<input id="mkdocs-search" type="search" class="form-control form-control-sm" placeholder="Search…" aria-label="Search">
112-
<i class="fa fa-search"></i>
113-
</div>
114-
115108
<!-- Mobile toggler (offcanvas) -->
116109
<button class="navbar-toggler ms-2" type="button"
117110
data-bs-toggle="offcanvas" data-bs-target="#offcanvasNav"
118111
aria-controls="offcanvasNav" aria-label="Toggle navigation">
119112
<span class="navbar-toggler-icon"></span>
120113
</button>
121114

122-
<!-- Desktop menu -->
115+
<!-- Desktop menu (grows to fill middle) -->
123116
<div class="collapse navbar-collapse order-lg-1">
124117
<ul class="navbar-nav ms-3">
125118

126119
{% if nav|length > 0 %}
127120
{% for nav_item in nav %}
121+
128122
{% if not nav_item.children %}
129123
<!-- Top-level single page -->
130124
<li class="nav-item {% if nav_item.active %}nav_active{% endif %}">
@@ -148,7 +142,7 @@
148142
</a>
149143

150144
<div class="dropdown-menu mega p-2" role="menu" aria-label="{{ nav_item.title }}">
151-
{# optional Overview link for the section #}
145+
{# Optional Overview link for the section #}
152146
{% set parent_overview = None %}
153147
{% for ch in nav_item.children %}
154148
{% if ch.title in menu_group_titles %}
@@ -186,6 +180,7 @@ <h2 class="accordion-header" id="{{ hdr_id }}">
186180
<div id="{{ col_id }}" class="accordion-collapse collapse"
187181
data-bs-parent="#mega-acc-{{ top_i }}">
188182
<div class="accordion-body p-2">
183+
189184
{% set child_overview = None %}
190185
{% for gc in child.children %}
191186
{% if gc.title in menu_group_titles %}
@@ -200,6 +195,7 @@ <h2 class="accordion-header" id="{{ hdr_id }}">
200195
href="{{ child_overview.url|url }}">Overview</a>
201196
</li>
202197
{% endif %}
198+
203199
{% for gc in child.children %}
204200
{% if gc.title not in menu_group_titles %}
205201
<li>
@@ -209,6 +205,7 @@ <h2 class="accordion-header" id="{{ hdr_id }}">
209205
{% endif %}
210206
{% endfor %}
211207
</ul>
208+
212209
</div>
213210
</div>
214211
</div>
@@ -227,14 +224,35 @@ <h2 class="accordion-header" id="{{ hdr_id }}">
227224
</div>
228225
</li>
229226
{% endif %}
227+
230228
{% endfor %}
231229
{% endif %}
232230

233231
</ul>
234232
</div>
235-
</div>
236-
</nav>
237233

234+
<!-- Desktop search (RIGHT side) -->
235+
<form class="d-none d-lg-block ms-lg-auto order-lg-2 position-relative" role="search">
236+
<label for="mkdocs-search" class="visually-hidden">Search</label>
237+
<div class="input-group input-group-sm searchbar flex-nowrap">
238+
<span class="input-group-text bg-transparent border-0 pe-2">
239+
<svg class="search-icon" viewBox="0 0 24 24" aria-hidden="true">
240+
<circle cx="11" cy="11" r="7" fill="none" stroke="currentColor" stroke-width="2"/>
241+
<line x1="21" y1="21" x2="16.65" y2="16.65" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
242+
</svg>
243+
</span>
244+
<input id="mkdocs-search"
245+
type="search"
246+
class="form-control border-0 bg-transparent"
247+
placeholder="Search…"
248+
autocomplete="off" />
249+
</div>
250+
<!-- results popover anchor -->
251+
<div class="search-popover" id="search-popover-desktop" aria-label="Search results"></div>
252+
</form>
253+
254+
</div>
255+
</nav>
238256

239257
<!-- ========================= MOBILE OFFCANVAS (Accordion) ========================= -->
240258
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasNav" aria-labelledby="offcanvasNavLabel">
@@ -245,10 +263,21 @@ <h5 class="offcanvas-title" id="offcanvasNavLabel">{{ config.site_name }}</h5>
245263

246264
<div class="offcanvas-body">
247265
<!-- Mobile search -->
248-
<div class="mk-search mb-3">
249-
<input id="mkdocs-search-mobile" type="search" class="form-control" placeholder="Search…" aria-label="Search">
250-
<i class="fa fa-search"></i>
251-
</div>
266+
<form class="d-lg-none mb-3" role="search">
267+
<div class="input-group input-group-sm searchbar flex-nowrap">
268+
<span class="input-group-text bg-transparent border-0 pe-2">
269+
<svg class="search-icon" viewBox="0 0 24 24" aria-hidden="true">
270+
<circle cx="11" cy="11" r="7" fill="none" stroke="currentColor" stroke-width="2"/>
271+
<line x1="21" y1="21" x2="16.65" y2="16.65" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
272+
</svg>
273+
</span>
274+
<input id="mkdocs-search-mobile"
275+
type="search"
276+
class="form-control border-0 bg-transparent"
277+
placeholder="Search…"
278+
autocomplete="off" />
279+
</div>
280+
</form>
252281

253282
<!-- Accordion nav -->
254283
<div class="accordion accordion-flush" id="navAccordion">
@@ -482,8 +511,17 @@ <h2 class="accordion-header" id="h-{{ pid }}">
482511
</div>
483512
</footer>
484513

485-
<script type="text/javascript" src="/js/bundle.js" defer></script>
486-
<script src="/js/search.min.js" defer></script>
514+
<!-- Lunr core -->
515+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lunr.min.js" defer></script>
516+
517+
<!-- OPTIONAL: language support (Spanish/Portuguese); keep only what you need -->
518+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/lunr.stemmer.support.min.js" defer></script>
519+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/lunr.es.min.js" defer></script>
520+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/lunr.pt.min.js" defer></script>
521+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/lunr.multi.min.js" defer></script>
522+
523+
<!-- Your search UI/logic (must come after Lunr) -->
524+
<script src="/js/osl-search.js" defer></script>
487525
<script src="/js/theme.js" defer></script>
488526

489527
{% endblock footer %}

theme/css/content.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,17 @@ blockquote{
2828
.notices.note{ border-color: var(--notice-note-border-color); background: var(--notice-note-background); }
2929
.notices.tip{ border-color: var(--notice-tip-border-color); background: var(--notice-tip-background); }
3030
.notices .highlight_wrap{ background: var(--code-bg) !important; }
31+
32+
/* copy-code button */
33+
.copy-code { font-size: .75rem; line-height: 1; }
34+
35+
/* heading anchor mark */
36+
.anchor-link { text-decoration: none; opacity: .6; }
37+
.anchor-link:hover { opacity: 1; }
38+
39+
/* ensure the back-to-top is perfectly round */
40+
.to_top {
41+
width: 48px; height: 48px; border-radius: 50%;
42+
display: grid; place-items: center;
43+
}
44+
.to_top .icon { width: 24px; height: 24px; }

theme/css/nav.css

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,84 @@
162162
/* Back to top */
163163
.to_top{ position: fixed; right: 1rem; bottom: 1rem; z-index: 10; opacity: .9; }
164164
.to_top .icon{ width: 34px; height: 34px; }
165+
166+
167+
/* Keep navbar items on one line and let brand | menu | search align properly */
168+
.navbar > .container-xxl,
169+
.navbar > .container,
170+
.navbar > .container-fluid{
171+
display: flex; /* be explicit */
172+
flex-wrap: nowrap; /* no wrapping */
173+
align-items: center; /* vertical centering */
174+
justify-content: space-between; /* brand left, last item (search) far right */
175+
}
176+
177+
178+
/* Keep icon + input on one line and vertically centered */
179+
.navbar .searchbar { flex-wrap: nowrap; align-items: center; }
180+
181+
/* Make the icon sit nicely in light/dark */
182+
.navbar .searchbar .input-group-text {
183+
display: flex; align-items: center;
184+
color: var(--nav-link); /* inherits your theme */
185+
}
186+
187+
/* Size + feel of the field */
188+
.navbar .searchbar .form-control {
189+
min-width: 20rem; /* adjust as you like */
190+
box-shadow: none !important;
191+
color: var(--nav-link);
192+
}
193+
.navbar .searchbar .form-control::placeholder { opacity: .6; }
194+
195+
/* Tweak for narrower viewports where this form is still visible */
196+
@media (max-width: 1200px){
197+
.navbar .searchbar .form-control { min-width: 14rem; }
198+
}
199+
200+
/* Prevent navbar wrapping that shoves items to a new row */
201+
.navbar .container,
202+
.navbar .container-fluid { flex-wrap: nowrap; align-items: center; }
203+
204+
/* Brand sizing guard — prevents distortion */
205+
.navbar-brand img {
206+
height: 34px; /* adjust if you prefer 32/36 */
207+
width: auto;
208+
object-fit: contain;
209+
display: block;
210+
}
211+
212+
/* Search bar: keep icon + field on one line and nice width */
213+
.navbar .searchbar {
214+
flex-wrap: nowrap;
215+
align-items: center;
216+
width: clamp(12rem, 22vw, 18rem); /* doesn’t push nav items */
217+
}
218+
219+
/* Icon inside the input group (independent of your global .icon rules) */
220+
.navbar .searchbar .search-icon {
221+
width: 16px; height: 16px;
222+
display: block;
223+
}
224+
225+
/* Field look + colors for dark/light */
226+
.navbar .searchbar .form-control {
227+
box-shadow: none !important;
228+
color: var(--nav-link);
229+
}
230+
.navbar .searchbar .form-control::placeholder { opacity: .6; }
231+
232+
/* Make sure the text addon inherits theme color */
233+
.navbar .searchbar .input-group-text {
234+
color: var(--nav-link);
235+
}
236+
237+
/* Slightly shrink on tighter desktops so it never wraps */
238+
@media (max-width: 1200px){
239+
.navbar .searchbar { width: clamp(10rem, 24vw, 14rem); }
240+
}
241+
242+
/* Let the menu take the middle space so search pushes to the edge */
243+
@media (min-width: 992px){
244+
.navbar .navbar-collapse { flex-grow: 1; }
245+
}

theme/css/search.css

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
1-
/* Search fields (desktop + mobile) */
2-
.mk-search{ position: relative; }
3-
.mk-search input{
4-
background: rgba(255,255,255,.06);
5-
border: 1px solid rgba(255,255,255,.12);
6-
color: var(--fg);
7-
border-radius: 999px;
8-
padding-right: 2.5rem;
9-
}
10-
.mk-search .fa{
11-
position: absolute; right: .85rem; top: 50%; transform: translateY(-50%);
12-
color: var(--muted);
1+
/* /css/search.css */
2+
.search-popover{
3+
position: absolute;
4+
left: 0;
5+
right: 0;
6+
top: calc(100% + .25rem);
7+
z-index: 1050;
8+
9+
background: var(--dd-bg, rgba(16,18,27,.98));
10+
border: 1px solid var(--dd-border, rgba(255,255,255,.12));
11+
backdrop-filter: blur(10px);
12+
-webkit-backdrop-filter: blur(10px);
13+
border-radius: .5rem;
14+
padding: .25rem;
15+
box-shadow: 0 8px 30px rgba(0,0,0,.25);
16+
display: none;
17+
max-height: min(60vh, 520px);
18+
overflow: auto;
19+
}
20+
.search-popover.open{ display: block; }
21+
22+
.sr-item{
23+
display: block;
24+
padding: .6rem .7rem;
25+
border-radius: .4rem;
26+
color: var(--fg, #e8eaf0);
27+
text-decoration: none;
28+
}
29+
.sr-item .sr-title{ font-weight: 600; margin-bottom: .15rem; }
30+
.sr-item .sr-snippet{ font-size: .875rem; opacity: .85; line-height: 1.35; }
31+
.sr-item:hover,
32+
.sr-item.active{
33+
background: var(--dd-hover-bg, rgba(255,255,255,.08));
34+
}
35+
36+
.sr-item.muted{ opacity: .7; pointer-events: none; }
37+
38+
mark{
39+
background: color-mix(in oklab, var(--brand, #3b82f6) 28%, transparent);
40+
color: inherit;
41+
padding: 0 .15em;
42+
border-radius: .2em;
43+
}
44+
45+
/* Light-mode tweaks (a bit more contrast) */
46+
[data-bs-theme="light"] .search-popover{
47+
background: #fff;
48+
border-color: rgba(0,0,0,.12);
49+
box-shadow: 0 8px 24px rgba(0,0,0,.12);
50+
}
51+
[data-bs-theme="light"] .sr-item{ color: #1f2937; }
52+
[data-bs-theme="light"] .sr-item:hover,
53+
[data-bs-theme="light"] .sr-item.active{
54+
background: rgba(0,0,0,.05);
1355
}

theme/js/bundle.js

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

0 commit comments

Comments
 (0)