valaxy 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/bin/valaxy.mjs +1 -5
  2. package/client/components/ValaxyDecrypt.vue +6 -25
  3. package/client/components/ValaxyDynamicComponent.vue +13 -34
  4. package/client/components/ValaxyFootnoteTooltip.vue +140 -11
  5. package/client/composables/app/index.ts +1 -0
  6. package/client/composables/app/usePageSeo.ts +40 -0
  7. package/client/composables/app/useValaxyApp.ts +24 -23
  8. package/client/composables/app/useValaxyHead.ts +5 -12
  9. package/client/composables/dark.ts +8 -1
  10. package/client/composables/post/filter.ts +1 -1
  11. package/client/composables/post/index.ts +4 -4
  12. package/client/composables/search/index.ts +2 -0
  13. package/client/composables/search/package.json +4 -0
  14. package/client/composables/search/useFuseSearch.ts +1 -1
  15. package/client/composables/widgets/backToTop.ts +30 -6
  16. package/client/main.ts +6 -6
  17. package/client/runtime/ValaxyRuntimeTemplate.vue +26 -0
  18. package/client/setup/main.ts +0 -2
  19. package/client/shims.d.ts +4 -0
  20. package/client/stores/router.ts +12 -0
  21. package/client/stores/site.ts +5 -50
  22. package/client/utils/index.ts +1 -0
  23. package/client/utils/seo.ts +79 -0
  24. package/client/utils/time.ts +7 -4
  25. package/dist/node/cli/index.mjs +2 -3
  26. package/dist/node/index.d.mts +295 -48
  27. package/dist/node/index.mjs +2 -3
  28. package/dist/shared/{valaxy.BTmQYjWn.mjs → valaxy.BrBGPvyF.mjs} +1250 -210
  29. package/dist/shared/{valaxy.EzGcrVef.d.mts → valaxy.Jqi53gnQ.d.mts} +42 -15
  30. package/dist/types/index.d.mts +2 -2
  31. package/package.json +4 -5
  32. package/shared/index.ts +2 -0
  33. package/shared/page-policy.ts +123 -0
  34. package/shared/seo.ts +182 -0
  35. package/types/config.ts +39 -17
  36. package/types/vue-router.d.ts +4 -0
  37. package/vendor/README.md +4 -4
  38. package/client/components/footnote/FootnotePopover.vue +0 -146
  39. package/client/components/footnote/LegacyFootnoteTooltip.vue +0 -25
  40. package/client/modules/floating-vue.ts +0 -11
  41. package/vendor/ensure-gray-matter.d.ts +0 -1
  42. package/vendor/ensure-gray-matter.mjs +0 -23
  43. package/vendor/redirect-gray-matter.mjs +0 -30
package/bin/valaxy.mjs CHANGED
@@ -2,13 +2,9 @@
2
2
  'use strict'
3
3
 
4
4
  import process from 'node:process'
5
- import { ensureGrayMatterRedirect } from '../vendor/ensure-gray-matter.mjs'
5
+ import { run } from '../dist/node/cli/index.mjs'
6
6
 
7
7
  async function main() {
8
- // gray-matter 4 crashes at import when js-yaml 5 is resolved. Install the
9
- // redirect before the CLI graph loads @mdit-vue/plugin-frontmatter.
10
- await ensureGrayMatterRedirect()
11
- const { run } = await import('../dist/node/cli/index.mjs')
12
8
  await run()
13
9
  }
14
10
 
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import { isClient } from '@vueuse/core'
3
3
  import { runContentUpdated, useDecrypt, useFrontmatter } from 'valaxy'
4
- import { computed, defineComponent, h, ref } from 'vue'
4
+ import { computed, ref } from 'vue'
5
5
 
