Skip to content

Commit

Permalink
fix: fuse generate /index path, close #366
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Apr 29, 2024
1 parent bbb3b73 commit bfb6304
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions demo/yun/.valaxy/typed-router.d.ts
Expand Up @@ -66,6 +66,7 @@ declare module 'vue-router/auto-routes' {
'/posts/markdown': RouteRecordInfo<'/posts/markdown', '/posts/markdown', Record<never, never>, Record<never, never>>,
'/posts/mermaid': RouteRecordInfo<'/posts/mermaid', '/posts/mermaid', Record<never, never>, Record<never, never>>,
'/posts/nested/a/b/c': RouteRecordInfo<'/posts/nested/a/b/c', '/posts/nested/a/b/c', Record<never, never>, Record<never, never>>,
'/posts/nested/z/': RouteRecordInfo<'/posts/nested/z/', '/posts/nested/z', Record<never, never>, Record<never, never>>,
'/posts/post-updated': RouteRecordInfo<'/posts/post-updated', '/posts/post-updated', Record<never, never>, Record<never, never>>,
'/posts/redirect': RouteRecordInfo<'/posts/redirect', '/posts/redirect', Record<never, never>, Record<never, never>>,
'/posts/test': RouteRecordInfo<'/posts/test', '/posts/test', Record<never, never>, Record<never, never>>,
Expand Down
5 changes: 5 additions & 0 deletions demo/yun/pages/posts/nested/z/index.md
@@ -0,0 +1,5 @@
---
title: Nested Z
---

Nested Z Test for Fuse Search index
13 changes: 3 additions & 10 deletions packages/valaxy-theme-yun/components/YunFuseSearch.vue
Expand Up @@ -4,7 +4,6 @@ import { useFuse } from '@vueuse/integrations/useFuse'
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useSiteConfig } from 'valaxy'
import { useRouter } from 'vue-router'
import type { FuseListItem } from 'valaxy/types'
import { isClient, onClickOutside, useScrollLock } from '@vueuse/core'
Expand Down Expand Up @@ -67,12 +66,6 @@ watch(() => props.open, async () => {
})
})
const router = useRouter()
function jumpToLink(link: string) {
router.push(link)
emit('close')
}
onClickOutside(searchInputRef, () => {
// emit('close')
})
Expand All @@ -98,12 +91,12 @@ onClickOutside(searchInputRef, () => {
</div>
<div v-if="results.length > 0" overflow="auto" flex="~" w="full">
<div class="yun-fuse-result-container" flex="~ col" w="full">
<div
<AppLink
v-for="result in results" :key="result.item.title"
:to="result.item.link"
class="yun-fuse-result-item text-$va-c-text hover:(text-$va-c-bg bg-$va-c-text-dark bg-opacity-100)"
flex="~ col" pb-2
@click="jumpToLink(result.item.link)"
@click="emit('close')"
>
<h3 font="serif black">
{{ result.item.title }}
Expand All @@ -114,7 +107,7 @@ onClickOutside(searchInputRef, () => {
<span text-xs opacity-50 mt="1">
Score Index: {{ result.refIndex }}
</span>
</div>
</AppLink>
</div>
</div>
</div>
Expand Down
20 changes: 14 additions & 6 deletions packages/valaxy-theme-yun/components/YunSelect.vue
Expand Up @@ -12,16 +12,23 @@ const optionVisible = ref(false)
useEventListener('click', () => {
optionVisible.value = false
})
function toggleOptionVisible(e: MouseEvent) {
e.preventDefault()
e.stopImmediatePropagation()
e.stopPropagation()
optionVisible.value = !optionVisible.value
}
</script>

<template>
<div class="relative h-8 w-30 text-[var(--va-c-text-2)] z-100">
<div class="relative h-8 w-30 text-[var(--va-c-text-2)] z-20" @mousedown.stop>
<button
class="flex h-full w-full px-2 items-center justify-between border rounded-2 transition"
class="flex h-full w-full px-2 items-center justify-between border rounded transition"
:class="optionVisible ? 'border-[var(--va-c-primary)] shadow-lg' : ''"
@click.stop="optionVisible = true"
@click="toggleOptionVisible"
>
<span>{{ activeValue }}</span>
<span case-capital op-90>{{ activeValue }}</span>
<div inline-flex i-ri-arrow-down-s-line />
</button>
<Transition>
Expand All @@ -32,7 +39,8 @@ useEventListener('click', () => {
<li
v-for="option in options"
:key="option"
class="cursor-pointer list-none px-2 hover:bg-[var(--va-c-primary-lighter)] hover:text-white"
class="cursor-pointer list-none px-2 hover:bg-[var(--va-c-primary-light)] hover:text-white case-capital"
:class="{ 'bg-[var(--va-c-primary)] text-white': activeValue === option }"
@click="activeValue = option"
>
{{ option }}
Expand All @@ -49,7 +57,7 @@ useEventListener('click', () => {
.v-enter-active,
.v-leave-active {
transition: opacity .3s ease;
transition: opacity .2s ease;
}
.v-enter-from,
Expand Down
9 changes: 8 additions & 1 deletion packages/valaxy/node/modules/fuse.ts
Expand Up @@ -40,14 +40,21 @@ export async function generateFuseList(options: ResolvedValaxyOptions) {
continue

const keys = options.config.siteConfig.fuse.options.keys || []

// adapt for nested folders, like /posts/2021/01/01/index.md
const relativeLink = i.replace(`${options.userRoot}/pages`, '')
const link = i.endsWith('index.md')
? relativeLink.replace(/\/index\.md$/, '')
: relativeLink.replace(/\.md$/, '')

const fuseListItem: FuseListItem = {
title: data.title || '',
tags: (typeof data.tags === 'string' ? [data.tags] : data.tags) || [],
categories: data.categories || [],
author: options.config.siteConfig.author.name,
excerpt: excerpt || content.slice(0, 100),
// encode for chinese url
link: encodeURI(i.replace(`${options.userRoot}/pages`, '').replace(/\.md$/, '')),
link: encodeURI(link),
}
if (keys.includes('content'))
fuseListItem.content = content || ''
Expand Down

1 comment on commit bfb6304

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://662f6f02a18d5e03ebbce954--valaxy.netlify.app

Please sign in to comment.