Skip to content

Commit 81d6327

Browse files
improved optional search, with and without navbar
1 parent 3dbdb90 commit 81d6327

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

src/export/project.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
185185
true,
186186
)
187187

188-
if (searchEntry && argument['project-search']) searchIndex.push(searchEntry)
188+
if (searchEntry && argument['project-search'])
189+
searchIndex.push(searchEntry)
189190
subCards += `<div class='col-sm-6 col-md-4 col-lg-3 ${
190191
course.grid ? 'mb-3' : ''
191192
}'>
@@ -236,7 +237,8 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
236237
let { html, json, searchEntry } = await toCard(argument, course)
237238

238239
cards += "<div class='col'>" + html + '</div>'
239-
if (searchEntry && argument['project-search']) searchIndex.push(searchEntry)
240+
if (searchEntry && argument['project-search'])
241+
searchIndex.push(searchEntry)
240242
itemList.push(json)
241243
}
242244
}
@@ -387,7 +389,17 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
387389
<body>
388390
389391
${generateNavbar(json.navbar, !!searchIndex.length)}
390-
${searchIndex.length ? `<!-- Search Modal -->
392+
${
393+
searchIndex.length && !json.navbar
394+
? `<!-- Search FAB -->
395+
<button id="searchFab" type="button" data-bs-toggle="modal" data-bs-target="#searchModal" title="Search (Ctrl+K)" style="position:fixed;bottom:1.5rem;right:1.5rem;z-index:1030;width:52px;height:52px;border-radius:50%;background:#0B6E75;border:none;color:#fff;box-shadow:0 2px 8px rgba(0,0,0,0.25);display:flex;align-items:center;justify-content:center;">
396+
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.415l-3.85-3.85zm-5.242 1.656a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z"/></svg>
397+
</button>`
398+
: ''
399+
}
400+
${
401+
searchIndex.length
402+
? `<!-- Search Modal -->
391403
<div class="modal fade" id="searchModal" tabindex="-1" aria-labelledby="searchModalLabel" aria-hidden="true">
392404
<div class="modal-dialog modal-lg modal-dialog-scrollable">
393405
<div class="modal-content">
@@ -409,7 +421,9 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
409421
<style>
410422
.search-highlight { background-color: rgba(255, 193, 7, 0.4); padding: 0 1px; border-radius: 2px; font-weight: 600; }
411423
.text-truncate-multiline { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
412-
</style>` : ''}
424+
</style>`
425+
: ''
426+
}
413427
<main>
414428
<div class="container-fluid" ${background} >
415429
<section class="py-5 text-center container">
@@ -451,7 +465,9 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
451465
</footer>
452466
453467
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
454-
${searchIndex.length ? `<script src="https://cdn.jsdelivr.net/npm/fuse.js@7.0.0/dist/fuse.min.js"></script>
468+
${
469+
searchIndex.length
470+
? `<script src="https://cdn.jsdelivr.net/npm/fuse.js@7.0.0/dist/fuse.min.js"></script>
455471
<script>
456472
// Compact index: [{t, g, i, u, s: [[sectionTitle, sectionContent, indentation], ...]}]
457473
// Denormalize into flat records for Fuse
@@ -598,7 +614,9 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
598614
document.getElementById('searchResults').innerHTML = '<p class="text-muted px-3">Start typing to search…</p>';
599615
});
600616
});
601-
</script>` : ''}
617+
</script>`
618+
: ''
619+
}
602620
</body>
603621
</html>
604622
`
@@ -607,7 +625,7 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
607625
}
608626

609627
function generateNavbar(navbar: any, hasSearch: boolean = false): string {
610-
if (!navbar && !hasSearch) return ''
628+
if (!navbar) return ''
611629

612630
const bg = navbar?.background || '#0B6E75'
613631
const theme = navbar?.theme === 'light' ? 'navbar-light' : 'navbar-dark'

0 commit comments

Comments
 (0)