6
6
  const props = withDefaults(defineProps<{
7
7
  encryptedContent: string
@@ -16,6 +16,7 @@ const decryptedContent = ref('')
16
16
  const hasError = ref(false)
17
17
 
18
18
  const { decrypt } = useDecrypt()
19
+ const frontmatter = useFrontmatter()
19
20
  async function decryptContent() {
20
21
  const ciphertext = props.encryptedContent
21
22
  if (!ciphertext)
@@ -23,10 +24,6 @@ async function decryptContent() {
23
24
  try {
24
25
  const result = await decrypt(password.value, ciphertext)
25
26
  decryptedContent.value = result || ''
26
-
27
- setTimeout(() => {
28
- runContentUpdated()
29
- }, 16)
30
27
  }
31
28
  catch (e) {
32
29
  hasError.value = true
@@ -43,25 +40,6 @@ function encryptAgain() {
43
40
  }, 16)
44
41
  }
45
42
 
46
- const ValaxyDeprecatedContent = defineComponent({
47
- name: 'ValaxyDeprecatedContent',
48
- props: {
49
- html: String,
50
- },
51
- render() {
52
- const content = `<div>${this.html}</div>`
53
- return h({
54
- setup: () => {
55
- const fm = useFrontmatter()
56
- return {
57
- frontmatter: fm,
58
- }
59
- },
60
- template: content,
61
- })
62
- },
63
- })
64
-
65
43
  const hasWarning = computed(() => isClient && location.protocol !== 'https:')
66
44
  </script>
67
45
 
@@ -102,7 +80,10 @@ const hasWarning = computed(() => isClient && location.protocol !== 'https:')
102
80
  </div>
103
81
  </div>
104
82
  <div v-else>
105
- <ValaxyDeprecatedContent :html="decryptedContent" />
83
+ <ValaxyDynamicComponent
84
+ :template-str="decryptedContent" :data="{ frontmatter }"
85
+ @rendered="runContentUpdated"
86
+ />
106
87
  <div class="decrypt-action mb-8 sm:mb-0" w-full text-center mt-8>
107
88
  <button m-auto class="btn" font-bold @click="encryptAgain">
108
89
  Encrypt Again
@@ -1,41 +1,20 @@
1
1
  <script setup lang="ts">
2
- import type { Component } from 'vue'
3
- import { compile, computed, defineComponent } from 'vue'
2
+ import { defineAsyncComponent } from 'vue'
4
3
 
5
- const props = withDefaults(
6
- defineProps<{
7
- templateStr: string
8
- data?: Record<string, any>
9
- }>(),
10
- {
11
- data: () => ({}),
12
- },
13
- )
4
+ defineProps<{
5
+ templateStr: string
6
+ data?: Record<string, any>
7
+ }>()
8
+ const emit = defineEmits<{ rendered: [] }>()
14
9
 
15
- // Separate compile from component creation — compile() is expensive and
16
- // should only re-run when the template string itself changes.
17
- const compiledRender = computed(() => {
18
- if (!props.templateStr)
19
- return null
20
- return compile(props.templateStr)
21
- })
22
-
23
- // defineComponent creates a proper component instance so that compile()'s
24
- // render function can access data properties through the instance context.
25
- // Avoids defineAsyncComponent which causes "missing template" warnings in SSG.
26
- const dynamicComponent = computed<Component | null>(() => {
27
- const render = compiledRender.value
28
- if (!render)
29
- return null
30
- return defineComponent({
31
- data: () => ({ ...props.data }),
32
- render,
33
- })
34
- })
10
+ // Vue's async component boundary also preserves server-rendered content while
11
+ // the compiler loads during hydration, without requiring a parent Suspense.
12
+ const ValaxyRuntimeTemplate = defineAsyncComponent(() => import('../runtime/ValaxyRuntimeTemplate.vue'))
35
13
  </script>
36
14
 
37
15
  <template>
38
- <div v-if="dynamicComponent">
39
- <component :is="dynamicComponent" />
40
- </div>
16
+ <ValaxyRuntimeTemplate
17
+ v-if="templateStr" :template-str="templateStr" :data="data"
18
+ @rendered="emit('rendered')"
19
+ />
41
20
  </template>
@@ -1,17 +1,146 @@
1
1
  <script setup lang="ts">
2
- import { useSiteConfig } from '../config'
3
- import FootnotePopover from './footnote/FootnotePopover.vue'
4
- import LegacyFootnoteTooltip from './footnote/LegacyFootnoteTooltip.vue'
2
+ import { PopoverArrow, PopoverClose, PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
3
+ import { onBeforeUnmount, shallowRef } from 'vue'
4
+ import { useI18n } from 'vue-i18n'
5
5
 
6
- const siteConfig = useSiteConfig()
6
+ const { t } = useI18n()
7
+ const open = shallowRef(false)
8
+ // Hover previews must neither steal focus nor return it when dismissed.
9
+ const interactive = shallowRef(false)
10
+ const contentFocused = shallowRef(false)
11
+ let closeTimer: ReturnType<typeof setTimeout> | undefined
12
+
13
+ function cancelClose() {
14
+ clearTimeout(closeTimer)
15
+ }
16
+
17
+ function preview(event: PointerEvent) {
18
+ if (event.pointerType === 'touch')
19
+ return
20
+ cancelClose()
21
+ if (!open.value) {
22
+ interactive.value = false
23
+ open.value = true
24
+ }
25
+ }
26
+
27
+ function scheduleClose() {
28
+ cancelClose()
29
+ closeTimer = setTimeout(() => {
30
+ if (!interactive.value && !contentFocused.value)
31
+ open.value = false
32
+ }, 200)
33
+ }
34
+
35
+ function updateOpen(value: boolean) {
36
+ cancelClose()
37
+ if (value)
38
+ interactive.value = true
39
+ open.value = value
40
+ }
41
+
42
+ function followFootnote() {
43
+ cancelClose()
44
+ interactive.value = false
45
+ open.value = false
46
+ }
47
+
48
+ function autoFocus(event: Event) {
49
+ if (!interactive.value)
50
+ event.preventDefault()
51
+ }
52
+
53
+ onBeforeUnmount(cancelClose)
7
54
  </script>
8
55
 
9
56
  <template>
10
- <component :is="siteConfig.footnote.preview === 'floating-vue' ? LegacyFootnoteTooltip : FootnotePopover">
11
- <slot />
12
-
13
- <template #popper>
14
- <slot name="popper" />
15
- </template>
16
- </component>
57
+ <PopoverRoot :open="open" :modal="false" @update:open="updateOpen">
58
+ <span class="va-footnote">
59
+ <span @pointerenter="preview" @pointerleave="scheduleClose" @click="followFootnote">
60
+ <slot />
61
+ </span>
62
+ <PopoverTrigger
63
+ class="va-footnote-preview"
64
+ :aria-label="t('post.footnote_preview')"
65
+ @pointerenter="cancelClose"
66
+ @pointerleave="scheduleClose"
67
+ >
68
+ <span aria-hidden="true">⋯</span>
69
+ </PopoverTrigger>
70
+ <PopoverPortal to="#valaxy-teleports">
71
+ <PopoverContent
72
+ class="va-footnote-popover markdown-body"
73
+ side="top"
74
+ :side-offset="8"
75
+ :collision-padding="12"
76
+ @open-auto-focus="autoFocus"
77
+ @close-auto-focus="autoFocus"
78
+ @pointerenter="cancelClose"
79
+ @pointerleave="scheduleClose"
80
+ @focusin="contentFocused = true"
81
+ @focusout="contentFocused = false"
82
+ >
83
+ <PopoverClose class="va-footnote-close" :aria-label="t('post.footnote_close')">
84
+ <span aria-hidden="true">×</span>
85
+ </PopoverClose>
86
+ <slot name="popper" />
87
+ <PopoverArrow class="va-footnote-arrow" />
88
+ </PopoverContent>
89
+ </PopoverPortal>
90
+ </span>
91
+ </PopoverRoot>
17
92
  </template>
93
+
94
+ <style>
95
+ .va-footnote {
96
+ display: inline-block;
97
+ }
98
+
99
+ .va-footnote-preview {
100
+ vertical-align: super;
101
+ padding: 0 0.2em;
102
+ color: var(--va-c-primary);
103
+ font-size: 0.75em;
104
+ line-height: 1;
105
+ cursor: pointer;
106
+ }
107
+
108
+ .va-footnote-popover {
109
+ box-sizing: border-box;
110
+ z-index: 100;
111
+ width: max-content;
112
+ max-width: min(24rem, var(--reka-popover-content-available-width));
113
+ max-height: var(--reka-popover-content-available-height);
114
+ overflow: auto;
115
+ padding: 0.75rem 1rem;
116
+ border: 1px solid var(--va-c-divider);
117
+ border-radius: 0.5rem;
118
+ background: var(--va-c-bg);
119
+ color: var(--va-c-text);
120
+ box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
121
+ font-size: 0.875rem;
122
+ line-height: 1.6;
123
+ overflow-wrap: anywhere;
124
+ }
125
+
126
+ .va-footnote-popover > p:last-of-type {
127
+ margin-bottom: 0;
128
+ }
129
+
130
+ .va-footnote-close {
131
+ float: right;
132
+ margin-inline-start: 0.5rem;
133
+ padding: 0 0.25rem;
134
+ cursor: pointer;
135
+ }
136
+
137
+ .va-footnote-preview:focus-visible,
138
+ .va-footnote-close:focus-visible {
139
+ outline: 2px solid var(--va-c-primary);
140
+ outline-offset: 2px;
141
+ }
142
+
143
+ .va-footnote-arrow {
144
+ fill: var(--va-c-bg);
145
+ }
146
+ </style>
@@ -1,2 +1,3 @@
1
+ export * from './usePageSeo'
1
2
  export * from './useValaxyApp'
2
3
  export * from './useValaxyHead'
@@ -0,0 +1,40 @@
1
+ import { computed } from 'vue'
2
+ import { useRoute } from 'vue-router'
3
+ import { openGraphType, pickPageShareImage } from '../../../shared/seo'
4
+ import { useSiteConfig } from '../../config'
5
+ import { resolveSiteUrl } from '../../utils/path'
6
+ import { resolveCanonicalPath, resolveShareImage } from '../../utils/seo'
7
+ import { useFrontmatter } from '../common'
8
+ import { useValaxyI18n } from '../locale'
9
+
10
+ function asText(value: unknown): string {
11
+ return typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : ''
12
+ }
13
+
14
+ /**
15
+ * Description, canonical URL, share image, and Open Graph type for the current page.
16
+ * A page without frontmatter `description` uses the plain-text excerpt prepared at build time.
17
+ */
18
+ export function usePageSeo() {
19
+ const fm = useFrontmatter()
20
+ const route = useRoute()
21
+ const siteConfig = useSiteConfig()
22
+ const { $t, $tO } = useValaxyI18n()
23
+
24
+ const description = computed(() => {
25
+ return asText($tO(fm.value.description))
26
+ || asText(route.meta.seoDescription)
27
+ || asText($t(siteConfig.value.description))
28
+ })
29
+
30
+ const routePath = computed(() => resolveCanonicalPath(route))
31
+ const pagePath = computed(() => fm.value.canonical || routePath.value)
32
+ const pageUrl = computed(() => resolveSiteUrl(siteConfig.value.url, pagePath.value))
33
+ const image = computed(() => {
34
+ const src = pickPageShareImage(fm.value)
35
+ return src ? resolveShareImage(siteConfig.value.url, routePath.value, src) : undefined
36
+ })
37
+ const type = computed(() => openGraphType(route.path, route.meta.layout))
38
+
39
+ return { description, pageUrl, image, type }
40
+ }
@@ -3,10 +3,12 @@ import { useSeoMeta } from '@unhead/vue'
3
3
  import { computed } from 'vue'
4
4
  import { useI18n } from 'vue-i18n'
5
5
  import { useRoute } from 'vue-router'
6
+ import { publicAuthor } from '../../../shared/seo'
6
7
  import { useFrontmatter, useLocale, useValaxyHead, useValaxyI18n } from '../../composables'
7
8
  import { useTimezone } from '../../composables/global'
8
9
  import { useSiteConfig } from '../../config'
9
- import { resolveSiteUrl } from '../../utils'
10
+ import { resolveSocialSameAs } from '../../utils/seo'
11
+ import { usePageSeo } from './usePageSeo'
10
12
  // https://github.com/vueuse/head
11
13
  // you can use this to manipulate the document head in any components,
12
14
  // they will be rendered correctly in the html results with vite-ssg
@@ -18,8 +20,6 @@ export function useValaxyApp() {
18
20
  const { locale } = useI18n()
19
21
  const { $t, $tO } = useValaxyI18n()
20
22
 
21
- const title = computed(() => $tO(fm.value.title))
22
-
23
23
  const route = useRoute()
24
24
  const { toggleLocale } = useLocale()
25
25
  // if lang exist, toggle the locale
@@ -28,16 +28,12 @@ export function useValaxyApp() {
28
28
  }
29
29
 
30
30
  // seo
31
- const siteUrl = computed(() => resolveSiteUrl(
32
- siteConfig.value.url,
33
- fm.value.url || route.path,
34
- ))
35
- const description = computed(() => $tO(fm.value.excerpt) || $tO(fm.value.description) || $t(siteConfig.value.description))
36
- const ogImage = computed(() => resolveSiteUrl(
37
- siteConfig.value.url,
38
- fm.value.ogImage || fm.value.cover || fm.value.firstImage || siteConfig.value.favicon,
39
- ))
31
+ const { description, pageUrl, image, type } = usePageSeo()
40
32
  const seoTitle = computed(() => $tO(fm.value.title) || $t(siteConfig.value.title))
33
+ const author = publicAuthor(siteConfig.value.author)
34
+ const personUrl = author.link && /^https?:\/\//.test(author.link)
35
+ ? author.link
36
+ : (/^https?:\/\//.test(siteConfig.value.url) ? siteConfig.value.url : undefined)
41
37
 
42
38
  useSeoMeta({
43
39
  description,
@@ -46,32 +42,37 @@ export function useValaxyApp() {
46
42
  ogLocaleAlternate: computed(() => siteConfig.value.languages.filter(l => l !== locale.value)),
47
43
  ogSiteName: computed(() => $t(siteConfig.value.title)),
48
44
  ogTitle: seoTitle,
49
- ogImage,
50
- ogImageAlt: seoTitle,
51
- ogType: 'website',
52
- ogUrl: siteUrl,
53
- twitterCard: 'summary_large_image',
45
+ ogImage: image,
46
+ ogImageAlt: image.value ? seoTitle : undefined,
47
+ ogType: type,
48
+ ogUrl: pageUrl,
49
+ twitterCard: computed(() => image.value ? 'summary_large_image' : 'summary'),
54
50
  twitterDescription: description,
55
- twitterImage: ogImage,
51
+ twitterImage: image,
56
52
  twitterTitle: seoTitle,
57
53
  })
58
54
 
59
55
  // for SEO
60
56
  useSchemaOrg([
61
57
  // https://unhead.unjs.io/docs/schema-org/guides/recipes/identity
62
- // Personal Website or Blog
58
+ // Personal Website or Blog. url is the author's link, or the site when that link is unset.
63
59
  definePerson({
64
60
  name: $t(siteConfig.value.author.name),
65
- url: siteConfig.value.url,
61
+ ...(personUrl ? { url: personUrl } : {}),
66
62
  image: $t(siteConfig.value.author.avatar),
67
- sameAs: siteConfig.value.social.map(s => s.link),
63
+ sameAs: resolveSocialSameAs(siteConfig.value.url, siteConfig.value.social, siteConfig.value.feed?.name),
68
64
  }),
69
65
  defineWebSite({
70
- name: title.value,
66
+ name: $t(siteConfig.value.title),
67
+ description: $t(siteConfig.value.description),
68
+ }),
69
+ defineWebPage({
70
+ name: seoTitle,
71
+ description,
72
+ url: pageUrl,
71
73
  datePublished: computed(() => fm.value.date),
72
74
  dateModified: computed(() => fm.value.updated),
73
75
  }),
74
- defineWebPage(),
75
76
  ])
76
77
 
77
78
  useTimezone()
@@ -1,27 +1,20 @@
1
1
  import { useHead } from '@unhead/vue'
2
2
  import { computed, onMounted } from 'vue'
3
- import { useRoute } from 'vue-router'
4
3
  import pkg from '../../../package.json' with { type: 'json' }
5
4
 
6
5
  import { useFrontmatter, useValaxyI18n } from '../../composables'
7
6
  import { useSiteConfig } from '../../config'
8
- import { resolveSiteUrl, withBase } from '../../utils'
7
+ import { withBase } from '../../utils'
8
+ import { usePageSeo } from './usePageSeo'
9
9
 
10
10
  export function useValaxyHead() {
11
11
  const { $t, $tO, locale } = useValaxyI18n()
12
12
 
13
13
  const fm = useFrontmatter()
14
- const route = useRoute()
15
14
  const siteConfig = useSiteConfig()
15
+ const { description, pageUrl } = usePageSeo()
16
16
  const $title = computed(() => $tO(fm.value.title))
17
- const canonicalUrl = computed(() => {
18
- const siteUrl = siteConfig.value.url
19
- if (!/^https?:\/\//.test(siteUrl))
20
- return ''
21
-
22
- const pagePath = fm.value.canonical || fm.value.url || route.path
23
- return resolveSiteUrl(siteUrl, pagePath)
24
- })
17
+ const canonicalUrl = computed(() => /^https?:\/\//.test(siteConfig.value.url) ? pageUrl.value : '')
25
18
 
26
19
  useHead({
27
20
  htmlAttrs: {
@@ -43,7 +36,7 @@ export function useValaxyHead() {
43
36
  computed(() => {
44
37
  return {
45
38
  name: 'description',
46
- content: $tO(fm.value.description) || $t(siteConfig.value.description),
39
+ content: description.value,
47
40
  }
48
41
  }),
49
42
  {
@@ -21,7 +21,14 @@ export function useValaxyDark(options: {
21
21
  dark?: string
22
22
  }
23
23
  } = {}) {
24
- const isDark = useDark(options.useDarkOptions)
24
+ const isDark = useDark(options.useDarkOptions ?? {
25
+ onChanged(dark, applyMode, mode) {
26
+ // The document may already have the right theme before Vue starts.
27
+ // Skip VueUse's transition suppression and style flush in that case.
28
+ if (typeof document !== 'undefined' && document.documentElement.classList.contains('dark') !== dark)
29
+ applyMode(mode)
30
+ },
31
+ })
25
32
  const toggleDark = useToggle(isDark)
26
33
 
27
34
  const themeColor = computed(() => isDark.value
@@ -18,7 +18,7 @@ export function filterAndSortPosts(
18
18
  i.path?.startsWith(pathPrefix)
19
19
  && !i.path?.endsWith('.html')
20
20
  && i.date
21
- && (import.meta.env.DEV || !i.draft) // filter draft posts in production (SSG safety net)
21
+ && (import.meta.env.DEV || siteConfig.publishing?.drafts || !i.draft) // filter draft posts in production (SSG safety net)
22
22
  && (!params.type || i.type === params.type)
23
23
  && (!i.hide || i.hide === 'index'), // hide `hide: all` posts
24
24
  )
@@ -27,12 +27,12 @@ export function usePostTitle(post: ComputedRef<Post>) {
27
27
  * get all page in 'pages' folder
28
28
  */
29
29
  export function usePageList() {
30
+ const siteConfig = useSiteConfig()
30
31
  const routerStore = useRouterStore()
31
- const router = routerStore.router
32
32
 
33
33
  return computed<Post[]>(() => {
34
34
  const excludePages = ['/:..all', '/:all(.*)*', '/', '/:path(.*)']
35
- const routes = router.getRoutes()
35
+ const routes = routerStore.routes
36
36
  // Exclude alias routes (e.g. abbrlink) to avoid duplicate entries
37
37
  // router.getRoutes() returns alias routes as separate RouteRecordNormalized
38
38
  // entries with aliasOf pointing to the original record
@@ -40,9 +40,9 @@ export function usePageList() {
40
40
  .filter(i => i.name)
41
41
  .filter(i => i.meta)
42
42
  .filter(i => i.meta!.frontmatter)
43
- // In production, draft routes are already removed before registration (see main.ts filterDraft).
43
+ // Keep this safety net consistent with the router publishing policy.
44
44
  // In dev, they remain in the router so they can be previewed.
45
- .filter(i => import.meta.env.DEV || !i.meta!.frontmatter!.draft)
45
+ .filter(i => import.meta.env.DEV || siteConfig.value.publishing?.drafts || !i.meta!.frontmatter!.draft)
46
46
  .filter(i => i.path && !excludePages.includes(i.path))
47
47
  .map((i) => {
48
48
  return { path: i.path, excerpt: i.meta!.excerpt, ...i.meta!.frontmatter || {} } as Post
@@ -1,2 +1,4 @@
1
+ // This directory is marked side-effect-free. Keep initialization inside the
2
+ // composables so re-exporting them does not eagerly load unused search providers.
1
3
  export * from './useFuseSearch'
2
4
  export * from './useLocalSearch'
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": false
4
+ }
@@ -2,8 +2,8 @@ import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
2
2
  import type { MaybeRefOrGetter } from 'vue'
3
3
  import type { FuseListItem } from '../../../types'
4
4
  import { useFuse } from '@vueuse/integrations/useFuse'
5
- import { useSiteConfig } from 'valaxy'
6
5
  import { computed, shallowRef } from 'vue'
6
+ import { useSiteConfig } from '../../config'
7
7
 
8
8
  export function useFuseSearch<T extends FuseListItem = FuseListItem>(
9
9
  search: MaybeRefOrGetter<string>,
@@ -1,5 +1,22 @@
1
- import { isClient, useWindowScroll } from '@vueuse/core'
2
- import { computed, ref } from 'vue'
1
+ import { createSharedComposable, isClient, useEventListener, useRafFn, useResizeObserver, useWindowSize } from '@vueuse/core'
2
+ import { computed, shallowRef } from 'vue'
3
+
4
+ /** Track only the vertical offset, without measuring scroll boundaries. */
5
+ export const useWindowScrollY = createSharedComposable(() => {
6
+ const y = shallowRef(0)
7
+
8
+ if (isClient) {
9
+ const update = () => {
10
+ y.value = window.scrollY
11
+ }
12
+
13
+ useEventListener('scroll', update, { passive: true })
14
+ // Pick up restored scroll positions outside the hydration task.
15
+ useRafFn(update, { once: true })
16
+ }
17
+
18
+ return computed(() => y.value)
19
+ })
3
20
 
4
21
  /**
5
22
  * You can use href="#" to back to top
@@ -15,14 +32,21 @@ export function useBackToTop(options: {
15
32
  }) {
16
33
  if (!isClient) {
17
34
  return {
18
- percentage: ref(0),
19
- show: ref(false),
35
+ percentage: shallowRef(0),
36
+ show: shallowRef(false),
20
37
  }
21
38
  }
22
39
 
23
- const { y } = useWindowScroll()
40
+ const y = useWindowScrollY()
41
+ const documentHeight = shallowRef(0)
42
+ const { height: viewportHeight } = useWindowSize()
43
+ // Read the document height after layout and reuse it between size changes.
44
+ useResizeObserver([document.body, document.documentElement], () => {
45
+ documentHeight.value = document.scrollingElement?.scrollHeight ?? 0
46
+ })
24
47
  const percentage = computed(() => {
25
- return y.value / (document.body.scrollHeight - window.innerHeight)
48
+ const scrollRange = documentHeight.value - viewportHeight.value
49
+ return scrollRange > 0 ? y.value / scrollRange : 0
26
50
  })
27
51
 
28
52
  const show = computed(() => y.value > options.offset)
package/client/main.ts CHANGED
@@ -5,6 +5,7 @@ import { setupLayouts } from 'virtual:generated-layouts'
5
5
  import { createSSRApp, createApp as vueCreateApp } from 'vue'
6
6
  import { createMemoryHistory, createRouter, createWebHistory } from 'vue-router'
7
7
  import { routes as autoRoutes, handleHotUpdate } from 'vue-router/auto-routes'
8
+ import { omitProductionDraftRoutes } from '../shared/page-policy'
8
9
 
9
10
  // import App from '/@valaxyjs/App.vue'
10
11
  import App from './App.vue'
@@ -12,6 +13,7 @@ import { initData } from './app/data'
12
13
  import ClientOnly from './components/ClientOnly'
13
14
 
14
15
  import setupMain from './setup/main'
16
+ import { useRouterStore } from './stores/router'
15
17
  import { setupValaxyDevTools } from './utils/dev'
16
18
  // uno.css 先于 #valaxy/styles 加载,使主题/用户样式可以覆盖 utility
17
19
  import 'uno.css'
@@ -60,12 +62,7 @@ function flattenRoutes(routes: any[]): any[] {
60
62
 
61
63
  // filter children recursive
62
64
  function filterDraft(routes: any[]) {
63
- return routes.filter((i) => {
64
- if (i.children)
65
- i.children = filterDraft(i.children)
66
-
67
- return !i.meta?.frontmatter?.draft
68
- })
65
+ return omitProductionDraftRoutes(routes, valaxyConfig.value.siteConfig.publishing?.drafts)
69
66
  }
70
67
 
71
68
  /**
@@ -129,6 +126,9 @@ export function createValaxyApp(options: CreateValaxyAppOptions = {}): ValaxySSG
129
126
  router.clearRoutes()
130
127
  for (const route of resolveRoutes(newRoutes))
131
128
  router.addRoute(route)
129
+ // Notify every list consumer, including pages that have never been
130
+ // visited (and therefore have no mounted Markdown component to update).
131
+ app.runWithContext(() => useRouterStore().refreshRoutes())
132
132
  })
133
133
  }
134
134
 
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { computed, defineComponent } from 'vue'
3
+ import { compile } from 'vue/dist/vue.esm-bundler.js'
4
+
5
+ const props = withDefaults(defineProps<{
6
+ templateStr: string
7
+ data?: Record<string, any>
8
+ }>(), { data: () => ({}) })
9
+ const emit = defineEmits<{ rendered: [] }>()
10
+
11
+ // The full Vue entry shares runtime-dom with the app and provides Vue's own
12
+ // compiler cache and runtime render-function registration. Only this lazy
13
+ // module imports it; ordinary pages keep using the runtime-only Vue entry.
14
+ const compiledRender = computed(() => props.templateStr ? compile(props.templateStr) : null)
15
+ const dynamicComponent = computed(() => {
16
+ const render = compiledRender.value
17
+ const data = { ...props.data }
18
+ return render ? defineComponent({ data: () => ({ ...data }), render }) : null
19
+ })
20
+ </script>
21
+
22
+ <template>
23
+ <div v-if="dynamicComponent">
24
+ <component :is="dynamicComponent" @vue:mounted="emit('rendered')" />
25
+ </div>
26
+ </template>