@sugarat/theme 0.1.13 → 0.1.15

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/node.d.ts CHANGED
@@ -132,6 +132,17 @@ declare namespace Theme {
132
132
  url: string;
133
133
  avatar: string;
134
134
  }
135
+ type SearchConfig = boolean | 'pagefind' | {
136
+ btnPlaceholder?: string;
137
+ placeholder?: string;
138
+ emptyText?: string;
139
+ /**
140
+ * @example
141
+ * 'Total: {{searchResult}} search results.'
142
+ */
143
+ heading?: string;
144
+ mode?: boolean | 'pagefind';
145
+ };
135
146
  interface BlogConfig {
136
147
  blog?: false;
137
148
  pagesData: PageData[];
@@ -139,7 +150,7 @@ declare namespace Theme {
139
150
  author?: string;
140
151
  hotArticle?: HotArticle;
141
152
  home?: HomeBlog;
142
- search?: boolean | 'pagefind';
153
+ search?: SearchConfig;
143
154
  /**
144
155
  * 配置评论
145
156
  * power by https://giscus.app/zh-CN
@@ -155,34 +166,14 @@ declare namespace Theme {
155
166
  friend?: FriendLink[];
156
167
  }
157
168
  interface Config extends DefaultTheme.Config {
158
- blog: BlogConfig;
169
+ blog?: BlogConfig;
159
170
  }
160
171
  interface HomeConfig {
161
172
  handleChangeSlogan?: (oldSlogan: string) => string | Promise<string>;
162
173
  }
163
174
  }
164
175
 
165
- declare function getThemeConfig(cfg?: Partial<Theme.BlogConfig>): {
166
- blog: {
167
- blog?: false | undefined;
168
- pagesData: Theme.PageData[];
169
- srcDir?: string | undefined;
170
- author?: string | undefined;
171
- hotArticle?: Theme.HotArticle | undefined;
172
- home?: Theme.HomeBlog | undefined;
173
- search?: boolean | "pagefind" | undefined;
174
- comment?: false | Theme.GiscusConfig | undefined;
175
- recommend?: Theme.RecommendArticle | undefined;
176
- article?: Theme.ArticleConfig | undefined;
177
- alert?: Theme.Alert | undefined;
178
- popover?: Theme.Popover | undefined;
179
- friend?: Theme.FriendLink[] | undefined;
180
- };
181
- sidebar: {
182
- text: string;
183
- items: never[];
184
- }[];
185
- };
176
+ declare function getThemeConfig(cfg?: Partial<Theme.BlogConfig>): any;
186
177
  declare function getDefaultTitle(content: string): string;
187
178
  declare function clearMatterContent(content: string): string;
188
179
  declare function getFileBirthTime(url: string): string;
package/node.js CHANGED
@@ -71,6 +71,7 @@ function formatDate(d, fmt = "yyyy-MM-dd hh:mm:ss") {
71
71
  }
72
72
 
73
73
  // src/node.ts
74
+ var checkKeys = ["themeConfig"];
74
75
  function getThemeConfig(cfg) {
75
76
  const srcDir = cfg?.srcDir || process.argv.slice(2)?.[1] || ".";
76
77
  const files = import_fast_glob.default.sync(`${srcDir}/**/*.md`, { ignore: ["node_modules"] });
@@ -116,17 +117,73 @@ function getThemeConfig(cfg) {
116
117
  meta
117
118
  };
118
119
  }).filter((v) => v.meta.layout !== "home");
120
+ const extraConfig = {};
121
+ if (cfg?.search === "pagefind" || cfg?.search instanceof Object && cfg.search.mode === "pagefind") {
122
+ checkKeys.push("vite");
123
+ let flag = true;
124
+ let originLog = null;
125
+ extraConfig.vite = {
126
+ plugins: [
127
+ {
128
+ name: "@sugarar/theme-plugin-pagefind",
129
+ enforce: "pre",
130
+ buildEnd() {
131
+ const { log } = console;
132
+ if (flag) {
133
+ flag = false;
134
+ originLog = log;
135
+ Object.defineProperty(console, "log", {
136
+ value() {
137
+ if (`${arguments[0]}`.includes("build complete")) {
138
+ console.log = originLog;
139
+ setTimeout(() => {
140
+ originLog();
141
+ originLog("=== pagefind: https://pagefind.app/ ===");
142
+ const command = `npx pagefind --source ${import_path.default.join(
143
+ process.argv.slice(2)?.[1] || ".",
144
+ ".vitepress/dist"
145
+ )}`;
146
+ originLog(command);
147
+ originLog();
148
+ (0, import_child_process.execSync)(command, {
149
+ stdio: "inherit"
150
+ });
151
+ }, 100);
152
+ }
153
+ return log.apply(this, arguments);
154
+ }
155
+ });
156
+ }
157
+ },
158
+ transform(code, id) {
159
+ if (id.endsWith("theme-default/Layout.vue")) {
160
+ return code.replace(
161
+ "<VPContent>",
162
+ "<VPContent data-pagefind-body>"
163
+ );
164
+ }
165
+ return code;
166
+ }
167
+ }
168
+ ]
169
+ };
170
+ }
119
171
  return {
120
- blog: {
121
- pagesData: data,
122
- ...cfg
172
+ themeConfig: {
173
+ blog: {
174
+ pagesData: data,
175
+ ...cfg
176
+ },
177
+ ...cfg?.blog !== false ? {
178
+ sidebar: [
179
+ {
180
+ text: "",
181
+ items: []
182
+ }
183
+ ]
184
+ } : void 0
123
185
  },
124
- sidebar: [
125
- {
126
- text: "",
127
- items: []
128
- }
129
- ]
186
+ ...extraConfig
130
187
  };
131
188
  }
132
189
  function getDefaultTitle(content) {
@@ -183,59 +240,16 @@ function getTextSummary(text, count = 100) {
183
240
  return clearMatterContent(text).match(/^# ([\s\S]+)/m)?.[1]?.replace(/#/g, "")?.replace(/!\[.*?\]\(.*?\)/g, "")?.replace(/\[(.*?)\]\(.*?\)/g, "$1")?.replace(/\*\*(.*?)\*\*/g, "$1")?.split("\n")?.filter((v) => !!v)?.slice(1)?.join("\n")?.replace(/>(.*)/, "")?.slice(0, count);
184
241
  }
185
242
  function defineConfig(config) {
186
- if (config?.themeConfig?.blog?.search === "pagefind") {
187
- config.head = (config.head || []).concat([
188
- [
189
- "script",
190
- {},
191
- `import('/_pagefind/pagefind.js')
192
- .then((module) => {
193
- window.__pagefind__ = module
194
- })
195
- .catch(() => {
196
- console.log('not load /_pagefind/pagefind.js')
197
- })`
198
- ]
199
- ]);
200
- let flag = true;
201
- let originLog = null;
202
- config.vite = {
203
- ...config.vite,
204
- plugins: [
205
- ...config.vite?.plugins || [],
206
- {
207
- name: "@sugarar/theme-plugin-pagefind",
208
- buildEnd() {
209
- const { log } = console;
210
- if (flag) {
211
- flag = false;
212
- originLog = log;
213
- Object.defineProperty(console, "log", {
214
- value() {
215
- if (`${arguments[0]}`.includes("build complete")) {
216
- console.log = originLog;
217
- setTimeout(() => {
218
- originLog();
219
- originLog("=== pagefind: https://pagefind.app/ ===");
220
- const command = `npx pagefind --source ${import_path.default.join(
221
- process.argv.slice(2)?.[1] || ".",
222
- ".vitepress/dist"
223
- )}`;
224
- originLog(command);
225
- originLog();
226
- (0, import_child_process.execSync)(command, {
227
- stdio: "inherit"
228
- });
229
- }, 100);
230
- }
231
- return log.apply(this, arguments);
232
- }
233
- });
234
- }
235
- }
236
- }
237
- ]
238
- };
243
+ if (config.themeConfig?.themeConfig) {
244
+ config.extends = checkKeys.reduce((pre, key) => {
245
+ pre[key] = config.themeConfig[key];
246
+ delete config.themeConfig[key];
247
+ return pre;
248
+ }, {});
249
+ setTimeout(() => {
250
+ console.warn("==\u2193 \u4E3B\u9898\u914D\u7F6E\u65B9\u5F0F\u8FC7\u671F\uFF0C\u8BF7\u5C3D\u5FEB\u53C2\u7167\u6587\u6863\u66F4\u65B0 \u2193==");
251
+ console.warn("https://theme.sugarat.top/config/global.html");
252
+ }, 1200);
239
253
  }
240
254
  return config;
241
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -17,7 +17,7 @@ const { Layout } = Theme
17
17
  </script>
18
18
 
19
19
  <template>
20
- <Layout data-pagefind-body>
20
+ <Layout>
21
21
  <template #layout-top>
22
22
  <BlogAlert />
23
23
  <BlogPopover />
@@ -104,7 +104,7 @@ const publishDate = computed(() => {
104
104
  })
105
105
 
106
106
  const { theme } = useData<Theme.Config>()
107
- const globalAuthor = computed(() => theme.value.blog.author || '')
107
+ const globalAuthor = computed(() => theme.value.blog?.author || '')
108
108
  const author = computed(
109
109
  () => currentArticle.value?.meta.author || globalAuthor.value
110
110
  )
@@ -11,28 +11,27 @@
11
11
  stroke-linejoin="round"
12
12
  ></path>
13
13
  </svg>
14
- <span class="search-tip">搜索</span>
15
- <span class="metaKey"> ⌘ K </span>
14
+ <span v-if="!isMinimized" class="search-tip">{{
15
+ searchConfig?.btnPlaceholder || '搜索'
16
+ }}</span>
17
+ <span v-if="!isMinimized" class="metaKey"> {{ metaKey }} K </span>
16
18
  </div>
17
19
  <Command.Dialog :visible="searchModal" theme="algolia">
18
20
  <template #header>
19
21
  <Command.Input
20
22
  v-model:value="searchWords"
21
- placeholder="请输入要搜索的内容"
23
+ :placeholder="searchConfig?.placeholder || '请输入要搜素的内容'"
22
24
  />
23
25
  </template>
24
26
  <template #body>
25
27
  <div class="search-dialog">
26
28
  <Command.List>
27
- <Command.Empty v-if="!searchResult.length"
28
- >No results found.</Command.Empty
29
- >
30
- <Command.Group
31
- v-else
32
- :heading="`共:${searchResult.length} 个搜索结果`"
33
- >
29
+ <Command.Empty v-if="!searchResult.length">{{
30
+ searchConfig?.emptyText || 'No results found.'
31
+ }}</Command.Empty>
32
+ <Command.Group v-else :heading="headingText">
34
33
  <Command.Item
35
- v-for="item in showSearchResult"
34
+ v-for="item in searchResult"
36
35
  :data-value="withBase(item.route)"
37
36
  :key="item.route"
38
37
  @select="handleSelect"
@@ -128,27 +127,76 @@
128
127
  </template>
129
128
 
130
129
  <script lang="ts" setup>
131
- import { computed, nextTick, ref, watch } from 'vue'
132
- // @ts-ignore
130
+ // @ts-nocheck
131
+ import { computed, nextTick, ref, watch, onBeforeMount, onMounted } from 'vue'
133
132
  import { Command } from 'vue-command-palette'
134
133
  import { useRoute, useRouter, withBase } from 'vitepress'
135
- import { useMagicKeys } from '@vueuse/core'
134
+ import { useMagicKeys, useWindowSize } from '@vueuse/core'
136
135
  import { formatDate } from '../utils'
137
136
  import { useArticles, useBlogConfig } from '../composables/config/blog'
138
137
  import { Theme } from '../composables/config'
139
138
  import LogoPagefind from './LogoPagefind.vue'
140
139
 
141
- const { search: openSearch = true } = useBlogConfig()
140
+ const windowSize = useWindowSize()
142
141
 
142
+ const isMinimized = computed(() => windowSize.width.value < 760)
143
+ const flexValue = computed(() => (isMinimized.value ? 0 : 1))
144
+ const { search: searchConfig } = useBlogConfig()
145
+
146
+ const headingText = computed(() => {
147
+ return searchConfig?.heading
148
+ ? searchConfig.heading.replace(
149
+ /\{\{searchResult\}\}/,
150
+ searchResult.value.length
151
+ )
152
+ : `共: ${searchResult.value.length} 个搜索结果`
153
+ })
154
+ const openSearch = computed(() =>
155
+ searchConfig instanceof Object
156
+ ? searchConfig.mode ?? true
157
+ : searchConfig || true
158
+ )
159
+
160
+ const addInlineScript = () => {
161
+ const scriptText = `import('/_pagefind/pagefind.js')
162
+ .then((module) => {
163
+ window.__pagefind__ = module
164
+ })
165
+ .catch(() => {
166
+ console.log('not load /_pagefind/pagefind.js')
167
+ })`
168
+ const inlineScript = document.createElement('script')
169
+ inlineScript.innerHTML = scriptText
170
+ document.head.appendChild(inlineScript)
171
+ }
172
+
173
+ onBeforeMount(() => {
174
+ if (openSearch.value === 'pagefind') {
175
+ addInlineScript()
176
+ }
177
+ })
178
+
179
+ const metaKey = ref('')
180
+ onMounted(() => {
181
+ metaKey.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator?.platform)
182
+ ? '⌘'
183
+ : 'Ctrl'
184
+ })
143
185
  const searchModal = ref(false)
144
186
  const searchWords = ref('')
145
187
  const docs = useArticles()
146
188
 
147
189
  const keys = useMagicKeys()
148
190
  const CmdK = keys['Meta+K']
191
+ const CtrlK = keys['Ctrl+K']
149
192
  // eslint-disable-next-line dot-notation, prefer-destructuring
150
193
  const Escape = keys['Escape']
151
194
 
195
+ watch(CtrlK, (v) => {
196
+ if (v) {
197
+ searchModal.value = true
198
+ }
199
+ })
152
200
  watch(CmdK, (v) => {
153
201
  if (v) {
154
202
  searchModal.value = true
@@ -191,7 +239,7 @@ const inlineSearch = () => {
191
239
  watch(
192
240
  () => searchWords.value,
193
241
  async () => {
194
- if (openSearch === 'pagefind') {
242
+ if (openSearch.value === 'pagefind') {
195
243
  // dev-server兜底
196
244
  // @ts-ignore
197
245
  if (!window?.__pagefind__?.search) {
@@ -252,15 +300,17 @@ watch(
252
300
  }
253
301
  }
254
302
  )
255
- const pageSize = ref(6)
256
- const currentPage = ref(0)
257
- const showSearchResult = computed(() => {
258
- // 合法性处理
259
- const pageIdx =
260
- currentPage.value % Math.ceil(searchResult.value.length / pageSize.value)
261
- const startIdx = pageIdx * pageSize.value
262
- return searchResult.value.slice(startIdx, startIdx + pageSize.value)
263
- })
303
+
304
+ // 搜索结果分页?
305
+ // const pageSize = ref(6)
306
+ // const currentPage = ref(0)
307
+ // const showSearchResult = computed(() => {
308
+ // // 合法性处理
309
+ // const pageIdx =
310
+ // currentPage.value % Math.ceil(searchResult.value.length / pageSize.value)
311
+ // const startIdx = pageIdx * pageSize.value
312
+ // return searchResult.value.slice(startIdx, startIdx + pageSize.value)
313
+ // })
264
314
 
265
315
  const router = useRouter()
266
316
  const route = useRoute()
@@ -275,8 +325,9 @@ const handleSelect = (target: any) => {
275
325
 
276
326
  <style lang="scss" scoped>
277
327
  .blog-search {
278
- flex: 1;
279
- margin-left: 10px;
328
+ flex: v-bind(flexValue);
329
+ display: flex;
330
+ padding-left: 32px;
280
331
  .nav-search-btn-wait {
281
332
  cursor: pointer;
282
333
  display: flex;
@@ -284,7 +335,6 @@ const handleSelect = (target: any) => {
284
335
  justify-content: center;
285
336
  padding: 6px;
286
337
  box-sizing: border-box;
287
- width: 120px;
288
338
 
289
339
  .metaKey {
290
340
  margin-left: 10px;
@@ -292,7 +342,7 @@ const handleSelect = (target: any) => {
292
342
  }
293
343
 
294
344
  &:hover {
295
- border: 1px solid #409eff;
345
+ border: 1px solid var(--vp-c-brand);
296
346
  border-radius: 6px;
297
347
  }
298
348
 
@@ -51,11 +51,11 @@ export function useConfig() {
51
51
  }
52
52
 
53
53
  export function useBlogConfig() {
54
- return inject(configSymbol)!.value.blog
54
+ return inject(configSymbol)!.value.blog!
55
55
  }
56
56
 
57
57
  export function useBlogThemeMode() {
58
- return inject(configSymbol)!.value.blog.blog ?? true
58
+ return inject(configSymbol)!.value?.blog?.blog ?? true
59
59
  }
60
60
  export function useHomeConfig() {
61
61
  return inject(homeConfigSymbol)!
@@ -63,7 +63,7 @@ export function useHomeConfig() {
63
63
 
64
64
  export function useGiscusConfig() {
65
65
  const blogConfig = useConfig()
66
- return blogConfig.config.blog.comment
66
+ return blogConfig.config?.blog?.comment
67
67
  }
68
68
 
69
69
  export function useArticles() {
@@ -80,10 +80,14 @@ export function useCurrentArticle() {
80
80
  const blogConfig = useConfig()
81
81
  const route = useRoute()
82
82
 
83
- const docs = computed(() => blogConfig.config.blog.pagesData)
84
- const currentArticle = computed(() =>
85
- docs.value.find((v) => v.route === route.path.replace(/.html$/, ''))
86
- )
83
+ const docs = computed(() => blogConfig.config?.blog?.pagesData)
84
+ const currentArticle = computed(() => {
85
+ const currentPath = route.path.replace(/.html$/, '')
86
+ return docs.value?.find((v) =>
87
+ // 兼容中文路径
88
+ [currentPath, decodeURIComponent(currentPath)].includes(v.route)
89
+ )
90
+ })
87
91
 
88
92
  return currentArticle
89
93
  }
@@ -144,6 +144,21 @@ export namespace Theme {
144
144
  url: string
145
145
  avatar: string
146
146
  }
147
+ export type SearchConfig =
148
+ | boolean
149
+ | 'pagefind'
150
+ | {
151
+ btnPlaceholder?: string
152
+ placeholder?: string
153
+ emptyText?: string
154
+ /**
155
+ * @example
156
+ * 'Total: {{searchResult}} search results.'
157
+ */
158
+ heading?: string
159
+ mode?: boolean | 'pagefind'
160
+ }
161
+
147
162
  export interface BlogConfig {
148
163
  blog?: false
149
164
  pagesData: PageData[]
@@ -151,8 +166,8 @@ export namespace Theme {
151
166
  author?: string
152
167
  hotArticle?: HotArticle
153
168
  home?: HomeBlog
154
- // TODO: 本地全文搜索定制 pagefind || minisearch
155
- search?: boolean | 'pagefind'
169
+ // TODO: 本地全文搜索定制 pagefind || minisearch || flexsearch
170
+ search?: SearchConfig
156
171
  /**
157
172
  * 配置评论
158
173
  * power by https://giscus.app/zh-CN
@@ -169,7 +184,7 @@ export namespace Theme {
169
184
  }
170
185
 
171
186
  export interface Config extends DefaultTheme.Config {
172
- blog: BlogConfig
187
+ blog?: BlogConfig
173
188
  }
174
189
  export interface HomeConfig {
175
190
  handleChangeSlogan?: (oldSlogan: string) => string | Promise<string>
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export const BlogTheme: Theme = {
17
17
  ...DefaultTheme,
18
18
  Layout: withConfigProvider(BlogApp),
19
19
  enhanceApp(ctx) {
20
+ // TODO: 优化到自定义组件中注册
20
21
  ctx.app.component('TimelinePage', TimelinePage)
21
22
  }
22
23
  }
package/src/node.ts CHANGED
@@ -8,6 +8,8 @@ import type { UserConfig } from 'vitepress'
8
8
  import { formatDate } from './utils/index'
9
9
  import type { Theme } from './composables/config/index'
10
10
 
11
+ const checkKeys = ['themeConfig']
12
+
11
13
  export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
12
14
  const srcDir = cfg?.srcDir || process.argv.slice(2)?.[1] || '.'
13
15
  const files = glob.sync(`${srcDir}/**/*.md`, { ignore: ['node_modules'] })
@@ -82,17 +84,82 @@ export function getThemeConfig(cfg?: Partial<Theme.BlogConfig>) {
82
84
  })
83
85
  .filter((v) => v.meta.layout !== 'home')
84
86
 
87
+ const extraConfig: any = {}
88
+
89
+ if (
90
+ cfg?.search === 'pagefind' ||
91
+ (cfg?.search instanceof Object && cfg.search.mode === 'pagefind')
92
+ ) {
93
+ checkKeys.push('vite')
94
+ let flag = true
95
+ let originLog: any = null
96
+ extraConfig.vite = {
97
+ plugins: [
98
+ {
99
+ name: '@sugarar/theme-plugin-pagefind',
100
+ enforce: 'pre',
101
+ buildEnd() {
102
+ const { log } = console
103
+ // TODO: hack
104
+ if (flag) {
105
+ flag = false
106
+ originLog = log
107
+ Object.defineProperty(console, 'log', {
108
+ value() {
109
+ if (`${arguments[0]}`.includes('build complete')) {
110
+ console.log = originLog
111
+ setTimeout(() => {
112
+ originLog()
113
+ originLog('=== pagefind: https://pagefind.app/ ===')
114
+ const command = `npx pagefind --source ${path.join(
115
+ process.argv.slice(2)?.[1] || '.',
116
+ '.vitepress/dist'
117
+ )}`
118
+ originLog(command)
119
+ originLog()
120
+ execSync(command, {
121
+ stdio: 'inherit'
122
+ })
123
+ }, 100)
124
+ }
125
+ // @ts-ignore
126
+ return log.apply(this, arguments)
127
+ }
128
+ })
129
+ }
130
+ },
131
+ // 添加检索的内容标识
132
+ transform(code: string, id: string) {
133
+ if (id.endsWith('theme-default/Layout.vue')) {
134
+ return code.replace(
135
+ '<VPContent>',
136
+ '<VPContent data-pagefind-body>'
137
+ )
138
+ }
139
+ return code
140
+ }
141
+ }
142
+ ]
143
+ }
144
+ }
85
145
  return {
86
- blog: {
87
- pagesData: data as Theme.PageData[],
88
- ...cfg
146
+ themeConfig: {
147
+ blog: {
148
+ pagesData: data as Theme.PageData[],
149
+ ...cfg
150
+ },
151
+ ...(cfg?.blog !== false
152
+ ? {
153
+ sidebar: [
154
+ {
155
+ text: '',
156
+ items: []
157
+ }
158
+ ]
159
+ }
160
+ : undefined)
89
161
  },
90
- sidebar: [
91
- {
92
- text: '',
93
- items: []
94
- }
95
- ]
162
+ ...extraConfig
96
163
  }
97
164
  }
98
165
 
@@ -189,61 +256,22 @@ function getTextSummary(text: string, count = 100) {
189
256
  }
190
257
 
191
258
  export function defineConfig(config: UserConfig<Theme.Config>) {
192
- if (config?.themeConfig?.blog?.search === 'pagefind') {
193
- config.head = (config.head || []).concat([
194
- [
195
- 'script',
196
- {},
197
- `import('/_pagefind/pagefind.js')
198
- .then((module) => {
199
- window.__pagefind__ = module
200
- })
201
- .catch(() => {
202
- console.log('not load /_pagefind/pagefind.js')
203
- })`
204
- ]
205
- ])
206
- let flag = true
207
- let originLog: any = null
208
- config.vite = {
209
- ...config.vite,
210
- plugins: [
211
- ...(config.vite?.plugins || []),
212
- {
213
- name: '@sugarar/theme-plugin-pagefind',
214
- buildEnd() {
215
- const { log } = console
216
- // TODO: hack
217
- if (flag) {
218
- flag = false
219
- originLog = log
220
- Object.defineProperty(console, 'log', {
221
- value() {
222
- if (`${arguments[0]}`.includes('build complete')) {
223
- console.log = originLog
224
- setTimeout(() => {
225
- originLog()
226
- originLog('=== pagefind: https://pagefind.app/ ===')
227
- const command = `npx pagefind --source ${path.join(
228
- process.argv.slice(2)?.[1] || '.',
229
- '.vitepress/dist'
230
- )}`
231
- originLog(command)
232
- originLog()
233
- execSync(command, {
234
- stdio: 'inherit'
235
- })
236
- }, 100)
237
- }
238
- // @ts-ignore
239
- return log.apply(this, arguments)
240
- }
241
- })
242
- }
243
- }
244
- }
245
- ]
246
- }
259
+ // 兼容低版本主题配置
260
+ // @ts-ignore
261
+ if (config.themeConfig?.themeConfig) {
262
+ config.extends = checkKeys.reduce((pre, key) => {
263
+ // @ts-ignore
264
+ pre[key] = config.themeConfig[key]
265
+ // @ts-ignore
266
+ delete config.themeConfig[key]
267
+ return pre
268
+ }, {})
269
+
270
+ // 打印warn信息
271
+ setTimeout(() => {
272
+ console.warn('==↓ 主题配置方式过期,请尽快参照文档更新 ↓==')
273
+ console.warn('https://theme.sugarat.top/config/global.html')
274
+ }, 1200)
247
275
  }
248
276
  return config
249
277
  }
@@ -39,7 +39,7 @@ export function isCurrentWeek(date: Date, target?: Date) {
39
39
  }
40
40
 
41
41
  export function formatShowDate(date: Date | string) {
42
- const source = +new Date(date)
42
+ const source = date ? +new Date(date) : +new Date()
43
43
  const now = +new Date()
44
44
  const diff = now - source
45
45
  const oneSeconds = 1000