-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new custom local only JavaScript search to avoid google integration
- Loading branch information
Showing
2 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div class="search-box"> | ||
<h5>Search</h5> | ||
<input list="search-completions" id="search-term"> | ||
|
||
<!-- TODO: make even better by not hardcoding possible suggestions. Maybe tags or similar could work? Some type of combinations that make sense as well? | ||
Now it is just a proof of concept to test the idea in production :P | ||
--> | ||
<datalist id="search-completions"> | ||
<option value="Linux" /> | ||
<option value="Emacs" /> | ||
<option value="Emacs packages" /> | ||
<option value="Kotlin books" /> | ||
<option value="Rust" /> | ||
</datalist> | ||
|
||
<button onclick="navigateToSearchPage()">🔍</button> | ||
</div> | ||
|
||
<script> | ||
function navigateToSearchPage() { | ||
const term = document.getElementById('search-term').value; | ||
|
||
window.open(`{{ site.url }}/search.html?term=${term}`, '_self'); | ||
} | ||
|
||
// add enter submission on input field | ||
document.getElementById('search-term').addEventListener('keypress', (event) => { | ||
if ('Enter' == event.key) { | ||
navigateToSearchPage(); | ||
} | ||
}); | ||
|
||
// TODO: can probably unify the code between here and search a bit | ||
const siteUrl = new URL(document.URL); | ||
const searchInput = siteUrl.searchParams.get('term'); | ||
if (null !== searchInput) { | ||
const searchTerm = decodeURIComponent(searchInput); | ||
document.getElementById('search-term').value = searchTerm; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters