valaxy 1.0.1 → 1.2.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/ValaxyCopyright.vue +2 -1
- package/client/components/ValaxyCover.vue +92 -0
- package/client/components/ValaxyFootnoteTooltip.vue +6 -14
- package/client/components/ValaxySvgExport.vue +71 -0
- package/client/components/footnote/FootnotePopover.vue +146 -0
- package/client/components/footnote/LegacyFootnoteTooltip.vue +25 -0
- package/client/composables/collections.ts +13 -9
- package/client/composables/decrypt.ts +8 -1
- package/client/composables/outline/anchor.ts +20 -8
- package/client/composables/post/filter.ts +38 -0
- package/client/composables/post/index.ts +2 -34
- package/client/index.d.ts +0 -1
- package/client/layouts/README.md +1 -1
- package/client/locales/en.yml +2 -0
- package/client/locales/zh-CN.yml +2 -0
- package/client/main.ts +35 -20
- package/client/modules/valaxy.ts +14 -5
- package/client/shims.d.ts +27 -0
- package/client/utils/index.ts +1 -0
- package/client/utils/layouts.ts +359 -0
- package/client/utils/path.ts +30 -0
- package/client/utils/svg.ts +104 -0
- package/dist/node/cli/index.mjs +4 -11
- package/dist/node/index.d.mts +71 -46
- package/dist/node/index.mjs +4 -11
- package/dist/shared/{valaxy.CjaAzLmd.d.mts → valaxy.BGgY-Hwl.d.mts} +28 -3
- package/dist/shared/{valaxy.DstXQBtK.mjs → valaxy.CRodiDWz.mjs} +402 -1811
- package/dist/types/index.d.mts +2 -2
- package/package.json +9 -15
- package/types/config.ts +12 -1
- package/types/frontmatter/page.ts +9 -2
- package/types/vue-router.d.ts +8 -0
- package/vendor/README.md +8 -8
- package/vendor/sources.json +0 -31
- package/vendor/i18n/LICENSE +0 -20
- package/vendor/i18n/index.d.mts +0 -7
- package/vendor/i18n/index.mjs +0 -1389
- package/vendor/i18n/types.d.ts +0 -48
- package/vendor/layouts/LICENSE +0 -21
- package/vendor/layouts/client.d.ts +0 -11
- package/vendor/layouts/index.d.mts +0 -86
- package/vendor/layouts/index.mjs +0 -235
- package/vendor/layouts/layoutName-DVkP7Qpo.mjs +0 -82
- package/vendor/layouts/runtime.d.mts +0 -72
- package/vendor/layouts/runtime.mjs +0 -284
|
@@ -3,6 +3,7 @@ import { useValaxyI18n } from 'valaxy'
|
|
|
3
3
|
import { computed } from 'vue'
|
|
4
4
|
import { useI18n } from 'vue-i18n'
|
|
5
5
|
import { useSiteConfig } from '../config'
|
|
6
|
+
import { decodePath } from '../utils/path'
|
|
6
7
|
|
|
7
8
|
withDefaults(defineProps<{
|
|
8
9
|
url?: string
|
|
@@ -40,7 +41,7 @@ const licenseHtml = computed(() => {
|
|
|
40
41
|
{{ t('post.copyright.link') + t('symbol.colon') }}
|
|
41
42
|
</strong>
|
|
42
43
|
<a :href="url" target="_blank" :title="t('post.copyright.link')">
|
|
43
|
-
{{
|
|
44
|
+
{{ decodePath(url) }}
|
|
44
45
|
</a>
|
|
45
46
|
</li>
|
|
46
47
|
<li class="post-copyright-license">
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import coverComponents from 'virtual:valaxy-cover-components'
|
|
3
|
+
import { computed, onErrorCaptured, shallowRef, watch } from 'vue'
|
|
4
|
+
import { withBase } from '../utils/path'
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(defineProps<{
|
|
7
|
+
src?: string
|
|
8
|
+
alt?: string
|
|
9
|
+
component?: string
|
|
10
|
+
componentProps?: Record<string, unknown>
|
|
11
|
+
context?: 'card' | 'page'
|
|
12
|
+
}>(), { alt: '', context: 'page' })
|
|
13
|
+
|
|
14
|
+
const failed = shallowRef(false)
|
|
15
|
+
const coverComponent = computed(() => props.component && coverComponents.get(props.component))
|
|
16
|
+
const imageSrc = computed(() => props.src ? withBase(props.src) : undefined)
|
|
17
|
+
const diagnostic = computed(() => {
|
|
18
|
+
if (!import.meta.env.DEV || !props.component)
|
|
19
|
+
return ''
|
|
20
|
+
if (!coverComponent.value)
|
|
21
|
+
return `[valaxy:cover] Unknown component "${props.component}". Check its filename in components/covers/.`
|
|
22
|
+
if (failed.value)
|
|
23
|
+
return `[valaxy:cover] Component "${props.component}" failed to load or render. See the console for details.`
|
|
24
|
+
return ''
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
watch(diagnostic, (message) => {
|
|
28
|
+
if (message)
|
|
29
|
+
console.warn(message)
|
|
30
|
+
}, { immediate: true })
|
|
31
|
+
|
|
32
|
+
watch([() => props.component, () => props.componentProps], () => {
|
|
33
|
+
failed.value = false
|
|
34
|
+
})
|
|
35
|
+
onErrorCaptured((error) => {
|
|
36
|
+
// Keep the static image visible if a custom component fails to load or render.
|
|
37
|
+
failed.value = true
|
|
38
|
+
if (import.meta.env.DEV)
|
|
39
|
+
console.warn(`[valaxy:cover] Error in "${props.component}":`, error)
|
|
40
|
+
return false
|
|
41
|
+
})
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<div v-if="src || coverComponent || diagnostic" class="valaxy-cover">
|
|
46
|
+
<img
|
|
47
|
+
v-if="imageSrc" :src="imageSrc" :alt="alt" class="valaxy-cover-image"
|
|
48
|
+
width="640" height="360" loading="lazy"
|
|
49
|
+
>
|
|
50
|
+
<div v-if="coverComponent && !failed" class="valaxy-cover-content">
|
|
51
|
+
<component
|
|
52
|
+
:is="coverComponent" v-bind="componentProps" :src="src" :context="context"
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
<p v-if="diagnostic" class="valaxy-cover-diagnostic" role="status">
|
|
56
|
+
{{ diagnostic }}
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<style scoped>
|
|
62
|
+
.valaxy-cover {
|
|
63
|
+
position: relative;
|
|
64
|
+
width: 100%;
|
|
65
|
+
aspect-ratio: 16 / 9;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.valaxy-cover-image,
|
|
70
|
+
.valaxy-cover-content {
|
|
71
|
+
position: absolute;
|
|
72
|
+
inset: 0;
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.valaxy-cover-image {
|
|
78
|
+
object-fit: cover;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.valaxy-cover-diagnostic {
|
|
82
|
+
position: absolute;
|
|
83
|
+
inset: auto 0 0;
|
|
84
|
+
z-index: 3;
|
|
85
|
+
margin: 0;
|
|
86
|
+
padding: 0.75rem;
|
|
87
|
+
color: #fff;
|
|
88
|
+
background: #78251c;
|
|
89
|
+
font: 0.8rem/1.5 monospace;
|
|
90
|
+
overflow-wrap: anywhere;
|
|
91
|
+
}
|
|
92
|
+
</style>
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { useSiteConfig } from '../config'
|
|
3
|
+
import FootnotePopover from './footnote/FootnotePopover.vue'
|
|
4
|
+
import LegacyFootnoteTooltip from './footnote/LegacyFootnoteTooltip.vue'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
// Only mount the Tooltip after the component is mounted on the client to avoid mismatches.
|
|
7
|
-
// During SSR and initial client render, a plain <span> is shown instead.
|
|
8
|
-
const mounted = ref(false)
|
|
9
|
-
onMounted(() => {
|
|
10
|
-
mounted.value = true
|
|
11
|
-
})
|
|
6
|
+
const siteConfig = useSiteConfig()
|
|
12
7
|
</script>
|
|
13
8
|
|
|
14
9
|
<template>
|
|
15
|
-
<
|
|
10
|
+
<component :is="siteConfig.footnote.preview === 'floating-vue' ? LegacyFootnoteTooltip : FootnotePopover">
|
|
16
11
|
<slot />
|
|
17
12
|
|
|
18
13
|
<template #popper>
|
|
19
14
|
<slot name="popper" />
|
|
20
15
|
</template>
|
|
21
|
-
</
|
|
22
|
-
<span v-else class="inline-block">
|
|
23
|
-
<slot />
|
|
24
|
-
</span>
|
|
16
|
+
</component>
|
|
25
17
|
</template>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { shallowRef } from 'vue'
|
|
3
|
+
import { svgToPng } from '../utils/svg'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<{
|
|
6
|
+
svg?: SVGSVGElement | null
|
|
7
|
+
filename?: string
|
|
8
|
+
label?: string
|
|
9
|
+
width?: number
|
|
10
|
+
height?: number
|
|
11
|
+
}>(), { filename: 'cover.png', label: 'Export PNG', width: 1200, height: 630 })
|
|
12
|
+
|
|
13
|
+
const pending = shallowRef(false)
|
|
14
|
+
const error = shallowRef('')
|
|
15
|
+
|
|
16
|
+
async function download() {
|
|
17
|
+
if (!props.svg || pending.value)
|
|
18
|
+
return
|
|
19
|
+
pending.value = true
|
|
20
|
+
error.value = ''
|
|
21
|
+
try {
|
|
22
|
+
const png = await svgToPng(props.svg, { width: props.width, height: props.height })
|
|
23
|
+
const url = URL.createObjectURL(png)
|
|
24
|
+
const link = document.createElement('a')
|
|
25
|
+
link.href = url
|
|
26
|
+
link.download = props.filename
|
|
27
|
+
document.body.append(link)
|
|
28
|
+
link.click()
|
|
29
|
+
link.remove()
|
|
30
|
+
// Leave the URL alive long enough for the browser to start the download.
|
|
31
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
32
|
+
}
|
|
33
|
+
catch (cause) {
|
|
34
|
+
error.value = cause instanceof Error ? cause.message : 'Could not export this SVG.'
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
pending.value = false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<div class="valaxy-svg-export">
|
|
44
|
+
<button type="button" :disabled="!svg || pending" :aria-busy="pending" @click="download">
|
|
45
|
+
{{ label }}
|
|
46
|
+
</button>
|
|
47
|
+
<p v-if="error" role="alert">
|
|
48
|
+
{{ error }}
|
|
49
|
+
</p>
|
|
50
|
+
</div>
|
|
51
|
+
</template>
|
|
52
|
+
|
|
53
|
+
<style scoped>
|
|
54
|
+
.valaxy-svg-export button {
|
|
55
|
+
padding: 0.5rem 1rem;
|
|
56
|
+
border: 1px solid currentcolor;
|
|
57
|
+
border-radius: 0.5rem;
|
|
58
|
+
font: inherit;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.valaxy-svg-export button:disabled {
|
|
63
|
+
cursor: wait;
|
|
64
|
+
opacity: 0.6;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.valaxy-svg-export button:focus-visible {
|
|
68
|
+
outline: 2px solid currentcolor;
|
|
69
|
+
outline-offset: 3px;
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { PopoverArrow, PopoverClose, PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
|
|
3
|
+
import { onBeforeUnmount, shallowRef } from 'vue'
|
|
4
|
+
import { useI18n } from 'vue-i18n'
|
|
5
|
+
|
|
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)
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
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>
|
|
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>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Tooltip } from 'floating-vue'
|
|
3
|
+
import { onMounted, ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
// floating-vue Tooltip generates different DOM during SSR vs client hydration.
|
|
6
|
+
// Only mount the Tooltip after the component is mounted on the client to avoid mismatches.
|
|
7
|
+
// During SSR and initial client render, a plain <span> is shown instead.
|
|
8
|
+
const mounted = ref(false)
|
|
9
|
+
onMounted(() => {
|
|
10
|
+
mounted.value = true
|
|
11
|
+
})
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<Tooltip v-if="mounted" class="inline-block" :distance="8">
|
|
16
|
+
<slot />
|
|
17
|
+
|
|
18
|
+
<template #popper>
|
|
19
|
+
<slot name="popper" />
|
|
20
|
+
</template>
|
|
21
|
+
</Tooltip>
|
|
22
|
+
<span v-else class="inline-block">
|
|
23
|
+
<slot />
|
|
24
|
+
</span>
|
|
25
|
+
</template>
|
|
@@ -4,6 +4,7 @@ import { computed, unref } from 'vue'
|
|
|
4
4
|
|
|
5
5
|
import { useRoute } from 'vue-router'
|
|
6
6
|
import collections from '#valaxy/blog/collections'
|
|
7
|
+
import { decodePath } from '../utils/path'
|
|
7
8
|
import { usePageList } from './post'
|
|
8
9
|
|
|
9
10
|
export interface PostCollectionInfo {
|
|
@@ -42,8 +43,9 @@ export function useCollections() {
|
|
|
42
43
|
export function useCollection() {
|
|
43
44
|
const route = useRoute()
|
|
44
45
|
const collectionId = computed(() => {
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const path = decodePath(route.path)
|
|
47
|
+
if (path.startsWith('/collections/')) {
|
|
48
|
+
return path.split('/')[2] // 获取集合 ID
|
|
47
49
|
}
|
|
48
50
|
return ''
|
|
49
51
|
})
|
|
@@ -70,10 +72,12 @@ export function useCollectionPosts(collectionKey: MaybeRef<string>) {
|
|
|
70
72
|
if (!key)
|
|
71
73
|
return []
|
|
72
74
|
|
|
75
|
+
// page paths are percent-encoded, collection and item keys are raw
|
|
73
76
|
const prefix = `/collections/${key}/`
|
|
74
|
-
const pages = pageList.value.filter(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
const pages = pageList.value.filter((p) => {
|
|
78
|
+
const path = p.path ? decodePath(p.path) : ''
|
|
79
|
+
return path.startsWith(prefix) && path !== prefix && !path.endsWith('/')
|
|
80
|
+
})
|
|
77
81
|
|
|
78
82
|
// Sort by collection items order if available
|
|
79
83
|
const col = collections.value.find(c => c.key === key)
|
|
@@ -84,8 +88,8 @@ export function useCollectionPosts(collectionKey: MaybeRef<string>) {
|
|
|
84
88
|
.map((item, idx) => [item.key, idx]),
|
|
85
89
|
)
|
|
86
90
|
return pages.toSorted((a, b) => {
|
|
87
|
-
const aSlug = a.path
|
|
88
|
-
const bSlug = b.path
|
|
91
|
+
const aSlug = decodePath(a.path || '').split('/').pop() || ''
|
|
92
|
+
const bSlug = decodePath(b.path || '').split('/').pop() || ''
|
|
89
93
|
const aIdx = orderMap.get(aSlug) ?? Infinity
|
|
90
94
|
const bIdx = orderMap.get(bSlug) ?? Infinity
|
|
91
95
|
if (aIdx === bIdx)
|
|
@@ -105,7 +109,7 @@ export function useCollectionPosts(collectionKey: MaybeRef<string>) {
|
|
|
105
109
|
*/
|
|
106
110
|
export function usePostCollections(postPath: MaybeRef<string>): ComputedRef<PostCollectionInfo[]> {
|
|
107
111
|
return computed(() => {
|
|
108
|
-
const path = stripTrailingSlash(unref(postPath))
|
|
112
|
+
const path = stripTrailingSlash(decodePath(unref(postPath)))
|
|
109
113
|
if (!path)
|
|
110
114
|
return []
|
|
111
115
|
|
|
@@ -121,7 +125,7 @@ export function usePostCollections(postPath: MaybeRef<string>): ComputedRef<Post
|
|
|
121
125
|
break
|
|
122
126
|
}
|
|
123
127
|
// Match internal link items (non-http)
|
|
124
|
-
if (item.link && !/^https?:\/\//.test(item.link) && stripTrailingSlash(item.link) === path) {
|
|
128
|
+
if (item.link && !/^https?:\/\//.test(item.link) && stripTrailingSlash(decodePath(item.link)) === path) {
|
|
125
129
|
result.push({ collection: col, itemIndex: i })
|
|
126
130
|
break
|
|
127
131
|
}
|
|
@@ -36,6 +36,12 @@ function getCryptoDeriveKey(keyMaterial: CryptoKey, salt: BufferSource) {
|
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Decrypt ciphertext produced by `encryptContent` (valaxy/node).
|
|
41
|
+
*
|
|
42
|
+
* `ciphertext` must be base64. Earlier versions passed a binary string (one
|
|
43
|
+
* char per byte), which no longer decrypts.
|
|
44
|
+
*/
|
|
39
45
|
export function useDecrypt() {
|
|
40
46
|
const siteConfig = useSiteConfig()
|
|
41
47
|
|
|
@@ -51,7 +57,8 @@ export function useDecrypt() {
|
|
|
51
57
|
const keyMaterial = await getKeyMaterial(password)
|
|
52
58
|
const key = await getCryptoDeriveKey(keyMaterial, salt)
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
// ciphertext is base64, see `encryptContent` in node/utils/encrypt.ts
|
|
61
|
+
const ciphertextData = Uint8Array.from(atob(ciphertext), c => c.charCodeAt(0))
|
|
55
62
|
|
|
56
63
|
const decrypted = await window.crypto.subtle.decrypt(
|
|
57
64
|
{
|
|
@@ -24,6 +24,25 @@ function getAbsoluteTop(element: HTMLElement): number {
|
|
|
24
24
|
return offsetTop
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function safeDecode(value: string): string {
|
|
28
|
+
try {
|
|
29
|
+
return decodeURIComponent(value)
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return value
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Themes render outline links either as plain `#id` anchors or as RouterLinks
|
|
38
|
+
* whose href includes the page path, so compare decoded hashes instead of hrefs.
|
|
39
|
+
*/
|
|
40
|
+
function findLinkByHash(container: HTMLElement, hash: string): HTMLAnchorElement | null {
|
|
41
|
+
const target = safeDecode(hash)
|
|
42
|
+
return [...container.querySelectorAll<HTMLAnchorElement>('a[href*="#"]')]
|
|
43
|
+
.find(link => safeDecode(link.hash) === target) ?? null
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
export function useActiveAnchor(
|
|
28
47
|
container: Ref<HTMLElement>,
|
|
29
48
|
marker: Ref<HTMLElement>,
|
|
@@ -118,14 +137,7 @@ export function useActiveAnchor(
|
|
|
118
137
|
if (prevActiveLink)
|
|
119
138
|
prevActiveLink.classList.remove('active')
|
|
120
139
|
|
|
121
|
-
|
|
122
|
-
prevActiveLink = null
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
prevActiveLink = container.value.querySelector(
|
|
126
|
-
`a[href="${decodeURIComponent(hash)}"]`,
|
|
127
|
-
)
|
|
128
|
-
}
|
|
140
|
+
prevActiveLink = hash ? findLinkByHash(container.value, hash) : null
|
|
129
141
|
|
|
130
142
|
const activeLink = prevActiveLink
|
|
131
143
|
checkActiveLinkInViewport()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Post, SiteConfig } from '../../../types'
|
|
2
|
+
import { orderByMeta } from '../../utils/time'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Pure function to filter and sort posts from page list
|
|
6
|
+
* Can be used in both composables and stores without inject() issues
|
|
7
|
+
*/
|
|
8
|
+
export function filterAndSortPosts(
|
|
9
|
+
pages: Post[],
|
|
10
|
+
siteConfig: SiteConfig,
|
|
11
|
+
params: { type?: string, pathPrefix?: string } = {},
|
|
12
|
+
): Post[] {
|
|
13
|
+
const pathPrefix = `${(params.pathPrefix || '/posts').replace(/\/$/, '')}/`
|
|
14
|
+
|
|
15
|
+
// Filter posts
|
|
16
|
+
const routes = pages
|
|
17
|
+
.filter(i =>
|
|
18
|
+
i.path?.startsWith(pathPrefix)
|
|
19
|
+
&& !i.path?.endsWith('.html')
|
|
20
|
+
&& i.date
|
|
21
|
+
&& (import.meta.env.DEV || !i.draft) // filter draft posts in production (SSG safety net)
|
|
22
|
+
&& (!params.type || i.type === params.type)
|
|
23
|
+
&& (!i.hide || i.hide === 'index'), // hide `hide: all` posts
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
function sortBySiteConfigOrderBy(posts: Post[]) {
|
|
27
|
+
const orderBy = siteConfig.orderBy
|
|
28
|
+
return orderByMeta(posts, orderBy)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 置顶
|
|
33
|
+
*/
|
|
34
|
+
const topPosts = sortBySiteConfigOrderBy(routes.filter(i => i.top)).sort((a, b) => b.top! - a.top!)
|
|
35
|
+
const otherPosts = sortBySiteConfigOrderBy(routes.filter(i => !i.top))
|
|
36
|
+
|
|
37
|
+
return [...topPosts, ...otherPosts]
|
|
38
|
+
}
|
|
@@ -7,7 +7,9 @@ import { useI18n } from 'vue-i18n'
|
|
|
7
7
|
import collections from '#valaxy/blog/collections'
|
|
8
8
|
import { useRouterStore } from '../../stores'
|
|
9
9
|
import { isLocaleKey, stripLocalePrefix, tObject } from '../../utils'
|
|
10
|
+
import { filterAndSortPosts } from './filter'
|
|
10
11
|
|
|
12
|
+
export { filterAndSortPosts } from './filter'
|
|
11
13
|
export * from './usePagination'
|
|
12
14
|
export * from './usePrevNext'
|
|
13
15
|
|
|
@@ -54,40 +56,6 @@ export function usePageList() {
|
|
|
54
56
|
})
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
/**
|
|
58
|
-
* Pure function to filter and sort posts from page list
|
|
59
|
-
* Can be used in both composables and stores without inject() issues
|
|
60
|
-
*/
|
|
61
|
-
export function filterAndSortPosts(
|
|
62
|
-
pages: Post[],
|
|
63
|
-
siteConfig: SiteConfig,
|
|
64
|
-
params: { type?: string } = {},
|
|
65
|
-
): Post[] {
|
|
66
|
-
// Filter posts
|
|
67
|
-
const routes = pages
|
|
68
|
-
.filter(i =>
|
|
69
|
-
i.path?.startsWith('/posts')
|
|
70
|
-
&& !i.path?.endsWith('.html')
|
|
71
|
-
&& i.date
|
|
72
|
-
&& (import.meta.env.DEV || !i.draft) // filter draft posts in production (SSG safety net)
|
|
73
|
-
&& (!params.type || i.type === params.type)
|
|
74
|
-
&& (!i.hide || i.hide === 'index'), // hide `hide: all` posts
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
function sortBySiteConfigOrderBy(posts: Post[]) {
|
|
78
|
-
const orderBy = siteConfig.orderBy
|
|
79
|
-
return orderByMeta(posts, orderBy)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 置顶
|
|
84
|
-
*/
|
|
85
|
-
const topPosts = sortBySiteConfigOrderBy(routes.filter(i => i.top)).sort((a, b) => b.top! - a.top!)
|
|
86
|
-
const otherPosts = sortBySiteConfigOrderBy(routes.filter(i => !i.top))
|
|
87
|
-
|
|
88
|
-
return [...topPosts, ...otherPosts]
|
|
89
|
-
}
|
|
90
|
-
|
|
91
59
|
/**
|
|
92
60
|
* Merge collapsed collections into the post list.
|
|
93
61
|
* For collapsed collections, add a single synthetic entry representing the
|
package/client/index.d.ts
CHANGED
package/client/layouts/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Vue components in this dir are used as layouts.
|
|
|
4
4
|
|
|
5
5
|
By default, `default.vue` will be used unless an alternative is specified in the route meta.
|
|
6
6
|
|
|
7
|
-
With [vue-router](https://router.vuejs.org/) file-based routing and
|
|
7
|
+
With [vue-router](https://router.vuejs.org/) file-based routing and Valaxy's layout system (`virtual:generated-layouts`), you can specify the layout in the page's SFCs like this:
|
|
8
8
|
|
|
9
9
|
```html
|
|
10
10
|
<route lang="yaml">
|
package/client/locales/en.yml
CHANGED