Skip to content

Commit

Permalink
fix: site store router refresh when save md file
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 11, 2024
1 parent 69d0df2 commit f2aa963
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
18 changes: 9 additions & 9 deletions packages/valaxy-theme-yun/components/ValaxyMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ onContentUpdated(() => {

<div p="x-4 b-8" class="sm:px-6 lg:px-12 xl:px-16" w="full">
<slot name="main-content">
<Transition appear>
<ValaxyMd :frontmatter="frontmatter">
<YunAiExcerpt v-if="frontmatter.excerpt_type === 'ai' && frontmatter.excerpt" />
<YunMdTimeWarning />

<slot name="main-content-md" />
<slot />
</ValaxyMd>
</Transition>
<!-- <Transition appear> -->
<ValaxyMd :frontmatter="frontmatter">
<YunAiExcerpt v-if="frontmatter.excerpt_type === 'ai' && frontmatter.excerpt" />
<YunMdTimeWarning />

<slot name="main-content-md" />
<slot />
</ValaxyMd>
<!-- </Transition> -->
</slot>

<slot name="main-content-after" />
Expand Down
11 changes: 5 additions & 6 deletions packages/valaxy/client/composables/post.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ComputedRef } from 'vue'
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import type { Post } from 'valaxy'
import { sortByDate } from '../utils'
import { useSiteStore } from '../stores'
import { useRouterStore, useSiteStore } from '../stores'

export function usePostTitle(post: ComputedRef<Post>) {
const { locale } = useI18n()
Expand All @@ -18,12 +18,11 @@ export function usePostTitle(post: ComputedRef<Post>) {
* get all page in 'pages' folder
*/
export function usePageList() {
const router = useRouter()
const routerStore = useRouterStore()
const router = routerStore.router

return computed<Post[]>(() => {
const excludePages = ['/:..all', '/:all(.*)*', '/', '/:path(.*)']
if (!router)
return []

const routes = router.getRoutes()
.filter(i => i.name)
.filter(i => i.meta)
Expand Down
1 change: 1 addition & 0 deletions packages/valaxy/client/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './app'
export * from './router'
export * from './site'
10 changes: 10 additions & 0 deletions packages/valaxy/client/stores/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineStore } from 'pinia'
import { useRouter } from 'vue-router'

export const useRouterStore = defineStore('routerStore', () => {
const router = useRouter()

return {
router,
}
})
14 changes: 8 additions & 6 deletions packages/valaxy/client/stores/site.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { computed, ref } from 'vue'
import { acceptHMRUpdate, defineStore } from 'pinia'
import { useRouter } from 'vue-router'
import { usePostList } from '..'
import { usePostList, useRouterStore } from '..'
import type { PageDataPayload } from '../../types'

/**
Expand All @@ -11,18 +10,21 @@ import type { PageDataPayload } from '../../types'
* - category
*/
export const useSiteStore = defineStore('site', () => {
const routerStore = useRouterStore()
const router = routerStore.router

const reload = ref(1)
// for dev hot reload
const postList = computed(() => {
if (reload.value)
return usePostList().value
const val = usePostList().value
if (reload.value && val)
return val
else
return usePostList().value
return val
})

// const postList = usePostList()

const router = useRouter()
if (router) {
router.isReady().then(() => {
// hot reload when save md
Expand Down

1 comment on commit f2aa963

@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://65c91ceba4e7cf4f4756c6dd--valaxy.netlify.app

Please sign in to comment.