Skip to content

Commit

Permalink
feat: latex in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Dec 4, 2022
1 parent 4cd6f7e commit ce5df83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions assets/js/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function htmlToElement(html) {
return template.content.firstChild
}

function initPopover(baseURL, useContextualBacklinks, renderLatex) {
function initPopover(baseURL, useContextualBacklinks) {
const basePath = baseURL.replace(window.location.origin, "")
fetchData.then(({ content }) => {
const links = [...document.getElementsByClassName("internal-link")]
Expand Down Expand Up @@ -42,7 +42,7 @@ function initPopover(baseURL, useContextualBacklinks, renderLatex) {

if (el) {
li.appendChild(el)
if (renderLatex) {
if (LATEX_ENABLED) {
renderMathInElement(el, {
delimiters: [
{ left: '$$', right: '$$', display: false },
Expand Down
10 changes: 10 additions & 0 deletions assets/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ const displayResults = (term, finalResults, extractHighlight = false) => {
}
)
.join("\n")
if (LATEX_ENABLED) {
renderMathInElement(results, {
delimiters: [
{ left: '$$', right: '$$', display: false },
{ left: '$', right: '$', display: false },
],
throwOnError: false
})
}

const anchors = [...document.getElementsByClassName("result-card")]
anchors.forEach((anchor) => {
anchor.onclick = () => redir(anchor.id, term)
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
}}
<script>
const SEARCH_ENABLED = {{.Site.Data.config.search.enableSemanticSearch}}
const LATEX_ENABLED = {{.Site.Data.config.enableLatex}}
const PRODUCTION = {{ hugo.IsProduction }}
const BASE_URL = {{.Site.BaseURL}}
const fetchData = Promise.all([
Expand Down Expand Up @@ -123,8 +124,7 @@
{{if $data.enableLinkPreview | default $.Site.Data.config.enableLinkPreview}}
initPopover(
{{strings.TrimRight "/" .Site.BaseURL }},
{{$data.enableContextualBacklinks | default $.Site.Data.config.enableContextualBacklinks}},
{{$data.enableLatex | default $.Site.Data.config.enableLatex}}
{{$data.enableContextualBacklinks | default $.Site.Data.config.enableContextualBacklinks}}
)
{{end}}

Expand Down

0 comments on commit ce5df83

Please sign in to comment.