valaxy 1.3.3 → 1.4.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.
- package/client/components/AppLink.vue +2 -2
- package/client/components/ValaxyDecrypt.vue +5 -3
- package/client/components/ValaxyMd.vue +2 -7
- package/client/composables/app/useValaxyHead.ts +11 -3
- package/client/composables/features/copy-code.ts +64 -38
- package/client/composables/features/copy-markdown.ts +2 -6
- package/client/composables/search/useFuseSearch.ts +38 -4
- package/client/composables/search/useLocalSearch.ts +47 -13
- package/client/composables/widgets/index.ts +0 -1
- package/client/utils/router.ts +83 -37
- package/dist/node/cli/index.d.mts +1 -1
- package/dist/node/cli/index.mjs +5 -5
- package/dist/node/index.d.mts +24 -7
- package/dist/node/index.mjs +5 -5
- package/dist/shared/valaxy.CaLqd5CH.d.mts +62 -0
- package/dist/shared/{valaxy.aOnvqwjo.mjs → valaxy.i_3nqqSt.mjs} +929 -328
- package/dist/shared/{valaxy.Jqi53gnQ.d.mts → valaxy.ukLrUCoH.d.mts} +3 -395
- package/dist/types/frontmatter/index.d.mts +321 -0
- package/dist/types/frontmatter/index.mjs +1 -0
- package/dist/types/index.d.mts +4 -3
- package/package.json +6 -3
- package/shared/utils/index.ts +2 -0
- package/shared/utils/sanitize.ts +82 -0
- package/shared/utils/uri.ts +93 -0
- package/types/config.ts +1 -2
- package/types/frontmatter/page.ts +0 -11
- package/types/frontmatter/post.ts +0 -6
- package/types/index.ts +1 -1
- package/types/posts.ts +1 -1
- package/client/composables/widgets/codepen.ts +0 -15
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// https://router.vuejs.org/guide/advanced/extending-router-link.html#extending-routerlink
|
|
3
3
|
import { computed } from 'vue'
|
|
4
4
|
import { RouterLink } from 'vue-router'
|
|
5
|
-
import { EXTERNAL_URL_RE } from '../../shared'
|
|
5
|
+
import { EXTERNAL_URL_RE, sanitizeUrl } from '../../shared'
|
|
6
6
|
|
|
7
7
|
defineOptions({
|
|
8
8
|
inheritAttrs: false,
|
|
@@ -15,7 +15,7 @@ const props = defineProps<{
|
|
|
15
15
|
target?: string
|
|
16
16
|
}>()
|
|
17
17
|
|
|
18
|
-
const link = computed(() => props.href || props.to
|
|
18
|
+
const link = computed(() => sanitizeUrl(props.href || props.to))
|
|
19
19
|
|
|
20
20
|
const isExternalLink = computed(() => {
|
|
21
21
|
return (link.value && EXTERNAL_URL_RE.test(link.value)) || props.target === '_blank'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import { isClient } from '@vueuse/core'
|
|
3
2
|
import { runContentUpdated, useDecrypt, useFrontmatter } from 'valaxy'
|
|
4
|
-
import {
|
|
3
|
+
import { onMounted, ref } from 'vue'
|
|
5
4
|
|
|
6
5
|
const props = withDefaults(defineProps<{
|
|
7
6
|
encryptedContent: string
|
|
@@ -40,7 +39,10 @@ function encryptAgain() {
|
|
|
40
39
|
}, 16)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
const hasWarning =
|
|
42
|
+
const hasWarning = ref(false)
|
|
43
|
+
onMounted(() => {
|
|
44
|
+
hasWarning.value = window.location.protocol !== 'https:'
|
|
45
|
+
})
|
|
44
46
|
</script>
|
|
45
47
|
|
|
46
48
|
<template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import type { Post } from 'valaxy'
|
|
3
|
-
import { onContentUpdated, runContentUpdated,
|
|
3
|
+
import { onContentUpdated, runContentUpdated, sanitizeUrl, setIframeAspectRatios, useCollapseCode, useCopyCode, useMediumZoom, wrapTable } from 'valaxy'
|
|
4
4
|
import { onMounted, onUpdated, ref } from 'vue'
|
|
5
5
|
import { useI18n } from 'vue-i18n'
|
|
6
6
|
import { useCodeGroups } from '../composables/codeGroups'
|
|
@@ -31,10 +31,6 @@ onUpdated(() => {
|
|
|
31
31
|
runContentUpdated()
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
// widgets
|
|
35
|
-
if (props.frontmatter.codepen)
|
|
36
|
-
useCodePen()
|
|
37
|
-
|
|
38
34
|
useCopyCode()
|
|
39
35
|
useCodeGroups()
|
|
40
36
|
useCollapseCode()
|
|
@@ -51,8 +47,7 @@ useVanillaLazyLoad()
|
|
|
51
47
|
|
|
52
48
|
<div v-if="frontmatter.url" text="center">
|
|
53
49
|
<a
|
|
54
|
-
|
|
55
|
-
:href="frontmatter.url"
|
|
50
|
+
:href="sanitizeUrl(frontmatter.url)"
|
|
56
51
|
class="post-link-btn shadow hover:shadow-md"
|
|
57
52
|
rounded
|
|
58
53
|
target="_blank"
|
|
@@ -5,12 +5,14 @@ import pkg from '../../../package.json' with { type: 'json' }
|
|
|
5
5
|
import { useFrontmatter, useValaxyI18n } from '../../composables'
|
|
6
6
|
import { useSiteConfig } from '../../config'
|
|
7
7
|
import { withBase } from '../../utils'
|
|
8
|
+
import { useLayout } from '../../utils/layouts'
|
|
8
9
|
import { usePageSeo } from './usePageSeo'
|
|
9
10
|
|
|
10
11
|
export function useValaxyHead() {
|
|
11
12
|
const { $t, $tO, locale } = useValaxyI18n()
|
|
12
13
|
|
|
13
14
|
const fm = useFrontmatter()
|
|
15
|
+
const layout = useLayout()
|
|
14
16
|
const siteConfig = useSiteConfig()
|
|
15
17
|
const { description, pageUrl } = usePageSeo()
|
|
16
18
|
const $title = computed(() => $tO(fm.value.title))
|
|
@@ -52,9 +54,15 @@ export function useValaxyHead() {
|
|
|
52
54
|
},
|
|
53
55
|
})
|
|
54
56
|
|
|
55
|
-
useHead(computed(() =>
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
useHead(computed(() => {
|
|
58
|
+
// YAML frontmatter can supply the layout name as a number.
|
|
59
|
+
if (String(layout.value) === '404')
|
|
60
|
+
return { meta: [{ name: 'robots', content: 'noindex' }] }
|
|
61
|
+
|
|
62
|
+
return canonicalUrl.value
|
|
63
|
+
? { link: [{ rel: 'canonical', href: canonicalUrl.value }] }
|
|
64
|
+
: {}
|
|
65
|
+
}))
|
|
58
66
|
|
|
59
67
|
// Add mac detection class on client side only, after hydration
|
|
60
68
|
// to avoid SSR/client mismatch on the <html> element
|
|
@@ -1,50 +1,76 @@
|
|
|
1
1
|
// ref vitepress copyCode.ts
|
|
2
2
|
import { isClient } from '@vueuse/core'
|
|
3
|
+
import { getCurrentScope, onScopeDispose } from 'vue'
|
|
4
|
+
|
|
5
|
+
const timeoutIdMap: WeakMap<HTMLElement, ReturnType<typeof setTimeout>> = new WeakMap()
|
|
6
|
+
let activeCopyCodeListeners = 0
|
|
7
|
+
|
|
8
|
+
function handleCopyClick(e: MouseEvent) {
|
|
9
|
+
const el = e.target
|
|
10
|
+
if (!(el instanceof Element) || !el.matches('div[class*="language-"] > button.copy'))
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
const parent = el.parentElement
|
|
14
|
+
const sibling = el.nextElementSibling?.nextElementSibling
|
|
15
|
+
if (!parent || !sibling)
|
|
16
|
+
return
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group
|
|
19
|
+
const isShell = /language-(shellscript|shell|bash|sh|zsh)/.test(
|
|
20
|
+
parent.className,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
let text = ''
|
|
24
|
+
|
|
25
|
+
sibling
|
|
26
|
+
.querySelectorAll('span.line:not(.diff.remove)')
|
|
27
|
+
.forEach(node => (text += `${node.textContent || ''}\n`))
|
|
28
|
+
text = text.slice(0, -1)
|
|
29
|
+
|
|
30
|
+
if (isShell)
|
|
31
|
+
text = text.replace(/^ *(\$|>) /gm, '').trim()
|
|
32
|
+
|
|
33
|
+
copyToClipboard(text)
|
|
34
|
+
.then(() => {
|
|
35
|
+
el.classList.add('copied')
|
|
36
|
+
clearTimeout(timeoutIdMap.get(el as HTMLElement))
|
|
37
|
+
const timeoutId = setTimeout(() => {
|
|
38
|
+
el.classList.remove('copied')
|
|
39
|
+
;(el as HTMLElement).blur?.()
|
|
40
|
+
timeoutIdMap.delete(el as HTMLElement)
|
|
41
|
+
}, 2000)
|
|
42
|
+
timeoutIdMap.set(el as HTMLElement, timeoutId)
|
|
43
|
+
})
|
|
44
|
+
.catch(() => {})
|
|
45
|
+
}
|
|
3
46
|
|
|
4
47
|
export function useCopyCode() {
|
|
5
|
-
if (isClient)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let text = ''
|
|
21
|
-
|
|
22
|
-
sibling
|
|
23
|
-
.querySelectorAll('span.line:not(.diff.remove)')
|
|
24
|
-
.forEach(node => (text += `${node.textContent || ''}\n`))
|
|
25
|
-
text = text.slice(0, -1)
|
|
26
|
-
|
|
27
|
-
if (isShell)
|
|
28
|
-
text = text.replace(/^ *(\$|>) /gm, '').trim()
|
|
29
|
-
|
|
30
|
-
copyToClipboard(text).then(() => {
|
|
31
|
-
el.classList.add('copied')
|
|
32
|
-
clearTimeout(timeoutIdMap.get(el))
|
|
33
|
-
const timeoutId = setTimeout(() => {
|
|
34
|
-
el.classList.remove('copied')
|
|
35
|
-
el.blur()
|
|
36
|
-
timeoutIdMap.delete(el)
|
|
37
|
-
}, 2000)
|
|
38
|
-
timeoutIdMap.set(el, timeoutId)
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
})
|
|
48
|
+
if (!isClient)
|
|
49
|
+
return () => {}
|
|
50
|
+
|
|
51
|
+
if (activeCopyCodeListeners === 0)
|
|
52
|
+
window.addEventListener('click', handleCopyClick)
|
|
53
|
+
activeCopyCodeListeners++
|
|
54
|
+
|
|
55
|
+
let disposed = false
|
|
56
|
+
const cleanup = () => {
|
|
57
|
+
if (disposed)
|
|
58
|
+
return
|
|
59
|
+
disposed = true
|
|
60
|
+
activeCopyCodeListeners = Math.max(0, activeCopyCodeListeners - 1)
|
|
61
|
+
if (activeCopyCodeListeners === 0)
|
|
62
|
+
window.removeEventListener('click', handleCopyClick)
|
|
42
63
|
}
|
|
64
|
+
|
|
65
|
+
if (getCurrentScope())
|
|
66
|
+
onScopeDispose(cleanup)
|
|
67
|
+
|
|
68
|
+
return cleanup
|
|
43
69
|
}
|
|
44
70
|
|
|
45
71
|
async function copyToClipboard(text: string) {
|
|
46
72
|
try {
|
|
47
|
-
return navigator.clipboard.writeText(text)
|
|
73
|
+
return await navigator.clipboard.writeText(text)
|
|
48
74
|
}
|
|
49
75
|
catch {
|
|
50
76
|
const element = document.createElement('textarea')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isClient, useClipboard } from '@vueuse/core'
|
|
2
2
|
import { computed, ref, watchEffect } from 'vue'
|
|
3
3
|
import { useRoute } from 'vue-router'
|
|
4
|
+
import { urlPathToMarkdownPath } from '../../../shared/utils/uri'
|
|
4
5
|
import { useSiteConfig } from '../../config'
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -34,12 +35,7 @@ export function useCopyMarkdown() {
|
|
|
34
35
|
const error = ref<string | null>(null)
|
|
35
36
|
const { copy: copyToClipboard } = useClipboard({ legacy: true })
|
|
36
37
|
|
|
37
|
-
const mdUrl = computed(() =>
|
|
38
|
-
const p = route.path !== '/' && route.path.endsWith('/')
|
|
39
|
-
? route.path.slice(0, -1)
|
|
40
|
-
: route.path
|
|
41
|
-
return `${p}.md`
|
|
42
|
-
})
|
|
38
|
+
const mdUrl = computed(() => urlPathToMarkdownPath(route.path).href)
|
|
43
39
|
|
|
44
40
|
// Only probe when raw Markdown output is enabled.
|
|
45
41
|
if (isClient) {
|
|
@@ -5,6 +5,17 @@ import { useFuse } from '@vueuse/integrations/useFuse'
|
|
|
5
5
|
import { computed, shallowRef } from 'vue'
|
|
6
6
|
import { useSiteConfig } from '../../config'
|
|
7
7
|
|
|
8
|
+
const fuseDataCache = new Map<string, FuseListItem[]>()
|
|
9
|
+
const fuseInFlight = new Map<string, Promise<FuseListItem[]>>()
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Clear module-scoped Fuse search caches (intended for tests or cache invalidation).
|
|
13
|
+
*/
|
|
14
|
+
export function clearFuseSearchCache() {
|
|
15
|
+
fuseDataCache.clear()
|
|
16
|
+
fuseInFlight.clear()
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
export function useFuseSearch<T extends FuseListItem = FuseListItem>(
|
|
9
20
|
search: MaybeRefOrGetter<string>,
|
|
10
21
|
options?: MaybeRefOrGetter<UseFuseOptions<T>>,
|
|
@@ -12,6 +23,7 @@ export function useFuseSearch<T extends FuseListItem = FuseListItem>(
|
|
|
12
23
|
const siteConfig = useSiteConfig()
|
|
13
24
|
|
|
14
25
|
const fuseListData = shallowRef<T[]>([])
|
|
26
|
+
let latestRequestId = 0
|
|
15
27
|
|
|
16
28
|
const keys = computed(() => {
|
|
17
29
|
const ks = siteConfig.value.fuse.options.keys || []
|
|
@@ -45,11 +57,33 @@ export function useFuseSearch<T extends FuseListItem = FuseListItem>(
|
|
|
45
57
|
? siteConfig.value.fuse.dataPath
|
|
46
58
|
: `${import.meta.env.BASE_URL}${siteConfig.value.fuse.dataPath}`)
|
|
47
59
|
|
|
48
|
-
const
|
|
49
|
-
|
|
60
|
+
const requestId = ++latestRequestId
|
|
61
|
+
|
|
62
|
+
const cached = fuseDataCache.get(fuseListDataPath)
|
|
63
|
+
if (cached) {
|
|
64
|
+
fuseListData.value = cached as T[]
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let pending = fuseInFlight.get(fuseListDataPath)
|
|
69
|
+
if (!pending) {
|
|
70
|
+
pending = (async () => {
|
|
71
|
+
const res = await fetch(fuseListDataPath)
|
|
72
|
+
if (!res.ok)
|
|
73
|
+
throw new Error(`Failed to fetch fuse list data (${res.status}): ${fuseListDataPath}`)
|
|
74
|
+
const data = await res.json()
|
|
75
|
+
const items = Array.isArray(data) ? data : []
|
|
76
|
+
fuseDataCache.set(fuseListDataPath, items)
|
|
77
|
+
return items
|
|
78
|
+
})().finally(() => {
|
|
79
|
+
fuseInFlight.delete(fuseListDataPath)
|
|
80
|
+
})
|
|
81
|
+
fuseInFlight.set(fuseListDataPath, pending)
|
|
82
|
+
}
|
|
50
83
|
|
|
51
|
-
|
|
52
|
-
|
|
84
|
+
const data = await pending
|
|
85
|
+
if (requestId === latestRequestId)
|
|
86
|
+
fuseListData.value = data as T[]
|
|
53
87
|
}
|
|
54
88
|
|
|
55
89
|
return {
|
|
@@ -10,30 +10,64 @@ export interface LocalSearchResult {
|
|
|
10
10
|
titles: string[]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const localSearchCache = new Map<string, MiniSearch>()
|
|
14
|
+
const localSearchInFlight = new Map<string, Promise<MiniSearch | null>>()
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Clear module-scoped local search caches (intended for tests or index invalidation).
|
|
18
|
+
*/
|
|
19
|
+
export function clearLocalSearchCache() {
|
|
20
|
+
localSearchCache.clear()
|
|
21
|
+
localSearchInFlight.clear()
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
export function useLocalSearch(query: Ref<string>) {
|
|
14
25
|
const results = shallowRef<LocalSearchResult[]>([])
|
|
15
26
|
const loading = ref(false)
|
|
16
27
|
const miniSearch = shallowRef<MiniSearch | null>(null)
|
|
28
|
+
let latestRequestId = 0
|
|
17
29
|
|
|
18
30
|
async function load(locale = 'root') {
|
|
31
|
+
const requestId = ++latestRequestId
|
|
32
|
+
|
|
33
|
+
const cached = localSearchCache.get(locale)
|
|
34
|
+
if (cached) {
|
|
35
|
+
miniSearch.value = cached
|
|
36
|
+
loading.value = false
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
loading.value = true
|
|
20
41
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
let pending = localSearchInFlight.get(locale)
|
|
43
|
+
if (!pending) {
|
|
44
|
+
pending = (async () => {
|
|
45
|
+
const searchIndex = (await import('@localSearchIndex')).default
|
|
46
|
+
const loader = searchIndex[locale] ?? searchIndex[Object.keys(searchIndex)[0]]
|
|
47
|
+
if (!loader)
|
|
48
|
+
return null
|
|
49
|
+
const mod = await loader()
|
|
50
|
+
const data: string = mod.default
|
|
51
|
+
const { default: MiniSearchCtor } = await import('minisearch')
|
|
52
|
+
const instance = MiniSearchCtor.loadJSON(data, {
|
|
53
|
+
fields: ['title', 'titles', 'text'],
|
|
54
|
+
storeFields: ['title', 'titles'],
|
|
55
|
+
})
|
|
56
|
+
localSearchCache.set(locale, instance)
|
|
57
|
+
return instance
|
|
58
|
+
})().finally(() => {
|
|
59
|
+
localSearchInFlight.delete(locale)
|
|
60
|
+
})
|
|
61
|
+
localSearchInFlight.set(locale, pending)
|
|
26
62
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fields: ['title', 'titles', 'text'],
|
|
32
|
-
storeFields: ['title', 'titles'],
|
|
33
|
-
})
|
|
63
|
+
|
|
64
|
+
const instance = await pending
|
|
65
|
+
if (requestId === latestRequestId)
|
|
66
|
+
miniSearch.value = instance
|
|
34
67
|
}
|
|
35
68
|
finally {
|
|
36
|
-
|
|
69
|
+
if (requestId === latestRequestId)
|
|
70
|
+
loading.value = false
|
|
37
71
|
}
|
|
38
72
|
}
|
|
39
73
|
|
package/client/utils/router.ts
CHANGED
|
@@ -64,48 +64,94 @@ export function scrollTo(el: HTMLElement, hash: string, options: Partial<ScrollT
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
interface ClickHandlerEntry {
|
|
68
|
+
refCount: number
|
|
69
|
+
detach: () => void
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const activeClickHandlers = new WeakMap<Router, ClickHandlerEntry>()
|
|
73
|
+
|
|
74
|
+
function safeDecodeHash(hash: string): string {
|
|
75
|
+
try {
|
|
76
|
+
return decodeURIComponent(hash)
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return hash
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
/**
|
|
68
|
-
* @description Intercept
|
|
69
|
-
* @description:zh-CN
|
|
84
|
+
* @description Intercept same-page inbound anchor clicks and handle offset positions for jump links on the same page
|
|
85
|
+
* @description:zh-CN 拦截点击事件,处理同一页面下跳转链接的偏移位置(按 router 实例引用计数共享监听,并返回独立的幂等清理函数)
|
|
70
86
|
* @param router Vue Router
|
|
71
87
|
*/
|
|
72
|
-
export function onClickHref(router: Router) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
!e.ctrlKey
|
|
86
|
-
&& !e.shiftKey
|
|
87
|
-
&& !e.altKey
|
|
88
|
-
&& !e.metaKey
|
|
89
|
-
&& target !== '_blank'
|
|
90
|
-
&& protocol === currentUrl.protocol
|
|
91
|
-
&& hostname === currentUrl.hostname
|
|
92
|
-
&& !(extMatch && extMatch[0] !== '.html')
|
|
93
|
-
) {
|
|
94
|
-
if (pathname === currentUrl.pathname) {
|
|
95
|
-
e.preventDefault()
|
|
96
|
-
// scroll between hash anchors in the same page
|
|
97
|
-
if (hash && hash !== currentUrl.hash) {
|
|
98
|
-
await router.push({ hash: decodeURIComponent(hash) })
|
|
88
|
+
export function onClickHref(router: Router): () => void {
|
|
89
|
+
if (typeof window === 'undefined')
|
|
90
|
+
return () => {}
|
|
91
|
+
|
|
92
|
+
let entry = activeClickHandlers.get(router)
|
|
93
|
+
if (!entry) {
|
|
94
|
+
const handleClick = async (e: MouseEvent) => {
|
|
95
|
+
const targetEl = e.target instanceof Element
|
|
96
|
+
? e.target
|
|
97
|
+
: (e.target as Node | null)?.parentElement
|
|
98
|
+
const link = targetEl?.closest('a')
|
|
99
|
+
if (!link)
|
|
100
|
+
return
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
const { protocol, hostname, pathname, hash, target } = link
|
|
103
|
+
const currentUrl = window.location
|
|
104
|
+
const extMatch = pathname.match(/\.\w+$/)
|
|
105
|
+
// only intercept inbound links
|
|
106
|
+
if (
|
|
107
|
+
!e.ctrlKey
|
|
108
|
+
&& !e.shiftKey
|
|
109
|
+
&& !e.altKey
|
|
110
|
+
&& !e.metaKey
|
|
111
|
+
&& target !== '_blank'
|
|
112
|
+
&& protocol === currentUrl.protocol
|
|
113
|
+
&& hostname === currentUrl.hostname
|
|
114
|
+
&& !(extMatch && extMatch[0] !== '.html')
|
|
115
|
+
) {
|
|
116
|
+
if (pathname === currentUrl.pathname) {
|
|
117
|
+
e.preventDefault()
|
|
118
|
+
// scroll between hash anchors in the same page
|
|
119
|
+
if (hash && hash !== currentUrl.hash) {
|
|
120
|
+
await router.push({ hash: safeDecodeHash(hash) })
|
|
121
|
+
|
|
122
|
+
// use smooth scroll when clicking on header anchor links
|
|
123
|
+
scrollTo(link, hash, {
|
|
124
|
+
smooth: link.classList.contains('header-anchor'),
|
|
125
|
+
})
|
|
105
126
|
}
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
window.addEventListener('click', handleClick, { capture: true })
|
|
132
|
+
|
|
133
|
+
const createdEntry: ClickHandlerEntry = {
|
|
134
|
+
refCount: 0,
|
|
135
|
+
detach: () => {
|
|
136
|
+
window.removeEventListener('click', handleClick, { capture: true })
|
|
137
|
+
if (activeClickHandlers.get(router) === createdEntry)
|
|
138
|
+
activeClickHandlers.delete(router)
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
entry = createdEntry
|
|
142
|
+
activeClickHandlers.set(router, entry)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const currentEntry = entry
|
|
146
|
+
currentEntry.refCount += 1
|
|
147
|
+
let cleaned = false
|
|
148
|
+
|
|
149
|
+
return () => {
|
|
150
|
+
if (cleaned)
|
|
151
|
+
return
|
|
152
|
+
cleaned = true
|
|
153
|
+
currentEntry.refCount -= 1
|
|
154
|
+
if (currentEntry.refCount <= 0)
|
|
155
|
+
currentEntry.detach()
|
|
156
|
+
}
|
|
111
157
|
}
|
package/dist/node/cli/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import 'node:path';
|
|
|
2
2
|
import 'node:process';
|
|
3
3
|
import 'yargs';
|
|
4
4
|
import 'yargs/helpers';
|
|
5
|
-
export {
|
|
5
|
+
export { a as createCli, t as desktopRuntimeVersion, v as execBuild, R as registerDevCommand, a3 as run, a5 as startValaxyDev } from '../../shared/valaxy.i_3nqqSt.mjs';
|
|
6
6
|
import 'node:os';
|
|
7
7
|
import '@11ty/gray-matter';
|
|
8
8
|
import 'consola';
|
|
@@ -24,12 +24,15 @@ import 'mlly';
|
|
|
24
24
|
import 'resolve-global';
|
|
25
25
|
import '@valaxyjs/utils';
|
|
26
26
|
import 'node:fs';
|
|
27
|
+
import 'p-map';
|
|
27
28
|
import 'picomatch';
|
|
28
29
|
import 'node:fs/promises';
|
|
29
30
|
import 'dayjs';
|
|
30
31
|
import 'feed';
|
|
31
32
|
import 'markdown-exit';
|
|
32
33
|
import 'table';
|
|
34
|
+
import 'htmlparser2';
|
|
35
|
+
import 'magic-string';
|
|
33
36
|
import 'hookable';
|
|
34
37
|
import '@unhead/bundler/vite';
|
|
35
38
|
import 'vitepress-plugin-group-icons';
|
|
@@ -38,8 +41,6 @@ import 'chokidar';
|
|
|
38
41
|
import 'unplugin';
|
|
39
42
|
import 'unplugin-utils';
|
|
40
43
|
import 'obug';
|
|
41
|
-
import 'magic-string';
|
|
42
|
-
import 'p-map';
|
|
43
44
|
import 'pascalcase';
|
|
44
45
|
import '@intlify/unplugin-vue-i18n/vite';
|
|
45
46
|
import 'minisearch';
|
|
@@ -53,7 +54,6 @@ import 'markdown-it-emoji';
|
|
|
53
54
|
import 'markdown-it-footnote';
|
|
54
55
|
import 'markdown-it-image-figures';
|
|
55
56
|
import 'markdown-it-task-lists';
|
|
56
|
-
import 'node:url';
|
|
57
57
|
import 'markdown-it-container';
|
|
58
58
|
import 'katex';
|
|
59
59
|
import 'katex/contrib/mhchem';
|
|
@@ -62,8 +62,8 @@ import 'jiti';
|
|
|
62
62
|
import 'unocss';
|
|
63
63
|
import 'html-to-text';
|
|
64
64
|
import 'vue-router/vite';
|
|
65
|
+
import 'node:url';
|
|
65
66
|
import '@unhead/vue/server';
|
|
66
|
-
import 'htmlparser2';
|
|
67
67
|
import 'escape-html';
|
|
68
68
|
import 'vue-router/unplugin';
|
|
69
69
|
import 'node:child_process';
|
package/dist/node/index.d.mts
CHANGED
|
@@ -20,12 +20,13 @@ import { Header } from '@valaxyjs/utils';
|
|
|
20
20
|
export { CreateCliOptions, createCli, desktopRuntimeVersion, execBuild, registerDevCommand, run, startValaxyDev } from './cli/index.mjs';
|
|
21
21
|
import { Awaitable } from '@antfu/utils';
|
|
22
22
|
import * as defu from 'defu';
|
|
23
|
+
import 'valaxy/types/frontmatter';
|
|
24
|
+
import '../shared/valaxy.CaLqd5CH.mjs';
|
|
23
25
|
import '@vueuse/integrations/useFuse';
|
|
24
26
|
import 'medium-zoom';
|
|
25
27
|
import 'vanilla-lazyload';
|
|
26
28
|
import 'vue-router';
|
|
27
29
|
import '@vueuse/core';
|
|
28
|
-
import '@unhead/schema-org';
|
|
29
30
|
|
|
30
31
|
//#region src/types.d.ts
|
|
31
32
|
/**
|
|
@@ -908,6 +909,18 @@ interface ResolvedValaxyOptions<ThemeConfig = DefaultTheme.Config> {
|
|
|
908
909
|
* @default process.cwd()
|
|
909
910
|
*/
|
|
910
911
|
userRoot: string;
|
|
912
|
+
/**
|
|
913
|
+
* Build output directory (resolved during build)
|
|
914
|
+
*/
|
|
915
|
+
outDir?: string;
|
|
916
|
+
/**
|
|
917
|
+
* Public static asset directory (resolved during build/dev)
|
|
918
|
+
*/
|
|
919
|
+
publicDir?: string | false;
|
|
920
|
+
/**
|
|
921
|
+
* Resolved Vite base URL
|
|
922
|
+
*/
|
|
923
|
+
base?: string;
|
|
911
924
|
/**
|
|
912
925
|
* Theme root path
|
|
913
926
|
*/
|
|
@@ -1103,8 +1116,8 @@ interface ValaxyExtendConfig {
|
|
|
1103
1116
|
*/
|
|
1104
1117
|
fullText: boolean;
|
|
1105
1118
|
/**
|
|
1106
|
-
* @zh
|
|
1107
|
-
* @en
|
|
1119
|
+
* @zh 使用构建产物中的图片 URL,兼容从旧版构建 HTML 中提取路径
|
|
1120
|
+
* @en Use emitted image URLs, falling back to rendered HTML for older builds
|
|
1108
1121
|
* @default true
|
|
1109
1122
|
*/
|
|
1110
1123
|
extractImagePathsFromHTML: boolean;
|
|
@@ -1362,10 +1375,10 @@ declare function postProcessForSSG(options: ResolvedValaxyOptions): Promise<void
|
|
|
1362
1375
|
declare function generateClientRedirects(options: ResolvedValaxyOptions): Promise<void>;
|
|
1363
1376
|
|
|
1364
1377
|
/**
|
|
1365
|
-
* merge vite.config
|
|
1378
|
+
* merge vite.config.* (theme & user, plus any required explicit config file)
|
|
1366
1379
|
* @internal
|
|
1367
1380
|
*/
|
|
1368
|
-
declare function mergeViteConfigs({ userRoot, themeRoot }: ResolvedValaxyOptions, command: 'serve' | 'build'): Promise<InlineConfig>;
|
|
1381
|
+
declare function mergeViteConfigs({ userRoot, themeRoot }: ResolvedValaxyOptions, command: 'serve' | 'build', mode?: string, extraFiles?: string[], isSsrBuild?: boolean, configLoader?: InlineConfig['configLoader'], logLevel?: InlineConfig['logLevel'], customLogger?: InlineConfig['customLogger']): Promise<InlineConfig>;
|
|
1369
1382
|
/**
|
|
1370
1383
|
* generate index.html from user/theme/client
|
|
1371
1384
|
* @internal
|
|
@@ -1599,8 +1612,12 @@ declare function encryptContent(content: string, options: {
|
|
|
1599
1612
|
salt: Uint8Array;
|
|
1600
1613
|
}): Promise<string>;
|
|
1601
1614
|
|
|
1615
|
+
/** Return a pipeline-scoped Git timestamp cache keyed by an options/app object. */
|
|
1616
|
+
declare function getGitTimestampCache(scope: object): Map<string, Promise<number>>;
|
|
1617
|
+
/** Clear cached Git timestamps for a specific file or all files in a pipeline cache. */
|
|
1618
|
+
declare function clearGitTimestampCache(cache: Map<string, Promise<number>>, file?: string): void;
|
|
1602
1619
|
/** Read commit timestamps from the file's repository, following renames. */
|
|
1603
|
-
declare function getGitTimestamp(file: string, type?: 'created' | 'updated'): Promise<number>;
|
|
1620
|
+
declare function getGitTimestamp(file: string, type?: 'created' | 'updated', cache?: Map<string, Promise<number>>): Promise<number>;
|
|
1604
1621
|
|
|
1605
1622
|
/**
|
|
1606
1623
|
* is url external (http/https:)
|
|
@@ -1639,5 +1656,5 @@ declare function toAtFS(path: string): string;
|
|
|
1639
1656
|
declare function resolveImportPath(importName: string, ensure?: true): Promise<string>;
|
|
1640
1657
|
declare function resolveImportPath(importName: string, ensure?: boolean): Promise<string | undefined>;
|
|
1641
1658
|
|
|
1642
|
-
export { $t, ALL_ROUTE, EXCERPT_SEPARATOR, GLOBAL_STATE, PATHNAME_PROTOCOL_RE, StateManager, ViteValaxyPlugins, build, createContentService, createMemoryReleasePlugin, createServer, createValaxyNode, createValaxyPlugin, customElements, defaultSiteConfig, defaultValaxyConfig, defaultViteConfig, defineAddon, defineConfig, defineContentLoader, defineSiteConfig, defineTheme, defineUnoSetup, defineValaxyAddon, defineValaxyConfig, defineValaxyTheme, encryptContent, generateClientRedirects, getGitTimestamp, getIndexHtml, getServerInfoText, isExternal, isInstalledGlobally, isKatexEnabled, isKatexPluginNeeded, isMathJaxEnabled, isPath, loadAllContent, loadConfigFromFile, mergeValaxyConfig, mergeViteConfigs, postProcessForSSG, processValaxyOptions, resolveAddonsConfig, resolveImportPath, resolveImportUrl, resolveOptions, resolveSiteConfig, resolveSiteConfigFromRoot, resolveThemeConfigFromRoot, resolveThemeValaxyConfig, resolveUserThemeConfig, resolveValaxyConfig, resolveValaxyConfigFromRoot, ssgBuild, toAtFS, transformObject, version };
|
|
1659
|
+
export { $t, ALL_ROUTE, EXCERPT_SEPARATOR, GLOBAL_STATE, PATHNAME_PROTOCOL_RE, StateManager, ViteValaxyPlugins, build, clearGitTimestampCache, createContentService, createMemoryReleasePlugin, createServer, createValaxyNode, createValaxyPlugin, customElements, defaultSiteConfig, defaultValaxyConfig, defaultViteConfig, defineAddon, defineConfig, defineContentLoader, defineSiteConfig, defineTheme, defineUnoSetup, defineValaxyAddon, defineValaxyConfig, defineValaxyTheme, encryptContent, generateClientRedirects, getGitTimestamp, getGitTimestampCache, getIndexHtml, getServerInfoText, isExternal, isInstalledGlobally, isKatexEnabled, isKatexPluginNeeded, isMathJaxEnabled, isPath, loadAllContent, loadConfigFromFile, mergeValaxyConfig, mergeViteConfigs, postProcessForSSG, processValaxyOptions, resolveAddonsConfig, resolveImportPath, resolveImportUrl, resolveOptions, resolveSiteConfig, resolveSiteConfigFromRoot, resolveThemeConfigFromRoot, resolveThemeValaxyConfig, resolveUserThemeConfig, resolveValaxyConfig, resolveValaxyConfigFromRoot, ssgBuild, toAtFS, transformObject, version };
|
|
1643
1660
|
export type { CdnModule, ContentCheckResult, ContentDiagnostic, ContentItem, ContentLoader, ContentLoaderContext, ContentPageInfo, ContentServiceOptions, GroupIconOptions, GroupIconValue, HookResult, LoadConfigFromFileOptions, MarkdownRenderer, MdAfterRenderContext, ResolvedConfig, ResolvedValaxyOptions, UnoSetup, UserInputConfig, UserValaxyNodeConfig, ValaxyAddonCliContext, ValaxyAddonExport, ValaxyAddonExtendCli, ValaxyAddonFn, ValaxyAddonLike, ValaxyAddonResolver, ValaxyAddons, ValaxyApp, ValaxyConfigExport, ValaxyConfigExtendKey, ValaxyConfigFn, ValaxyEntryOptions, ValaxyExtendConfig, ValaxyFileInfo, ValaxyHooks, ValaxyNode, ValaxyNodeAddon, ValaxyNodeConfig, ValaxyPickConfig, ValaxyServerOptions, ValaxyTheme };
|