@sugarat/theme 0.4.11 → 0.4.12
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.js +4 -3
- package/package.json +1 -1
- package/src/utils/node/theme.ts +12 -11
package/node.js
CHANGED
|
@@ -398,7 +398,8 @@ async function getArticleMeta(filepath, route, timeZone = defaultTimeZoneOffset)
|
|
|
398
398
|
if (!meta.title) {
|
|
399
399
|
meta.title = (0, import_theme_shared2.getDefaultTitle)(content);
|
|
400
400
|
}
|
|
401
|
-
const
|
|
401
|
+
const utcValue = timeZone >= 0 ? `+${timeZone}` : `${timeZone}`;
|
|
402
|
+
const date = await (meta.date && /* @__PURE__ */ new Date(`${new Date(meta.date).toUTCString()}${utcValue}`) || (0, import_theme_shared2.getFileLastModifyTime)(filepath));
|
|
402
403
|
meta.date = formatDate(date || /* @__PURE__ */ new Date());
|
|
403
404
|
meta.categories = typeof meta.categories === "string" ? [meta.categories] : meta.categories;
|
|
404
405
|
meta.tags = typeof meta.tags === "string" ? [meta.tags] : meta.tags;
|
|
@@ -444,8 +445,8 @@ function patchVPConfig(vpConfig, cfg) {
|
|
|
444
445
|
if (cfg?.comment && "type" in cfg.comment && cfg?.comment?.type === "artalk") {
|
|
445
446
|
const server = cfg.comment?.options?.server;
|
|
446
447
|
if (server) {
|
|
447
|
-
vpConfig.head.push(["link", { href: `${server}/dist/Artalk.css`, rel: "stylesheet" }]);
|
|
448
|
-
vpConfig.head.push(["script", { src: `${server}/dist/Artalk.js`, id: "artalk-script" }]);
|
|
448
|
+
vpConfig.head.push(["link", { href: `${server} /dist/Artalk.css`, rel: "stylesheet" }]);
|
|
449
|
+
vpConfig.head.push(["script", { src: `${server} /dist/Artalk.js`, id: "artalk-script" }]);
|
|
449
450
|
}
|
|
450
451
|
}
|
|
451
452
|
}
|
package/package.json
CHANGED
package/src/utils/node/theme.ts
CHANGED
|
@@ -43,17 +43,18 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
|
|
|
43
43
|
if (!meta.title) {
|
|
44
44
|
meta.title = getDefaultTitle(content)
|
|
45
45
|
}
|
|
46
|
+
const utcValue = timeZone >= 0 ? `+${timeZone}` : `${timeZone}`
|
|
46
47
|
const date = await (
|
|
47
48
|
(meta.date
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
&& new Date(`${new Date(meta.date).toUTCString()}${utcValue}`))
|
|
50
|
+
|| getFileLastModifyTime(filepath)
|
|
50
51
|
)
|
|
51
52
|
// 无法获取时兜底当前时间
|
|
52
53
|
meta.date = formatDate(date || new Date())
|
|
53
54
|
|
|
54
55
|
// 处理tags和categories,兼容历史文章
|
|
55
56
|
meta.categories
|
|
56
|
-
|
|
57
|
+
= typeof meta.categories === 'string'
|
|
57
58
|
? [meta.categories]
|
|
58
59
|
: meta.categories
|
|
59
60
|
meta.tags = typeof meta.tags === 'string' ? [meta.tags] : meta.tags
|
|
@@ -66,12 +67,12 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
|
|
|
66
67
|
// 获取摘要信息
|
|
67
68
|
// TODO:摘要生成优化
|
|
68
69
|
meta.description
|
|
69
|
-
|
|
70
|
+
= meta.description || getTextSummary(content, 100) || excerpt
|
|
70
71
|
|
|
71
72
|
// 获取封面图
|
|
72
73
|
meta.cover
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
= meta.cover
|
|
75
|
+
?? (getFirstImagURLFromMD(fileContent, route))
|
|
75
76
|
|
|
76
77
|
// 是否发布 默认发布
|
|
77
78
|
if (meta.publish === false) {
|
|
@@ -82,9 +83,9 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
|
|
|
82
83
|
}
|
|
83
84
|
export async function getArticles(cfg: Partial<Theme.BlogConfig>, vpConfig: SiteConfig) {
|
|
84
85
|
const srcDir
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
= cfg?.srcDir || vpConfig.srcDir.replace(vpConfig.root, '').replace(/^\//, '')
|
|
87
|
+
|| process.argv.slice(2)?.[1]
|
|
88
|
+
|| '.'
|
|
88
89
|
const files = glob.sync(`${srcDir}/**/*.md`, { ignore: ['node_modules'], absolute: true })
|
|
89
90
|
|
|
90
91
|
const metaResults = files.reduce((prev, curr) => {
|
|
@@ -124,8 +125,8 @@ export function patchVPConfig(vpConfig: any, cfg?: Partial<Theme.BlogConfig>) {
|
|
|
124
125
|
if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
|
|
125
126
|
const server = cfg.comment?.options?.server
|
|
126
127
|
if (server) {
|
|
127
|
-
vpConfig.head.push(['link', { href: `${server}/dist/Artalk.css`, rel: 'stylesheet' }])
|
|
128
|
-
vpConfig.head.push(['script', { src: `${server}/dist/Artalk.js`, id: 'artalk-script' }])
|
|
128
|
+
vpConfig.head.push(['link', { href: `${server} /dist/Artalk.css`, rel: 'stylesheet' }])
|
|
129
|
+
vpConfig.head.push(['script', { src: `${server} /dist/Artalk.js`, id: 'artalk-script' }])
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
}
|