-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
311c23c
commit 6ac3bbb
Showing
9 changed files
with
173 additions
and
0 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
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,4 @@ | ||
--- | ||
title: "Search the Site" | ||
description: "Find what you're looking for quickly and easily." | ||
--- |
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,4 @@ | ||
--- | ||
title: "Sök på webbplatsen" | ||
description: "Hitta snabbt och enkelt det du letar efter." | ||
--- |
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,14 @@ | ||
[ | ||
{{- $pages := .Site.RegularPages -}} | ||
{{- range $index, $page := $pages -}} | ||
{{- if $index }},{{ end }} | ||
{ | ||
"title": {{ $page.Title | jsonify }}, | ||
"url": {{ $page.RelPermalink | jsonify }}, | ||
"tags": {{ $page.Params.tags | jsonify }}, | ||
"keywords": {{ $page.Params.keywords | jsonify }}, | ||
"language": {{ $page.Lang | jsonify }} | ||
} | ||
{{- end -}} | ||
] | ||
|
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
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
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,29 @@ | ||
{{ define "main" }} | ||
<div class="container my-5"> | ||
<!-- Page Header --> | ||
<div class="mb-4 text-center"> | ||
<h1 class="fw-bold search-page-title" style="color: rgb(41, 89, 134);">{{ .Title }}</h1> | ||
<p class="text-muted search-page-description">{{ .Params.description }}</p> | ||
</div> | ||
|
||
<!-- Search Input --> | ||
<div class="input-group mb-4 shadow-sm" style="border-radius: 5px; overflow: hidden;"> | ||
<span class="input-group-text bg-white " style="color: rgb(71, 112, 177);"> | ||
<i class="bi bi-search" aria-hidden="true"></i> | ||
</span> | ||
<input type="text" id="search-input" class="form-control form-control-lg " | ||
placeholder="Type to search..." aria-label="Search" autofocus /> | ||
</div> | ||
|
||
<!-- Search Results --> | ||
<div id="search-results-container"> | ||
<p id="search-results-message" class="text-muted p-3" style="text-align: center; font-size: 14px;"> | ||
Start typing to see results... | ||
</p> | ||
<ul id="search-results" class="list-group"></ul> | ||
</div> | ||
</div> | ||
{{ end }} | ||
|
||
|
||
|
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
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,45 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
const lang = document.documentElement.lang || "en"; // Detect active language | ||
const searchFile = lang === "sv" ? "/sv/search-index.json" : "/search-index.json"; | ||
|
||
fetch(searchFile) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
const options = { | ||
keys: ["title", "tags", "keywords"], // Fields to search | ||
threshold: 0.4, // Fuzzy matching sensitivity | ||
}; | ||
const fuse = new Fuse(data, options); | ||
|
||
const searchInput = document.getElementById("search-input"); | ||
const searchResultsContainer = document.getElementById("search-results-container"); | ||
const searchResultsList = document.getElementById("search-results"); | ||
const searchResultsMessage = document.getElementById("search-results-message"); | ||
|
||
if (searchInput && searchResultsList && searchResultsMessage) { | ||
searchInput.addEventListener("input", function () { | ||
const query = searchInput.value.trim(); | ||
const results = fuse.search(query); | ||
|
||
if (results.length > 0) { | ||
searchResultsMessage.style.display = "none"; | ||
searchResultsList.innerHTML = results | ||
.map( | ||
(result) => ` | ||
<li class="list-group-item"> | ||
<a href="${result.item.url}" class="text-decoration-none"> | ||
${result.item.title} | ||
</a> | ||
</li> | ||
` | ||
) | ||
.join(""); | ||
} else { | ||
searchResultsMessage.style.display = "block"; | ||
searchResultsList.innerHTML = ""; | ||
} | ||
}); | ||
} | ||
}) | ||
.catch((err) => console.error("Error loading search index:", err)); | ||
}); |