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
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { NodeRelations, ImageObject } from '@unhead/schema-org';
|
|
2
|
+
import { C as CollectionConfig } from '../../shared/valaxy.CaLqd5CH.mjs';
|
|
3
|
+
|
|
4
|
+
interface Album {
|
|
5
|
+
/**
|
|
6
|
+
* @description:en-US Album Link
|
|
7
|
+
*/
|
|
8
|
+
url: string;
|
|
9
|
+
/**
|
|
10
|
+
* @description:en-US Album cover
|
|
11
|
+
* url
|
|
12
|
+
*/
|
|
13
|
+
cover: string;
|
|
14
|
+
/**
|
|
15
|
+
* @description:en-US Album caption
|
|
16
|
+
*/
|
|
17
|
+
caption: string;
|
|
18
|
+
/**
|
|
19
|
+
* @description:en-US Album description
|
|
20
|
+
*/
|
|
21
|
+
desc: string;
|
|
22
|
+
}
|
|
23
|
+
interface Photo {
|
|
24
|
+
src: string;
|
|
25
|
+
caption: string;
|
|
26
|
+
desc: string;
|
|
27
|
+
}
|
|
28
|
+
interface BaseFrontMatter extends Record<string, any> {
|
|
29
|
+
/** Canonical URL or site-relative path, independent of the current route alias. */
|
|
30
|
+
canonical?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Title
|
|
33
|
+
* @description 文章标题
|
|
34
|
+
*
|
|
35
|
+
* ```md
|
|
36
|
+
* ---
|
|
37
|
+
* title: Post Title
|
|
38
|
+
* ---
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* i18n:
|
|
42
|
+
*
|
|
43
|
+
* ```md
|
|
44
|
+
* ---
|
|
45
|
+
* title:
|
|
46
|
+
* en: Post Title
|
|
47
|
+
* zh-CN: 文章标题
|
|
48
|
+
* ---
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
title: string | Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* @description:en-US Created Date
|
|
54
|
+
* @description:zh-CN 文章创建日期
|
|
55
|
+
*/
|
|
56
|
+
date: string | number | Date;
|
|
57
|
+
/**
|
|
58
|
+
* Updated Time
|
|
59
|
+
*/
|
|
60
|
+
updated: string | number | Date;
|
|
61
|
+
}
|
|
62
|
+
interface PageFrontMatter extends BaseFrontMatter {
|
|
63
|
+
/**
|
|
64
|
+
* Path of post
|
|
65
|
+
* route.path
|
|
66
|
+
* @description 路径
|
|
67
|
+
*/
|
|
68
|
+
path: string;
|
|
69
|
+
/**
|
|
70
|
+
* abbrlink
|
|
71
|
+
*
|
|
72
|
+
* generated by valaxy-addon-abbrlink, do not manually modify
|
|
73
|
+
*
|
|
74
|
+
* just compatible for [hexo-abbrlink](https://github.com/ohroy/hexo-abbrlink)
|
|
75
|
+
*/
|
|
76
|
+
abbrlink: string;
|
|
77
|
+
/**
|
|
78
|
+
* i18n
|
|
79
|
+
*/
|
|
80
|
+
lang: string;
|
|
81
|
+
/**
|
|
82
|
+
* @description Author
|
|
83
|
+
* @description:zh-CN 作者
|
|
84
|
+
*/
|
|
85
|
+
author: string;
|
|
86
|
+
/**
|
|
87
|
+
* Display sponsor info
|
|
88
|
+
* @description 是否开启赞助
|
|
89
|
+
*/
|
|
90
|
+
sponsor: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Copyright
|
|
93
|
+
* @description 是否显示文章底部版权信息
|
|
94
|
+
*/
|
|
95
|
+
copyright: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* for seo
|
|
98
|
+
* schema
|
|
99
|
+
*/
|
|
100
|
+
image: NodeRelations<ImageObject | string>;
|
|
101
|
+
/**
|
|
102
|
+
* cover
|
|
103
|
+
* @description 封面图片(使用组件封面时可省略)
|
|
104
|
+
*/
|
|
105
|
+
cover?: string;
|
|
106
|
+
/**
|
|
107
|
+
* @description:en-US Vue component name from components/covers/, rendered by supporting themes. An image cover is optional.
|
|
108
|
+
* @description:zh-CN components/covers/ 下的 Vue 组件名,由支持的主题渲染。图片 cover 可省略。
|
|
109
|
+
*/
|
|
110
|
+
coverComponent?: string;
|
|
111
|
+
/** JSON-serializable props passed to the cover component. */
|
|
112
|
+
coverProps?: Record<string, unknown>;
|
|
113
|
+
/**
|
|
114
|
+
* @description:en-US Open Graph image for SEO
|
|
115
|
+
* @description:zh-CN Open Graph 图片,用于 SEO
|
|
116
|
+
*/
|
|
117
|
+
ogImage: string;
|
|
118
|
+
/**
|
|
119
|
+
* @protected
|
|
120
|
+
* @tutorial ⚠️ DO NOT SET MANUALLY (auto-extracted from markdown content)
|
|
121
|
+
* @description:en-US First image URL extracted from markdown content
|
|
122
|
+
* @description:zh-CN 从 Markdown 内容中自动提取的第一张图片 URL
|
|
123
|
+
*/
|
|
124
|
+
firstImage: string;
|
|
125
|
+
/**
|
|
126
|
+
* display toc
|
|
127
|
+
* @description 是否显示目录
|
|
128
|
+
*/
|
|
129
|
+
toc: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* display right sidebar
|
|
132
|
+
* @description 是否显示右侧侧边栏
|
|
133
|
+
*/
|
|
134
|
+
aside: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* display left sidebar
|
|
137
|
+
* @description 是否显示左侧侧边栏
|
|
138
|
+
*/
|
|
139
|
+
sidebar: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* @description:en-US Custom Markdown class
|
|
142
|
+
* @description:zh-CN 自定义 Markdown 样式
|
|
143
|
+
* @default 'markdown-body'
|
|
144
|
+
*/
|
|
145
|
+
markdownClass: string;
|
|
146
|
+
/**
|
|
147
|
+
* icon before title
|
|
148
|
+
* @description 标题前的图标
|
|
149
|
+
*/
|
|
150
|
+
icon: string;
|
|
151
|
+
/**
|
|
152
|
+
* display comment
|
|
153
|
+
*/
|
|
154
|
+
comment: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* post is end
|
|
157
|
+
* @description 是否完结,将在末尾添加衬线字体 Q.E.D.
|
|
158
|
+
*/
|
|
159
|
+
end: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Enable/disable KaTeX math rendering for this page.
|
|
162
|
+
* Overrides the global `features.katex` setting.
|
|
163
|
+
*
|
|
164
|
+
* - When `features.katex: true` (default), set `katex: false` to disable KaTeX for this page.
|
|
165
|
+
* - When `features.katex: false`, set `katex: true` to enable KaTeX for this page.
|
|
166
|
+
*
|
|
167
|
+
* @url https://katex.org/
|
|
168
|
+
*/
|
|
169
|
+
katex: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* use medium-zoom
|
|
172
|
+
* @url https://github.com/francoischalifour/medium-zoom
|
|
173
|
+
*/
|
|
174
|
+
medium_zoom: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* @description:en-US Albums
|
|
177
|
+
* @description:zh-CN 相册
|
|
178
|
+
*/
|
|
179
|
+
albums: Album[];
|
|
180
|
+
/**
|
|
181
|
+
* For layout Gallery
|
|
182
|
+
* @description:en-US Photos
|
|
183
|
+
*/
|
|
184
|
+
photos: Photo[];
|
|
185
|
+
/**
|
|
186
|
+
* for collections
|
|
187
|
+
*/
|
|
188
|
+
collections: CollectionConfig[];
|
|
189
|
+
/**
|
|
190
|
+
* @description:zh-CN 是否启用加密,password 存在时默认为 true
|
|
191
|
+
*/
|
|
192
|
+
encrypt: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* @description:zh-CN 加密密码
|
|
195
|
+
*/
|
|
196
|
+
password?: string;
|
|
197
|
+
/**
|
|
198
|
+
* @description:zh-CN 密码提示
|
|
199
|
+
*/
|
|
200
|
+
password_hint?: string;
|
|
201
|
+
/**
|
|
202
|
+
* @description:zh-CN 相册密码
|
|
203
|
+
*/
|
|
204
|
+
gallery_password?: string;
|
|
205
|
+
/**
|
|
206
|
+
* @en
|
|
207
|
+
* @description encrypted content
|
|
208
|
+
*
|
|
209
|
+
* @description:zh-CN 加密后的内容
|
|
210
|
+
*/
|
|
211
|
+
encryptedContent?: string;
|
|
212
|
+
/**
|
|
213
|
+
* @description:zh-CN 部分加密的内容
|
|
214
|
+
*/
|
|
215
|
+
partiallyEncryptedContents?: string[];
|
|
216
|
+
/**
|
|
217
|
+
* @description:zh-CN 加密后的相册
|
|
218
|
+
*/
|
|
219
|
+
encryptedPhotos?: string;
|
|
220
|
+
/**
|
|
221
|
+
* @description:en-US Limit the height of the code block in px
|
|
222
|
+
* @description:zh-CN 限制代码块的高度,单位是 px
|
|
223
|
+
*/
|
|
224
|
+
codeHeightLimit?: number;
|
|
225
|
+
/**
|
|
226
|
+
* @description:en-US Source path for client redirection
|
|
227
|
+
* @description:zh-CN 客户端重定向的源路径
|
|
228
|
+
*/
|
|
229
|
+
from?: string | string[];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
type ExcerptType = 'md' | 'html' | 'text' | 'ai';
|
|
233
|
+
interface PostFrontMatter extends PageFrontMatter {
|
|
234
|
+
/**
|
|
235
|
+
* @description:en-US Post Card Type, can be bilibili/yuque/... (need theme support)
|
|
236
|
+
* @description:zh-CN 卡片类型,可以是 bilibili/yuque/... (需主题支持)
|
|
237
|
+
*/
|
|
238
|
+
type: 'bilibili' | 'yuque' | string;
|
|
239
|
+
/**
|
|
240
|
+
* @en override url, and jump directly
|
|
241
|
+
* @zh 覆盖 post url,直接跳转
|
|
242
|
+
*/
|
|
243
|
+
url: string;
|
|
244
|
+
/**
|
|
245
|
+
* @description:en-US custom excerpt, `excerpt_type` will be invalid
|
|
246
|
+
* @description 手动指定摘要,此时 `excerpt_type` 将会无效
|
|
247
|
+
*/
|
|
248
|
+
excerpt: string;
|
|
249
|
+
/**
|
|
250
|
+
* @description 摘要类型
|
|
251
|
+
* @default 'html'
|
|
252
|
+
* render type of excerpt
|
|
253
|
+
* - md: render as raw markdown
|
|
254
|
+
* - html: render as html
|
|
255
|
+
* - text: render as text
|
|
256
|
+
*/
|
|
257
|
+
excerpt_type: 'md' | 'text' | 'html' | 'ai';
|
|
258
|
+
/**
|
|
259
|
+
* @description:en-US Category, if it is an array, it represents multiple folders in order
|
|
260
|
+
* @description:zh-CN 分类,若为数组,则按顺序代表多层文件夹
|
|
261
|
+
*/
|
|
262
|
+
categories: string | string[];
|
|
263
|
+
/**
|
|
264
|
+
* @description:en-US Tags, can have multiple
|
|
265
|
+
* @description:zh-CN 标签,可以有多个
|
|
266
|
+
*/
|
|
267
|
+
tags: string[];
|
|
268
|
+
/**
|
|
269
|
+
* @description:en-US Whether to display the previous and next navigation
|
|
270
|
+
* @description:zh-CN 是否显示前一篇、后一篇导航
|
|
271
|
+
*/
|
|
272
|
+
nav: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* @description:en-US Pin to top, the larger the number, the closer to the front
|
|
275
|
+
* @description:zh-CN 置顶,数字越大越靠前
|
|
276
|
+
*/
|
|
277
|
+
top: number;
|
|
278
|
+
/**
|
|
279
|
+
* @description:en-US Whether it is a draft, it will only be displayed during development
|
|
280
|
+
* @description:zh-CN 是否为草稿,将仅在开发时被展示
|
|
281
|
+
*/
|
|
282
|
+
draft: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* hide in index
|
|
285
|
+
* - true/`all`: hide in index & archive
|
|
286
|
+
* - `index`: hide in index
|
|
287
|
+
* @description 是否隐藏
|
|
288
|
+
*/
|
|
289
|
+
hide: 'index' | boolean;
|
|
290
|
+
/**
|
|
291
|
+
* @en
|
|
292
|
+
* when the post is updated more than 30 days ago, show a warning
|
|
293
|
+
* default 30 days, you can set `time_warning` in frontmatter to change it
|
|
294
|
+
*
|
|
295
|
+
* @zh
|
|
296
|
+
* 当文章更新时间超过 30 天时,显示一个警告
|
|
297
|
+
* 默认 30 天,你可以在 frontmatter 中设置 `time_warning` (数字)来修改,单位 ms
|
|
298
|
+
* @example 3600000
|
|
299
|
+
*/
|
|
300
|
+
time_warning: boolean | number;
|
|
301
|
+
/**
|
|
302
|
+
* @protected
|
|
303
|
+
* @see https://valaxy.site/guide/config/#%E9%98%85%E8%AF%BB%E7%BB%9F%E8%AE%A1
|
|
304
|
+
* @tutorial ⚠️ DO NOT SET MANUALLY (generated by `site.config.ts` -> `statistics.enable: true`)
|
|
305
|
+
* You can use `statistics.readTime.speed` to change the speed of reading time.
|
|
306
|
+
* @description:en-US Reading time
|
|
307
|
+
* @description:zh-CN 阅读时间
|
|
308
|
+
*/
|
|
309
|
+
readingTime: number;
|
|
310
|
+
/**
|
|
311
|
+
* @protected
|
|
312
|
+
* @see https://valaxy.site/guide/config/#%E9%98%85%E8%AF%BB%E7%BB%9F%E8%AE%A1
|
|
313
|
+
* @tutorial ⚠️ DO NOT SET MANUALLY (generated by `site.config.ts` -> `statistics.enable: true`)
|
|
314
|
+
* You need enable `statistics` in site config to use this feature.
|
|
315
|
+
* @description:en-US Word count
|
|
316
|
+
* @description:zh-CN 字数统计
|
|
317
|
+
*/
|
|
318
|
+
wordCount: string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export type { Album, BaseFrontMatter, ExcerptType, PageFrontMatter, Photo, PostFrontMatter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { c as Post } from '../shared/valaxy.
|
|
2
|
-
export {
|
|
1
|
+
import { c as Post } from '../shared/valaxy.ukLrUCoH.mjs';
|
|
2
|
+
export { D as DefaultTheme, F as FuseListItem, L as LlmsCollapse, d as LlmsFeatured, e as Page, P as PartialDeep, f as Pkg, a as RedirectItem, g as RedirectRule, R as RuntimeConfig, S as SiteConfig, h as SocialLink, U as UserSiteConfig, i as UserValaxyConfig, b as ValaxyAddon, V as ValaxyConfig } from '../shared/valaxy.ukLrUCoH.mjs';
|
|
3
3
|
import { Header } from '@valaxyjs/utils';
|
|
4
|
+
export * from 'valaxy/types/frontmatter';
|
|
5
|
+
import '../shared/valaxy.CaLqd5CH.mjs';
|
|
4
6
|
import '@vueuse/integrations/useFuse';
|
|
5
7
|
import 'medium-zoom';
|
|
6
8
|
import 'vanilla-lazyload';
|
|
7
9
|
import 'vue-router';
|
|
8
10
|
import '@vueuse/core';
|
|
9
|
-
import '@unhead/schema-org';
|
|
10
11
|
|
|
11
12
|
type CleanUrlsMode = 'disabled' | 'without-subfolders' | 'with-subfolders';
|
|
12
13
|
interface PageData {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valaxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"description": "📄 Vite & Vue powered static blog generator.",
|
|
6
6
|
"author": {
|
|
7
7
|
"email": "me@yunyoujun.cn",
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
"types": "./dist/types/index.d.mts",
|
|
38
38
|
"default": "./dist/types/index.mjs"
|
|
39
39
|
},
|
|
40
|
+
"./types/frontmatter": {
|
|
41
|
+
"types": "./dist/types/frontmatter/index.d.mts"
|
|
42
|
+
},
|
|
40
43
|
"./package.json": "./package.json",
|
|
41
44
|
"./*": "./*"
|
|
42
45
|
},
|
|
@@ -76,8 +79,8 @@
|
|
|
76
79
|
"@unhead/bundler": "^3.4.1",
|
|
77
80
|
"@unhead/schema-org": "^3.4.1",
|
|
78
81
|
"@unhead/vue": "^3.4.1",
|
|
79
|
-
"@valaxyjs/devtools": "1.
|
|
80
|
-
"@valaxyjs/utils": "1.
|
|
82
|
+
"@valaxyjs/devtools": "1.4.0",
|
|
83
|
+
"@valaxyjs/utils": "1.4.0",
|
|
81
84
|
"@vitejs/devtools": "0.8.0",
|
|
82
85
|
"@vitejs/plugin-vue": "^6.0.9",
|
|
83
86
|
"@vueuse/core": "^15.0.0",
|
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
|
+
}
|
package/types/config.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { FuseOptions } from '@vueuse/integrations/useFuse'
|
|
2
2
|
import type { ZoomOptions } from 'medium-zoom'
|
|
3
|
+
import type { ExcerptType, PostFrontMatter } from 'valaxy/types/frontmatter'
|
|
3
4
|
import type { ILazyLoadOptions } from 'vanilla-lazyload'
|
|
4
5
|
import type { RouteRecordRaw } from 'vue-router'
|
|
5
6
|
import type { ValaxyAddon } from './addon'
|
|
6
7
|
import type { DefaultTheme } from './default-theme'
|
|
7
|
-
import type { PostFrontMatter } from './frontmatter'
|
|
8
|
-
import type { ExcerptType } from './frontmatter/post'
|
|
9
8
|
import type { FuseListItem } from './node'
|
|
10
9
|
|
|
11
10
|
import './default-theme'
|
|
@@ -153,12 +153,6 @@ export interface PageFrontMatter extends BaseFrontMatter {
|
|
|
153
153
|
*/
|
|
154
154
|
markdownClass: string
|
|
155
155
|
|
|
156
|
-
/**
|
|
157
|
-
* @description:en-US Post title class
|
|
158
|
-
* @description:zh-CN 文章标题样式
|
|
159
|
-
*/
|
|
160
|
-
pageTitleClass: string
|
|
161
|
-
|
|
162
156
|
/**
|
|
163
157
|
* icon before title
|
|
164
158
|
* @description 标题前的图标
|
|
@@ -184,11 +178,6 @@ export interface PageFrontMatter extends BaseFrontMatter {
|
|
|
184
178
|
* @url https://katex.org/
|
|
185
179
|
*/
|
|
186
180
|
katex: boolean
|
|
187
|
-
/**
|
|
188
|
-
* use codepen
|
|
189
|
-
* @url https://codepen.io/
|
|
190
|
-
*/
|
|
191
|
-
codepen: boolean
|
|
192
181
|
/**
|
|
193
182
|
* use medium-zoom
|
|
194
183
|
* @url https://github.com/francoischalifour/medium-zoom
|
|
@@ -3,12 +3,6 @@ import type { PageFrontMatter } from './page'
|
|
|
3
3
|
export type ExcerptType = 'md' | 'html' | 'text' | 'ai'
|
|
4
4
|
|
|
5
5
|
export interface PostFrontMatter extends PageFrontMatter {
|
|
6
|
-
/**
|
|
7
|
-
* @description:en-US Custom post title class in post list
|
|
8
|
-
* @description:zh-CN 文章列表中 自定义标题样式
|
|
9
|
-
*/
|
|
10
|
-
postTitleClass: string
|
|
11
|
-
|
|
12
6
|
/**
|
|
13
7
|
* @description:en-US Post Card Type, can be bilibili/yuque/... (need theme support)
|
|
14
8
|
* @description:zh-CN 卡片类型,可以是 bilibili/yuque/... (需主题支持)
|
package/types/index.ts
CHANGED
|
@@ -7,9 +7,9 @@ export * from './config'
|
|
|
7
7
|
export * from './data'
|
|
8
8
|
// default theme
|
|
9
9
|
export * from './default-theme'
|
|
10
|
-
export * from './frontmatter'
|
|
11
10
|
|
|
12
11
|
// used in node, but without node deps
|
|
13
12
|
// and need be shared with client types
|
|
14
13
|
export * from './node'
|
|
15
14
|
export * from './posts'
|
|
15
|
+
export type * from 'valaxy/types/frontmatter'
|
package/types/posts.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { PageFrontMatter, PostFrontMatter } from 'valaxy/types/frontmatter'
|
|
1
2
|
import type { CollectionConfig } from '../client/types'
|
|
2
|
-
import type { PageFrontMatter, PostFrontMatter } from './frontmatter'
|
|
3
3
|
|
|
4
4
|
export type Page = Partial<PageFrontMatter>
|
|
5
5
|
export type Post = Partial<PostFrontMatter> & {
|