Jacky Zhao
2022-02-16 fcd5d2807d2bab68c6776e031e85d65fe88a6f7a
layouts/partials/search.html
@@ -67,6 +67,7 @@
    };
</script>
<script>
async function run() {
    const contentIndex = new FlexSearch.Document({
        cache: true,
        charset: "latin:extra",
@@ -89,6 +90,7 @@
        }
    })
  const { content } = await fetchData()
    for (const [key, value] of Object.entries(content)) {
        contentIndex.add({
            id: key,
@@ -147,7 +149,7 @@
        window.location.href = "{{.Site.BaseURL}}" + `${id}#:~:text=${encodeURIComponent(term)}`
    }
    const fetch = id => ({
  const formatForDisplay = id => ({
        id,
        url: id,
        title: content[id].title,
@@ -185,7 +187,7 @@
                }
            }
            const allIds = new Set([...getByField('title'), ...getByField('content')])
            const finalResults = [...allIds].map(fetch)
      const finalResults = [...allIds].map(formatForDisplay)
            // display
            if (finalResults.length === 0) {
@@ -210,6 +212,7 @@
    const searchContainer = document.getElementById("search-container")
    function openSearch() {
        if (searchContainer.style.display === "none" || searchContainer.style.display === "") {
            source.value = ""
@@ -251,5 +254,7 @@
            evt.stopPropagation()
        })
    })
}
run()
</script>