Jacky Zhao
2021-12-24 5bd5642c99d6d144c9932533dfdc3484bdb72b71
layouts/partials/search.html
@@ -145,7 +145,7 @@
    }
    const redir = (id, term) => {
        window.location.href = "{{.Site.BaseURL}}" + `${id}#:~:text=${encodeURIComponent(term)}`
        window.location.href = "{{.Site.BaseURL}}" + `${id.toLowerCase()}#:~:text=${encodeURIComponent(term)}`
    }
    const fetch = id => ({
@@ -177,10 +177,16 @@
                limit: 5,
            }
        ]).then(searchResults => {
        const titleIds = [...searchResults.filter(x => x.field === 'title')?.[0].result] ?? []
        const contentIds = [...searchResults.filter(x => x.field === 'content')?.[0].result] ?? []
        const allIds = [...titleIds, ...contentIds]
        const finalResults = allIds.map(fetch)
            const getByField = field => {
                const results = searchResults.filter(x => x.field === field)
                if (results.length === 0) {
                    return []
                } else {
                    return [...results[0].result]
                }
            }
            const allIds = new Set([...getByField('title'), ...getByField('content')])
            const finalResults = [...allIds].map(fetch)
            // display
            if (finalResults.length === 0) {
@@ -246,4 +252,4 @@
        })
    })
</script>
</script>