@wot-ui/vitepress-theme 2.0.0-alpha.15 → 2.0.0-alpha.16

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/dist/index.d.ts CHANGED
@@ -6,9 +6,15 @@ import './theme/styles/vars.css';
6
6
  import './theme/styles/custom.css';
7
7
  declare global {
8
8
  interface Window {
9
+ /**
10
+ * 百度统计全局队列。
11
+ */
9
12
  _hmt: any[];
10
13
  }
11
14
  }
15
+ /**
16
+ * 创建 Wot VitePress 主题实例。
17
+ */
12
18
  export declare function createWotVitePressTheme(options?: WotVitePressThemeOptions): Theme;
13
19
  declare const theme: Theme;
14
20
  export default theme;
package/dist/index.js CHANGED
@@ -19,7 +19,8 @@ function resolveThemeOptions(options = {}) {
19
19
  team: options.team ?? false,
20
20
  friendly: options.friendly ?? false,
21
21
  cases: options.cases ?? false,
22
- demoIframe: options.demoIframe ?? false
22
+ demoIframe: options.demoIframe ?? false,
23
+ specialSponsor: options.specialSponsor ?? false
23
24
  };
24
25
  }
25
26
  function enhanceAppWithOptions(ctx, options) {
@@ -1,8 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
- import { useAdSponsor } from '../composables/adSponsor'
3
+ import { useSpecialSponsor } from '../composables/specialSponsor'
4
4
 
5
- const { data } = useAdSponsor()
5
+ const { data } = useSpecialSponsor()
6
6
 
7
7
  // 分离超级赞助和金牌赞助
8
8
  const superSponsors = computed(() => {
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
- import { useAdSponsor } from '../composables/adSponsor'
3
+ import { useSpecialSponsor } from '../composables/specialSponsor'
4
4
 
5
5
  interface Props {
6
6
  title?: string
@@ -10,7 +10,7 @@ withDefaults(defineProps<Props>(), {
10
10
  title: '铂金赞助商'
11
11
  })
12
12
 
13
- const { data } = useAdSponsor()
13
+ const { data } = useSpecialSponsor()
14
14
 
15
15
  // 获取第一个铂金赞助商
16
16
  const platinumSponsor = computed(() => {
@@ -79,9 +79,11 @@ const emit = defineEmits<{
79
79
 
80
80
  const route = useRoute()
81
81
  const vitepressData = useData()
82
+ const { frontmatter } = vitepressData
82
83
  const themeOptions = inject(wotThemeOptionsKey)
83
84
  const demoIframeOptions = themeOptions?.demoIframe
84
85
  const assetBase = demoIframeOptions && demoIframeOptions.assetBase ? demoIframeOptions.assetBase : '/wxqrcode'
86
+ const qrcodeEnabled = demoIframeOptions && demoIframeOptions.enabled !== false
85
87
 
86
88
  const href = computed(() => {
87
89
  const path = route.path
@@ -89,10 +91,21 @@ const href = computed(() => {
89
91
 
90
92
  if (!paths.length) return baseUrl.value
91
93
 
92
- return baseUrl.value + `subPages/${kebabToCamel(paths[paths.length - 1])}/Index`
94
+ const pageName = paths[paths.length - 1]
95
+ const iframeFormatter = frontmatter.value.iframeFormatter
96
+
97
+ if (typeof iframeFormatter === 'function') {
98
+ return baseUrl.value + iframeFormatter(pageName)
99
+ } else if (typeof iframeFormatter === 'string') {
100
+ return baseUrl.value + iframeFormatter.replace('{name}', pageName).replace('{camelName}', kebabToCamel(pageName))
101
+ }
102
+
103
+ return baseUrl.value + `subPages/${kebabToCamel(pageName)}/Index`
93
104
  })
94
105
 
95
106
  const qrcode = computed(() => {
107
+ if (!qrcodeEnabled) return ''
108
+
96
109
  const path = route.path
97
110
  const paths = path ? path.split('.')[0].split('/') : []
98
111
  if (!paths.length) return ''
@@ -13,16 +13,28 @@ function useCaseData() {
13
13
  const fetchData = async () => {
14
14
  for (const url of urls) {
15
15
  try {
16
- const path = "/cases.json";
17
- const response = await axios.get(url + path + "?t=" + Date.now(), {
16
+ const response = await axios.get(url + "?t=" + Date.now(), {
18
17
  timeout: 5e3
19
18
  // 设置5秒超时
20
19
  });
21
20
  const data2 = response.data && response.data.data ? response.data.data : [];
21
+ const getFullImageUrl = (image, baseUrl) => {
22
+ if (!image)
23
+ return "";
24
+ if (image.startsWith("http://") || image.startsWith("https://")) {
25
+ return image;
26
+ }
27
+ try {
28
+ const { origin } = new URL(baseUrl);
29
+ return origin + image;
30
+ } catch {
31
+ return baseUrl + image;
32
+ }
33
+ };
22
34
  return data2.map((item) => {
23
35
  return {
24
36
  name: item.name,
25
- image: item.image ? url + item.image : "",
37
+ image: getFullImageUrl(item.image, url),
26
38
  description: item.description
27
39
  };
28
40
  });
@@ -9,7 +9,7 @@ export interface Sponsors {
9
9
  size?: GridSize;
10
10
  items: Sponsor[];
11
11
  }
12
- export declare function useAdSponsor(): {
12
+ export declare function useSpecialSponsor(): {
13
13
  data: import("vue").Ref<{
14
14
  tier?: string;
15
15
  size?: GridSize;
@@ -1,9 +1,15 @@
1
- import { ref, onMounted } from "vue";
1
+ import { ref, onMounted, inject } from "vue";
2
2
  import axios from "axios";
3
+ import { wotThemeOptionsKey } from "../options.js";
3
4
  const data = ref([]);
4
- function useAdSponsor() {
5
+ function useSpecialSponsor() {
6
+ const options = inject(wotThemeOptionsKey);
5
7
  onMounted(async () => {
6
- const urls = ["https://sponsor.wot-ui.cn/sponsor.json", "https://wot-sponsors.pages.dev/sponsor.json"];
8
+ const sponsorOptions = options?.specialSponsor;
9
+ if (!sponsorOptions || data.value.length) {
10
+ return;
11
+ }
12
+ const urls = sponsorOptions.urls || [];
7
13
  const fetchData = async () => {
8
14
  for (const url of urls) {
9
15
  try {
@@ -25,5 +31,5 @@ function useAdSponsor() {
25
31
  };
26
32
  }
27
33
  export {
28
- useAdSponsor
34
+ useSpecialSponsor
29
35
  };
@@ -28,7 +28,7 @@ function useTeam() {
28
28
  const fetchData = async () => {
29
29
  for (const url of urls) {
30
30
  try {
31
- const response = await axios.get(url + "/team.json?t=" + Date.now(), {
31
+ const response = await axios.get(url + "?t=" + Date.now(), {
32
32
  timeout: 5e3
33
33
  });
34
34
  const members = response.data && response.data.members ? response.data.members : [];
package/dist/types.d.ts CHANGED
@@ -1,86 +1,296 @@
1
1
  import type { DefaultTheme, HeadConfig, UserConfig } from 'vitepress';
2
2
  import type { PluginOption } from 'vite';
3
+ /**
4
+ * 主题埋点配置。
5
+ */
3
6
  export interface WotThemeAnalyticsOptions {
7
+ /**
8
+ * 是否在路由切换后上报百度统计。
9
+ */
4
10
  trackBaiduRoute?: boolean;
5
11
  }
12
+ /**
13
+ * 顶部横幅配置。
14
+ */
6
15
  export interface WotThemeBannerOptions {
16
+ /**
17
+ * 横幅图片地址列表。
18
+ */
7
19
  urls: string[];
8
20
  }
21
+ /**
22
+ * 侧边赞助位配置。
23
+ */
9
24
  export interface WotThemeSponsorOptions {
25
+ /**
26
+ * 赞助图片地址列表。
27
+ */
10
28
  urls: string[];
11
29
  }
30
+ /**
31
+ * 广告位配置。
32
+ */
12
33
  export interface WotThemeAdsOptions {
34
+ /**
35
+ * WwAds 广告位 ID。
36
+ */
13
37
  wwadsId?: string;
38
+ /**
39
+ * 自定义广告素材地址列表。
40
+ */
14
41
  urls?: string[];
15
42
  }
43
+ /**
44
+ * 团队成员展示配置。
45
+ */
16
46
  export interface WotThemeTeamOptions {
47
+ /**
48
+ * 团队成员数据地址列表。
49
+ */
17
50
  urls: string[];
18
51
  }
52
+ /**
53
+ * 友情链接配置。
54
+ */
19
55
  export interface WotThemeFriendlyOptions {
56
+ /**
57
+ * 友情链接数据地址列表。
58
+ */
20
59
  urls: string[];
21
60
  }
61
+ /**
62
+ * 案例展示配置。
63
+ */
22
64
  export interface WotThemeCasesOptions {
65
+ /**
66
+ * 案例数据地址列表。
67
+ */
23
68
  urls: string[];
24
69
  }
70
+ /**
71
+ * Demo iframe 展示配置。
72
+ */
25
73
  export interface WotThemeDemoIframeOptions {
74
+ /**
75
+ * iframe 资源基础路径。
76
+ */
26
77
  assetBase?: string;
78
+ /**
79
+ * 是否启用二维码。
80
+ */
81
+ enabled?: boolean;
27
82
  }
83
+ /**
84
+ * 主题运行时可选能力配置。
85
+ */
28
86
  export interface WotVitePressThemeOptions {
87
+ /**
88
+ * 埋点能力配置,传入 false 表示关闭。
89
+ */
29
90
  analytics?: false | WotThemeAnalyticsOptions;
91
+ /**
92
+ * 顶部横幅配置,传入 false 表示关闭。
93
+ */
30
94
  banner?: false | WotThemeBannerOptions;
95
+ /**
96
+ * 赞助位配置,传入 false 表示关闭。
97
+ */
31
98
  sponsors?: false | WotThemeSponsorOptions;
99
+ /**
100
+ * 特别赞助位配置,传入 false 表示关闭。
101
+ */
102
+ specialSponsor?: false | WotThemeSponsorOptions;
103
+ /**
104
+ * 广告位配置,传入 false 表示关闭。
105
+ */
32
106
  ads?: false | WotThemeAdsOptions;
107
+ /**
108
+ * 团队成员模块配置,传入 false 表示关闭。
109
+ */
33
110
  team?: false | WotThemeTeamOptions;
111
+ /**
112
+ * 友情链接模块配置,传入 false 表示关闭。
113
+ */
34
114
  friendly?: false | WotThemeFriendlyOptions;
115
+ /**
116
+ * 案例模块配置,传入 false 表示关闭。
117
+ */
35
118
  cases?: false | WotThemeCasesOptions;
119
+ /**
120
+ * Demo iframe 配置,传入 false 表示关闭。
121
+ */
36
122
  demoIframe?: false | WotThemeDemoIframeOptions;
37
123
  }
124
+ /**
125
+ * LLM 文本导出功能配置。
126
+ */
38
127
  export interface WotLlmsFeatureOptions {
128
+ /**
129
+ * 生成的站点域名。
130
+ */
39
131
  domain: string;
132
+ /**
133
+ * 需要忽略的文档路径列表。
134
+ */
40
135
  ignoreFiles?: string[];
41
136
  }
137
+ /**
138
+ * Markdown 组件源码链接配置。
139
+ */
42
140
  export interface WotMdComponentLinksOptions {
141
+ /**
142
+ * 仓库源码地址前缀。
143
+ */
43
144
  repoUrl: string;
145
+ /**
146
+ * Demo 源码根目录。
147
+ */
44
148
  demoSourceRoot: string;
149
+ /**
150
+ * 组件源码根目录。
151
+ */
45
152
  componentSourceRoot: string;
46
153
  }
154
+ /**
155
+ * Markdown SCSS 变量文档生成配置。
156
+ */
47
157
  export interface WotMdScssVarsOptions {
158
+ /**
159
+ * 组件样式源码根目录。
160
+ */
48
161
  componentScssRoot: string;
162
+ /**
163
+ * 文档组件名到实际组件名的映射表。
164
+ */
49
165
  componentMap?: Record<string, string[]>;
50
166
  }
167
+ /**
168
+ * 虚拟版本数据插件配置。
169
+ */
51
170
  export interface WotVirtualVersionDataOptions {
171
+ /**
172
+ * 文档根目录。
173
+ */
52
174
  docsRoot?: string;
53
175
  }
176
+ /**
177
+ * Markdown 增强能力配置集合。
178
+ */
54
179
  export interface WotMarkdownSourceOptions {
180
+ /**
181
+ * 组件源码链接能力配置。
182
+ */
55
183
  componentLinks?: false | WotMdComponentLinksOptions;
184
+ /**
185
+ * SCSS 变量文档能力配置。
186
+ */
56
187
  scssVars?: false | WotMdScssVarsOptions;
188
+ /**
189
+ * 是否开启版本徽标。
190
+ */
57
191
  versionBadge?: boolean;
192
+ /**
193
+ * 虚拟版本数据能力配置。
194
+ */
58
195
  virtualVersionData?: false | WotVirtualVersionDataOptions;
59
196
  }
197
+ /**
198
+ * VitePress 额外特性配置集合。
199
+ */
60
200
  export interface WotVitePressFeatureOptions {
201
+ /**
202
+ * LLM 文本导出能力配置。
203
+ */
61
204
  llms?: false | WotLlmsFeatureOptions;
205
+ /**
206
+ * 静态资源压缩配置。
207
+ */
62
208
  compression?: false | Record<string, unknown>;
63
209
  }
210
+ /**
211
+ * 创建 Wot VitePress 配置时接收的顶层参数。
212
+ */
64
213
  export interface WotVitePressConfigOptions {
214
+ /**
215
+ * 站点标题。
216
+ */
65
217
  title: string;
218
+ /**
219
+ * 站点描述。
220
+ */
66
221
  description: string;
222
+ /**
223
+ * 额外 head 配置。
224
+ */
67
225
  head?: HeadConfig[];
226
+ /**
227
+ * 国际化语言包配置。
228
+ */
68
229
  locales?: UserConfig['locales'];
230
+ /**
231
+ * 默认主题配置。
232
+ */
69
233
  themeConfig?: DefaultTheme.Config;
234
+ /**
235
+ * 透传给 VitePress 的 Vite 配置。
236
+ */
70
237
  vite?: UserConfig['vite'];
238
+ /**
239
+ * Markdown 能力配置。
240
+ */
71
241
  markdown: WotMarkdownSourceOptions;
242
+ /**
243
+ * 额外特性配置。
244
+ */
72
245
  features?: WotVitePressFeatureOptions;
73
246
  }
247
+ /**
248
+ * 主题内部使用的归一化配置。
249
+ */
74
250
  export interface WotResolvedThemeOptions {
251
+ /**
252
+ * 埋点配置。
253
+ */
75
254
  analytics: {
255
+ /**
256
+ * 是否在路由切换后上报百度统计。
257
+ */
76
258
  trackBaiduRoute: boolean;
77
259
  };
260
+ /**
261
+ * 归一化后的横幅配置。
262
+ */
78
263
  banner: false | WotThemeBannerOptions;
264
+ /**
265
+ * 归一化后的赞助位配置。
266
+ */
79
267
  sponsors: false | WotThemeSponsorOptions;
268
+ /**
269
+ * 归一化后的广告位配置。
270
+ */
80
271
  ads: false | WotThemeAdsOptions;
272
+ /**
273
+ * 归一化后的团队配置。
274
+ */
81
275
  team: false | WotThemeTeamOptions;
276
+ /**
277
+ * 归一化后的友情链接配置。
278
+ */
82
279
  friendly: false | WotThemeFriendlyOptions;
280
+ /**
281
+ * 归一化后的案例配置。
282
+ */
83
283
  cases: false | WotThemeCasesOptions;
284
+ /**
285
+ * 归一化后的 Demo iframe 配置。
286
+ */
84
287
  demoIframe: false | WotThemeDemoIframeOptions;
288
+ /**
289
+ * 归一化后的特别赞助位配置。
290
+ */
291
+ specialSponsor: false | WotThemeSponsorOptions;
85
292
  }
293
+ /**
294
+ * 过滤空值后的有效 Vite 插件类型。
295
+ */
86
296
  export type WotVitePlugin = Exclude<PluginOption, null | false | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wot-ui/vitepress-theme",
3
- "version": "2.0.0-alpha.15",
3
+ "version": "2.0.0-alpha.16",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"