@sugarat/theme 0.1.13 → 0.1.14
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 +2 -22
- package/node.js +79 -62
- package/package.json +1 -1
- package/src/composables/config/blog.ts +4 -4
- package/src/composables/config/index.ts +1 -1
- package/src/node.ts +91 -64
package/node.d.ts
CHANGED
|
@@ -155,34 +155,14 @@ declare namespace Theme {
|
|
|
155
155
|
friend?: FriendLink[];
|
|
156
156
|
}
|
|
157
157
|
interface Config extends DefaultTheme.Config {
|
|
158
|
-
blog
|
|
158
|
+
blog?: BlogConfig;
|
|
159
159
|
}
|
|
160
160
|
interface HomeConfig {
|
|
161
161
|
handleChangeSlogan?: (oldSlogan: string) => string | Promise<string>;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
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
|
-
};
|
|
165
|
+
declare function getThemeConfig(cfg?: Partial<Theme.BlogConfig>): any;
|
|
186
166
|
declare function getDefaultTitle(content: string): string;
|
|
187
167
|
declare function clearMatterContent(content: string): string;
|
|
188
168
|
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,76 @@ function getThemeConfig(cfg) {
|
|
|
116
117
|
meta
|
|
117
118
|
};
|
|
118
119
|
}).filter((v) => v.meta.layout !== "home");
|
|
120
|
+
const extraConfig = {};
|
|
121
|
+
if (cfg?.search === "pagefind") {
|
|
122
|
+
checkKeys.push("head", "vite");
|
|
123
|
+
extraConfig.head = [
|
|
124
|
+
[
|
|
125
|
+
"script",
|
|
126
|
+
{},
|
|
127
|
+
`import('/_pagefind/pagefind.js')
|
|
128
|
+
.then((module) => {
|
|
129
|
+
window.__pagefind__ = module
|
|
130
|
+
})
|
|
131
|
+
.catch(() => {
|
|
132
|
+
console.log('not load /_pagefind/pagefind.js')
|
|
133
|
+
})`
|
|
134
|
+
]
|
|
135
|
+
];
|
|
136
|
+
let flag = true;
|
|
137
|
+
let originLog = null;
|
|
138
|
+
extraConfig.vite = {
|
|
139
|
+
plugins: [
|
|
140
|
+
{
|
|
141
|
+
name: "@sugarar/theme-plugin-pagefind",
|
|
142
|
+
buildEnd() {
|
|
143
|
+
const { log } = console;
|
|
144
|
+
if (flag) {
|
|
145
|
+
flag = false;
|
|
146
|
+
originLog = log;
|
|
147
|
+
Object.defineProperty(console, "log", {
|
|
148
|
+
value() {
|
|
149
|
+
if (`${arguments[0]}`.includes("build complete")) {
|
|
150
|
+
console.log = originLog;
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
originLog();
|
|
153
|
+
originLog("=== pagefind: https://pagefind.app/ ===");
|
|
154
|
+
const command = `npx pagefind --source ${import_path.default.join(
|
|
155
|
+
process.argv.slice(2)?.[1] || ".",
|
|
156
|
+
".vitepress/dist"
|
|
157
|
+
)}`;
|
|
158
|
+
originLog(command);
|
|
159
|
+
originLog();
|
|
160
|
+
(0, import_child_process.execSync)(command, {
|
|
161
|
+
stdio: "inherit"
|
|
162
|
+
});
|
|
163
|
+
}, 100);
|
|
164
|
+
}
|
|
165
|
+
return log.apply(this, arguments);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
119
174
|
return {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
175
|
+
themeConfig: {
|
|
176
|
+
blog: {
|
|
177
|
+
pagesData: data,
|
|
178
|
+
...cfg
|
|
179
|
+
},
|
|
180
|
+
...cfg?.blog !== false ? {
|
|
181
|
+
sidebar: [
|
|
182
|
+
{
|
|
183
|
+
text: "",
|
|
184
|
+
items: []
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
} : void 0
|
|
123
188
|
},
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
text: "",
|
|
127
|
-
items: []
|
|
128
|
-
}
|
|
129
|
-
]
|
|
189
|
+
...extraConfig
|
|
130
190
|
};
|
|
131
191
|
}
|
|
132
192
|
function getDefaultTitle(content) {
|
|
@@ -183,59 +243,16 @@ function getTextSummary(text, count = 100) {
|
|
|
183
243
|
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
244
|
}
|
|
185
245
|
function defineConfig(config) {
|
|
186
|
-
if (config?.themeConfig
|
|
187
|
-
config.
|
|
188
|
-
[
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
};
|
|
246
|
+
if (config.themeConfig?.themeConfig) {
|
|
247
|
+
config.extends = checkKeys.reduce((pre, key) => {
|
|
248
|
+
pre[key] = config.themeConfig[key];
|
|
249
|
+
delete config.themeConfig[key];
|
|
250
|
+
return pre;
|
|
251
|
+
}, {});
|
|
252
|
+
setTimeout(() => {
|
|
253
|
+
console.warn("==\u2193 \u4E3B\u9898\u914D\u7F6E\u65B9\u5F0F\u8FC7\u671F\uFF0C\u8BF7\u5C3D\u5FEB\u53C2\u7167\u6587\u6863\u66F4\u65B0 \u2193==");
|
|
254
|
+
console.warn("https://theme.sugarat.top/config/global.html");
|
|
255
|
+
}, 1200);
|
|
239
256
|
}
|
|
240
257
|
return config;
|
|
241
258
|
}
|
package/package.json
CHANGED
|
@@ -55,7 +55,7 @@ export function useBlogConfig() {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function useBlogThemeMode() {
|
|
58
|
-
return inject(configSymbol)!.value
|
|
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
|
|
66
|
+
return blogConfig.config?.blog?.comment
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export function useArticles() {
|
|
@@ -80,9 +80,9 @@ export function useCurrentArticle() {
|
|
|
80
80
|
const blogConfig = useConfig()
|
|
81
81
|
const route = useRoute()
|
|
82
82
|
|
|
83
|
-
const docs = computed(() => blogConfig.config
|
|
83
|
+
const docs = computed(() => blogConfig.config?.blog?.pagesData)
|
|
84
84
|
const currentArticle = computed(() =>
|
|
85
|
-
docs.value
|
|
85
|
+
docs.value?.find((v) => v.route === route.path.replace(/.html$/, ''))
|
|
86
86
|
)
|
|
87
87
|
|
|
88
88
|
return currentArticle
|
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,81 @@ 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 (cfg?.search === 'pagefind') {
|
|
90
|
+
checkKeys.push('head', 'vite')
|
|
91
|
+
extraConfig.head = [
|
|
92
|
+
[
|
|
93
|
+
'script',
|
|
94
|
+
{},
|
|
95
|
+
`import('/_pagefind/pagefind.js')
|
|
96
|
+
.then((module) => {
|
|
97
|
+
window.__pagefind__ = module
|
|
98
|
+
})
|
|
99
|
+
.catch(() => {
|
|
100
|
+
console.log('not load /_pagefind/pagefind.js')
|
|
101
|
+
})`
|
|
102
|
+
]
|
|
103
|
+
]
|
|
104
|
+
let flag = true
|
|
105
|
+
let originLog: any = null
|
|
106
|
+
extraConfig.vite = {
|
|
107
|
+
plugins: [
|
|
108
|
+
{
|
|
109
|
+
name: '@sugarar/theme-plugin-pagefind',
|
|
110
|
+
buildEnd() {
|
|
111
|
+
const { log } = console
|
|
112
|
+
// TODO: hack
|
|
113
|
+
if (flag) {
|
|
114
|
+
flag = false
|
|
115
|
+
originLog = log
|
|
116
|
+
Object.defineProperty(console, 'log', {
|
|
117
|
+
value() {
|
|
118
|
+
if (`${arguments[0]}`.includes('build complete')) {
|
|
119
|
+
console.log = originLog
|
|
120
|
+
setTimeout(() => {
|
|
121
|
+
originLog()
|
|
122
|
+
originLog('=== pagefind: https://pagefind.app/ ===')
|
|
123
|
+
const command = `npx pagefind --source ${path.join(
|
|
124
|
+
process.argv.slice(2)?.[1] || '.',
|
|
125
|
+
'.vitepress/dist'
|
|
126
|
+
)}`
|
|
127
|
+
originLog(command)
|
|
128
|
+
originLog()
|
|
129
|
+
execSync(command, {
|
|
130
|
+
stdio: 'inherit'
|
|
131
|
+
})
|
|
132
|
+
}, 100)
|
|
133
|
+
}
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
return log.apply(this, arguments)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
85
144
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
145
|
+
themeConfig: {
|
|
146
|
+
blog: {
|
|
147
|
+
pagesData: data as Theme.PageData[],
|
|
148
|
+
...cfg
|
|
149
|
+
},
|
|
150
|
+
...(cfg?.blog !== false
|
|
151
|
+
? {
|
|
152
|
+
sidebar: [
|
|
153
|
+
{
|
|
154
|
+
text: '',
|
|
155
|
+
items: []
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
: undefined)
|
|
89
160
|
},
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
text: '',
|
|
93
|
-
items: []
|
|
94
|
-
}
|
|
95
|
-
]
|
|
161
|
+
...extraConfig
|
|
96
162
|
}
|
|
97
163
|
}
|
|
98
164
|
|
|
@@ -189,61 +255,22 @@ function getTextSummary(text: string, count = 100) {
|
|
|
189
255
|
}
|
|
190
256
|
|
|
191
257
|
export function defineConfig(config: UserConfig<Theme.Config>) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
}
|
|
258
|
+
// 兼容低版本主题配置
|
|
259
|
+
// @ts-ignore
|
|
260
|
+
if (config.themeConfig?.themeConfig) {
|
|
261
|
+
config.extends = checkKeys.reduce((pre, key) => {
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
pre[key] = config.themeConfig[key]
|
|
264
|
+
// @ts-ignore
|
|
265
|
+
delete config.themeConfig[key]
|
|
266
|
+
return pre
|
|
267
|
+
}, {})
|
|
268
|
+
|
|
269
|
+
// 打印warn信息
|
|
270
|
+
setTimeout(() => {
|
|
271
|
+
console.warn('==↓ 主题配置方式过期,请尽快参照文档更新 ↓==')
|
|
272
|
+
console.warn('https://theme.sugarat.top/config/global.html')
|
|
273
|
+
}, 1200)
|
|
247
274
|
}
|
|
248
275
|
return config
|
|
249
276
|
}
|