Jacky Zhao
2022-04-02 1ddd15afc6e69202080ffb91e8d82deb653a80b7
fix: non-unicode character in popover and search #67, #68
7 files modified
31 ■■■■■ changed files
.github/workflows/deploy.yaml 2 ●●● patch | view | raw | blame | history
assets/js/popover.js 1 ●●●● patch | view | raw | blame | history
assets/js/search.js 22 ●●●●● patch | view | raw | blame | history
content/_index.md 1 ●●●● patch | view | raw | blame | history
layouts/_default/single.html 3 ●●●● patch | view | raw | blame | history
layouts/index.html 2 ●●● patch | view | raw | blame | history
layouts/partials/backlinks.html patch | view | raw | blame | history
.github/workflows/deploy.yaml
@@ -12,7 +12,7 @@
      - uses: actions/checkout@v2
      - name: Build Link Index
        uses: jackyzha0/hugo-obsidian@v2.10
        uses: jackyzha0/hugo-obsidian@v2.11
        with:
          index: true
          input: content
assets/js/popover.js
@@ -12,7 +12,6 @@
            const links = [...document.getElementsByClassName("internal-link")]
            links.forEach(li => {
                const linkDest = content[li.dataset.src.replace(basePath, "")]
                // const linkDest = content[li.dataset.src]
                if (linkDest) {
                    const popoverElement = `<div class="popover">
    <h3>${linkDest.title}</h3>
assets/js/search.js
@@ -59,26 +59,20 @@
// -----
(async function () {
  const encoder = str => str.toLowerCase().split(/([^a-z]|[^\x00-\x7F])+/)
    const contentIndex = new FlexSearch.Document({
        cache: true,
        charset: "latin:extra",
        optimize: true,
        worker: true,
        document: {
            index: [{
                field: "content",
                tokenize: "strict",
                context: {
                    resolution: 5,
                    depth: 3,
                    bidirectional: true
                },
                suggest: true,
      tokenize: "reverse",
      encode: encoder,
            }, {
                field: "title",
                tokenize: "forward",
      encode: encoder,
            }]
        }
    })
    const { content } = await fetchData
@@ -158,17 +152,16 @@
    })
    source.addEventListener('input', (e) => {
        term = e.target.value
        contentIndex.search(term, [
    const searchResults = contentIndex.search(term, [
            {
                field: "content",
                limit: 10,
                suggest: true,
            },
            {
                field: "title",
                limit: 5,
            }
        ]).then(searchResults => {
    ])
            const getByField = field => {
                const results = searchResults.filter(x => x.field === field)
                if (results.length === 0) {
@@ -199,7 +192,6 @@
                })
            }
        })
    })
    const searchContainer = document.getElementById("search-container")
@@ -220,7 +212,7 @@
    }
    document.addEventListener('keydown', (event) => {
        if (event.key === "/") {
    if (event.key === "k" && (event.ctrlKey || event.metaKey)) {
            event.preventDefault()
            openSearch()
        }
content/_index.md
@@ -24,4 +24,3 @@
- 🚧 [Troubleshooting and FAQ](notes/troubleshooting.md)
- 🐛 [Submit an Issue](https://github.com/jackyzha0/quartz/issues)
- 👀 [Discord Community](https://discord.gg/cRFFHYye7t)
layouts/_default/single.html
@@ -28,8 +28,7 @@
          {{ .TableOfContents }}
      </aside>
      {{end}}
      {{.Content}}
      {{.Content | safeHTML}}
    </article>
    {{partial "footer.html" .}}
    {{partial "popover.html" .}}
layouts/index.html
@@ -19,7 +19,7 @@
            {{ .TableOfContents }}
        </aside>
        {{end}}
        {{- .Content -}}
        {{.Content | safeHTML}}
    </article>
    {{partial "footer.html" .}}
    {{partial "popover.html" .}}
layouts/partials/backlinks.html