valaxy 1.3.2 → 1.3.4
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 -3
- package/client/composables/app/useValaxyApp.ts +1 -0
- 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/config.ts +1 -0
- package/client/utils/router.ts +83 -37
- package/dist/node/cli/index.d.mts +1 -1
- package/dist/node/cli/index.mjs +6 -5
- package/dist/node/index.d.mts +22 -6
- package/dist/node/index.mjs +6 -5
- package/dist/shared/{valaxy.BIKfV_jq.mjs → valaxy.DQnMfBEN.mjs} +1026 -340
- package/package.json +4 -4
- package/shared/page-policy.ts +3 -9
- package/shared/utils/index.ts +2 -0
- package/shared/utils/sanitize.ts +82 -0
- package/shared/utils/uri.ts +93 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valaxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.4",
|
|
5
5
|
"description": "📄 Vite & Vue powered static blog generator.",
|
|
6
6
|
"author": {
|
|
7
7
|
"email": "me@yunyoujun.cn",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@unhead/bundler": "^3.4.1",
|
|
77
77
|
"@unhead/schema-org": "^3.4.1",
|
|
78
78
|
"@unhead/vue": "^3.4.1",
|
|
79
|
-
"@valaxyjs/devtools": "1.3.
|
|
80
|
-
"@valaxyjs/utils": "1.3.
|
|
79
|
+
"@valaxyjs/devtools": "1.3.4",
|
|
80
|
+
"@valaxyjs/utils": "1.3.4",
|
|
81
81
|
"@vitejs/devtools": "0.8.0",
|
|
82
82
|
"@vitejs/plugin-vue": "^6.0.9",
|
|
83
83
|
"@vueuse/core": "^15.0.0",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"fuse.js": "^7.5.0",
|
|
98
98
|
"hookable": "^6.1.2",
|
|
99
99
|
"html-to-text": "^10.0.1",
|
|
100
|
+
"htmlparser2": "^10.1.0",
|
|
100
101
|
"jiti": "^2.7.0",
|
|
101
102
|
"js-base64": "^3.9.4",
|
|
102
103
|
"js-yaml": "^5.4.2",
|
|
@@ -142,7 +143,6 @@
|
|
|
142
143
|
"vanilla-lazyload": "^19.1.3",
|
|
143
144
|
"vite": "^8.3.6",
|
|
144
145
|
"vite-plugin-vue-devtools": "^8.2.1",
|
|
145
|
-
"vite-ssg-sitemap": "^0.10.0",
|
|
146
146
|
"vitepress-plugin-group-icons": "^1.7.6",
|
|
147
147
|
"vue-i18n": "^11.4.18",
|
|
148
148
|
"yargs": "^18.1.0"
|
package/shared/page-policy.ts
CHANGED
|
@@ -111,13 +111,7 @@ export function omitProductionDraftRoutes<T extends DraftRoute>(routes: T[], inc
|
|
|
111
111
|
})
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/**
|
|
115
|
-
export function
|
|
116
|
-
|
|
117
|
-
for (const route of routes) {
|
|
118
|
-
const path = route.length > 1 && route.endsWith('/') ? route.slice(0, -1) : route
|
|
119
|
-
if (path === '/404' || path.endsWith('/404'))
|
|
120
|
-
paths.add(path)
|
|
121
|
-
}
|
|
122
|
-
return [...paths]
|
|
114
|
+
/** Paths reserved for a site's not-found document. */
|
|
115
|
+
export function isNotFoundPagePath(path: string): boolean {
|
|
116
|
+
return /\/404(?:\.html|\/(?:index\.html)?)?$/.test(path)
|
|
123
117
|
}
|
package/shared/utils/index.ts
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const HTML_ESCAPE_MAP: Record<string, string> = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
'\'': ''',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const SAFE_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:'])
|
|
10
|
+
const SAFE_DATA_IMAGE_RE = /^data:image\/(?:png|jpe?g|gif|webp|avif|x-icon|vnd\.microsoft\.icon|svg\+xml)[;,]/i
|
|
11
|
+
|
|
12
|
+
function stripControlsAndSpaces(value: string): string {
|
|
13
|
+
let out = ''
|
|
14
|
+
for (let i = 0; i < value.length; i++) {
|
|
15
|
+
const code = value.charCodeAt(i)
|
|
16
|
+
if (code > 0x20 && code !== 0x7F)
|
|
17
|
+
out += value[i]
|
|
18
|
+
}
|
|
19
|
+
return out
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function hasControlChars(value: string): boolean {
|
|
23
|
+
for (let i = 0; i < value.length; i++) {
|
|
24
|
+
const code = value.charCodeAt(i)
|
|
25
|
+
if (code <= 0x1F || code === 0x7F)
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Escape HTML special characters for safe interpolation into HTML text and quoted attributes.
|
|
33
|
+
*/
|
|
34
|
+
export function escapeHtml(str = ''): string {
|
|
35
|
+
return str.replace(/[&<>"']/g, ch => HTML_ESCAPE_MAP[ch])
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Serialize a string as an inline JavaScript string literal safe inside `<script>` tags.
|
|
40
|
+
*/
|
|
41
|
+
export function serializeInlineJsString(value: string): string {
|
|
42
|
+
return JSON.stringify(value)
|
|
43
|
+
.replace(/</g, '\\u003c')
|
|
44
|
+
.replace(/>/g, '\\u003e')
|
|
45
|
+
.replace(/&/g, '\\u0026')
|
|
46
|
+
.replace(/'/g, '\\u0027')
|
|
47
|
+
.replace(/\//g, '\\u002f')
|
|
48
|
+
.replace(/\u2028/g, '\\u2028')
|
|
49
|
+
.replace(/\u2029/g, '\\u2029')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SanitizeUrlOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Allow `data:image/...` URIs (intended for `<link rel="icon">` / image metadata, not navigation links).
|
|
55
|
+
*/
|
|
56
|
+
allowDataImage?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Sanitize a URL so dangerous schemes like `javascript:`, `vbscript:`, or `data:text/html` cannot execute.
|
|
61
|
+
*/
|
|
62
|
+
export function sanitizeUrl(url?: string, fallback = '#', options: SanitizeUrlOptions = {}): string {
|
|
63
|
+
if (!url)
|
|
64
|
+
return fallback
|
|
65
|
+
|
|
66
|
+
const trimmed = url.trim()
|
|
67
|
+
if (!trimmed || hasControlChars(trimmed))
|
|
68
|
+
return fallback
|
|
69
|
+
|
|
70
|
+
const normalized = stripControlsAndSpaces(trimmed)
|
|
71
|
+
if (!normalized)
|
|
72
|
+
return fallback
|
|
73
|
+
|
|
74
|
+
if (options.allowDataImage && SAFE_DATA_IMAGE_RE.test(normalized))
|
|
75
|
+
return trimmed
|
|
76
|
+
|
|
77
|
+
const schemeMatch = normalized.match(/^([a-z][a-z\d+.-]*):/i)
|
|
78
|
+
if (schemeMatch && !SAFE_URL_PROTOCOLS.has(`${schemeMatch[1].toLowerCase()}:`))
|
|
79
|
+
return fallback
|
|
80
|
+
|
|
81
|
+
return trimmed
|
|
82
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const PROTOCOL_PREFIX_RE = /^(?:[a-z][a-z\d+.-]*:)?\/\//i
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Safely decode a URI, returning the original string on malformed sequences.
|
|
5
|
+
*/
|
|
6
|
+
export function safeDecodeURI(uri: string): string {
|
|
7
|
+
try {
|
|
8
|
+
return decodeURI(uri)
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return uri
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Safely decode a URI component, returning the original string on malformed sequences.
|
|
17
|
+
*/
|
|
18
|
+
export function safeDecodeURIComponent(uri: string): string {
|
|
19
|
+
try {
|
|
20
|
+
return decodeURIComponent(uri)
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return uri
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Safely parse a URL relative to an optional base, returning null on invalid syntax.
|
|
29
|
+
*/
|
|
30
|
+
export function safeParseUrl(url: string, base?: string): URL | null {
|
|
31
|
+
try {
|
|
32
|
+
return new URL(url, base)
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Join a Vite base URL and a route path while preserving protocol/relative prefixes and `/` separators.
|
|
41
|
+
*/
|
|
42
|
+
export function joinBaseUrl(base = '/', routePath = ''): string {
|
|
43
|
+
const normalizedBase = (base || '/').replace(/\\/g, '/')
|
|
44
|
+
const normalizedRoute = routePath.replace(/\\/g, '/').replace(/^\/+/, '')
|
|
45
|
+
|
|
46
|
+
const protocolMatch = normalizedBase.match(PROTOCOL_PREFIX_RE)
|
|
47
|
+
if (protocolMatch) {
|
|
48
|
+
const prefix = protocolMatch[0]
|
|
49
|
+
const afterProtocol = normalizedBase.slice(prefix.length)
|
|
50
|
+
const slashIdx = afterProtocol.indexOf('/')
|
|
51
|
+
const authority = slashIdx === -1 ? afterProtocol : afterProtocol.slice(0, slashIdx)
|
|
52
|
+
const basePath = slashIdx === -1 ? '' : afterProtocol.slice(slashIdx).replace(/\/+$/, '')
|
|
53
|
+
const joinedPath = normalizedRoute ? `${basePath}/${normalizedRoute}` : `${basePath || ''}/`
|
|
54
|
+
return `${prefix}${authority}${joinedPath.startsWith('/') ? joinedPath : `/${joinedPath}`}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (normalizedBase.startsWith('./') || normalizedBase === '.') {
|
|
58
|
+
const cleanBase = normalizedBase.replace(/\/+$/, '')
|
|
59
|
+
const prefix = cleanBase === '.' ? './' : `${cleanBase}/`
|
|
60
|
+
return `${prefix}${normalizedRoute}`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const cleanBasePath = `/${normalizedBase.replace(/^\/+|\/+$/g, '')}`
|
|
64
|
+
if (!normalizedRoute)
|
|
65
|
+
return cleanBasePath === '/' ? '/' : `${cleanBasePath}/`
|
|
66
|
+
|
|
67
|
+
return cleanBasePath === '/'
|
|
68
|
+
? `/${normalizedRoute}`
|
|
69
|
+
: `${cleanBasePath}/${normalizedRoute}`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const INDEX_ONLY_SEGMENTS_RE = /^index(?:\/index)*$/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Map a route/URL path (e.g. `''`, `'/'`, `'/index'`, `'/posts/hello/'`) to a collision-free
|
|
76
|
+
* raw Markdown href and relative file path.
|
|
77
|
+
* - `''` / `'/'` (`pages/index.md`) -> `/index.md` (`index.md`)
|
|
78
|
+
* - `'/index'` (`pages/index/index.md`) -> `/index/index.md` (`index/index.md`)
|
|
79
|
+
* - `'/index/index'` -> `/index/index/index.md` (`index/index/index.md`)
|
|
80
|
+
* - Other routes keep `${normalized}.md`.
|
|
81
|
+
*/
|
|
82
|
+
export function urlPathToMarkdownPath(urlPath: string): { href: string, relativeFile: string } {
|
|
83
|
+
const normalized = urlPath.replace(/\\/g, '/').replace(/^\/+|\/+$/g, '')
|
|
84
|
+
const relativeFile = !normalized
|
|
85
|
+
? 'index.md'
|
|
86
|
+
: INDEX_ONLY_SEGMENTS_RE.test(normalized)
|
|
87
|
+
? `${normalized}/index.md`
|
|
88
|
+
: `${normalized}.md`
|
|
89
|
+
return {
|
|
90
|
+
href: `/${relativeFile}`,
|
|
91
|
+
relativeFile,
|
|
92
|
+
}
|
|
93
|
+
}
|