-
Notifications
You must be signed in to change notification settings - Fork 2
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
e676ec3
commit 57e49a6
Showing
8 changed files
with
206 additions
and
333 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,105 @@ | ||
var index = new FlexSearch.Document({ | ||
tokenize: "forward", | ||
cache: 100, | ||
document: { | ||
id: "id", | ||
store: [ | ||
"href", "title", "description", "content", "summary", "date", "type", "url" | ||
], | ||
index: [ | ||
"title", "description", "content", "summary", "date", "type", "url" | ||
] | ||
} | ||
}); | ||
|
||
// Load index data asynchronously | ||
let dataStore = []; | ||
fetch("/search/index.json") | ||
.then(response => response.json()) | ||
.then(data => { | ||
dataStore = data; | ||
data.forEach(item => { | ||
index.add({ | ||
id: item.id, | ||
href: item.href, | ||
title: item.title, | ||
summary: item.summary, | ||
type: item.type, | ||
date: item.date | ||
}); | ||
}); | ||
}) | ||
.catch(error => { | ||
console.error("Error fetching data:", error); | ||
}); | ||
|
||
const searchIcon = document.querySelector("[data-open-modal]"); | ||
const searchOverlay = document.querySelector("[data-modal]"); | ||
var inputElement = document.getElementById("search-query"); | ||
var resultsElement = document.getElementById("search-results"); | ||
console.log(inputElement, resultsElement) | ||
|
||
// Toggle search overlay | ||
searchIcon.addEventListener("click", function() { | ||
searchOverlay.showModal(); | ||
document.body.classList.add("modal-open"); | ||
inputElement.focus(); | ||
}); | ||
|
||
// Close overlay on outside click | ||
searchOverlay.addEventListener("click", function(e) { | ||
if (e.target === searchOverlay) { | ||
searchOverlay.close(); | ||
document.body.classList.remove("modal-open"); | ||
} | ||
}); | ||
|
||
// Search input event | ||
inputElement.addEventListener("input", function() { | ||
var query = inputElement.value; | ||
var results = index.search(query); | ||
|
||
// Clear previous results | ||
resultsElement.innerHTML = ""; | ||
|
||
// Flatten and deduplicate the results | ||
var docIds = new Set(); | ||
results.forEach(function(result) { | ||
if (result.result) { | ||
result.result.forEach(function(id) { | ||
docIds.add(id); | ||
}); | ||
} | ||
}); | ||
|
||
// Display search results | ||
docIds.forEach(function(docId) { | ||
// Find the document in the original data store | ||
var doc = dataStore.find(item => item.id === docId); | ||
if (doc) { | ||
var li = document.createElement("li"); | ||
|
||
// Construct result display | ||
li.innerHTML = ` | ||
<div class="p-1"> | ||
<a class="text-gray-700 bg-neutral-100 dark:text-gray-300 dark:bg-gray-900 dark:hover:bg-sky-600 hover:bg-sky-600 hover:text-gray-300 flex items-center px-3 py-2 rounded-md appearance-none focus:bg-primary-100 dark:focus:bg-primary-900 focus:outline-dotted focus:outline-transparent focus:outline-2" href="/" tabindex="0"> | ||
<div class="grow"> | ||
<div class="-mb-1 text-lg font-bold"> | ||
${doc.title} | ||
</div> | ||
<div class="text-sm text-neutral-500 dark:text-neutral-400 capitalize"> | ||
${doc.type} | ||
<span class="px-2 text-primary-500">·</span> | ||
${doc.date} | ||
</div> | ||
</div> | ||
<div class="ml-2 ltr:block rtl:hidden text-neutral-500">→</div> | ||
</a> | ||
</div> | ||
`; | ||
|
||
li.querySelector("a").href = doc.url; | ||
resultsElement.appendChild(li); | ||
} | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,40 +1,52 @@ | ||
{{ define "main" }} | ||
|
||
{{- $showTitle := .Params.showTitle -}} | ||
{{ $tutorials := .Site.GetPage "section" "tutorials" }} | ||
|
||
<div class="prose-singularisart dark:prose-invert px-4 py-4 md:py-3 md:px-8 max-w-[1000px] mx-auto min-h-[100vh] flex flex-col"> | ||
{{ $tutorials := .Site.GetPage "section" "tutorials" }} | ||
{{- if eq $showTitle true -}} | ||
<h1 class="text-center">{{ .Title }}</h1> | ||
{{- end -}} | ||
{{ .Content }} | ||
|
||
{{ range $tutorials.Pages }} | ||
{{- if not .Params.series }} | ||
{{- $url := .Page.Permalink }} | ||
{{- with .Params.introFile }} | ||
{{- $url = printf "%s%s" $url . }} | ||
{{- end }} | ||
|
||
<div class="mb-[2em]"> | ||
<a class="hover:no-underline text-gray-700 dark:text-gray-300" href={{ $url }}> | ||
<div class="text-[80%] font-small-caps lowercase font-[700]"> | ||
<span>{{ .Page.Date.Format "January 2 Monday, 2006" }}</span> | ||
{{ if ne .Lastmod .Date }} | ||
<span class="px-2 text-primary-500">•</span> | ||
Updated: {{ .Page.Lastmod.Format "January 2 Monday, 2006" }} | ||
{{ end }} | ||
<span class="px-2 text-primary-500">•</span> | ||
<span>{{ .Page.WordCount }} word{{ if (ne .Page.WordCount 1) }}s{{ end }}</span> | ||
<span class="px-2 text-primary-500">•</span> | ||
<span title="reading-time">{{ .Page.ReadingTime }} minute{{ if (ne .Page.ReadingTime 1) }}s{{ end }}</span> | ||
</div> | ||
<h2 class="mb-[0.2em] mr-0 mt-0 ml-0 font-[600] leading-7">{{ .Title }}</h2> | ||
<p class="m-0">{{ .Summary }}</p> | ||
</a> | ||
|
||
<section class="relative"> | ||
<h2>Tutorials</h2> | ||
|
||
Single articles/multi-part series that I've written explaining any topic | ||
that piques my interest. I write them in a way that I would have liked to | ||
have read them when I was learning the topic. Here are the three most | ||
recent tutorials that I've written. | ||
|
||
<br /> | ||
<br /> | ||
|
||
{{ range $tutorials.Pages | first 3 }} | ||
{{ partial "list-tutorial.html" . }} | ||
{{ end }} | ||
|
||
{{- if gt (len $tutorials.Pages) 3 -}} | ||
<div class="text-center"> | ||
<a class="text-primary-500 hover:text-primary-700" href="{{ $tutorials.RelPermalink }}">View More</a> | ||
</div> | ||
{{- end -}} | ||
|
||
{{ partial "line.html" . }} | ||
</section> | ||
|
||
<section class="relative"> | ||
<h2>Projects</h2> | ||
|
||
{{ range $tutorials.Pages | first 3 }} | ||
{{ partial "list-tutorial.html" . }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{- if gt (len $tutorials.Pages) 3 -}} | ||
<div class="text-center"> | ||
<a class="text-primary-500 hover:text-primary-700" href="{{ $tutorials.RelPermalink }}">View More</a> | ||
</div> | ||
{{- end -}} | ||
|
||
{{ partial "line.html" . }} | ||
</section> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="absolute bottom-0 left-0 right-0 mx-auto border-2 border-gray-200 dark:border-gray-800"></div> |
Oops, something went wrong.