docs updates, add search to main page, fix redir bug

This commit is contained in:
Jacky Zhao 2021-10-24 23:31:09 -07:00
parent c1c061fbea
commit 22a9c0ddfc
4 changed files with 38 additions and 25 deletions

View file

@ -1,16 +1,28 @@
{{define "head"}}
<!DOCTYPE html>
<html lang="en">
{{ partial "head.html" . }}
{{end}}
{{define "main"}}
<!-- Main Page -->
<body>
{{partial "search.html" .}}
<div class="singlePage">
{{partial "darkmode.html" .}}
{{.Content}}
<!-- Contact Info -->
<div>
{{partial "footer.html" .}}
</div>
<!-- Begin actual content -->
<header>
{{if .Title}}<h1>{{ .Title }}</h1>{{end}}
<svg tabindex="0" id="search-icon" aria-labelledby="title desc" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7"><title id="title">Search Icon</title><desc id="desc">Icon to open search</desc><g class="search-path" fill="none"><path stroke-linecap="square" d="M18.5 18.3l-5.4-5.4"/><circle cx="8" cy="8" r="7"/></g></svg>
<div class="spacer"></div>
{{partial "darkmode.html" .}}
</header>
<article>
{{if $.Site.Data.config.enableToc}}
<aside class="mainTOC">
<h3>Table of Contents</h3>
{{ .TableOfContents }}
</aside>
{{end}}
{{- .Content -}}
</article>
{{partial "footer.html" .}}
</div>
{{end}}
</body>
</html>

View file

@ -126,13 +126,17 @@
</button>`
}
const redir = (id, term) => {
window.location.href = {{.Site.BaseURL}} + `${id}#:~:text=${encodeURIComponent(term)}`
}
const source = document.getElementById('search-bar')
const results = document.getElementById("results-container")
let term
source.addEventListener("keyup", (e) => {
if (e.key === "Enter") {
const anchor = document.getElementsByClassName("result-card")[0]
window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}`
redir(anchor.id, term)
}
})
source.addEventListener('input', (e) => {
@ -163,9 +167,7 @@
.join("\n")
const anchors = document.getElementsByClassName("result-card");
[...anchors].forEach(anchor => {
anchor.onclick = () => {
window.location.href = `${anchor.id}#:~:text=${encodeURIComponent(term)}`
}
anchor.onclick = () => redir(anchor.id, term)
})
}
})