vitepress-velonor 0.1.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/README.md +9 -0
- package/dist/chunk-BCwAaXi7.cjs +31 -0
- package/dist/client.cjs +261 -0
- package/dist/client.d.cts +72 -0
- package/dist/client.d.ts +72 -0
- package/dist/client.js +249 -0
- package/dist/constants-CnBvTOWr.cjs +83 -0
- package/dist/constants-Dc4Co5gF.js +52 -0
- package/dist/date-BySfVUhd.d.ts +67 -0
- package/dist/date-CCP55OAZ.d.cts +67 -0
- package/dist/date-DAUKykKr.js +21 -0
- package/dist/date-ygOc7hIU.cjs +34 -0
- package/dist/index-B6RX4u89.d.cts +7 -0
- package/dist/index-hfvJJTlf.d.ts +7 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/loader.cjs +145 -0
- package/dist/loader.d.cts +73 -0
- package/dist/loader.d.ts +73 -0
- package/dist/loader.js +139 -0
- package/dist/post-helpers-BygKdsMh.cjs +42 -0
- package/dist/post-helpers-C_A-ioOF.js +36 -0
- package/package.json +45 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
const DEFAULT_PAGE_SIZE = 5;
|
|
5
|
+
const DEFAULT_PAGE_GROUP_SIZE = 5;
|
|
6
|
+
const MAX_DISPLAYED_TAGS = 20;
|
|
7
|
+
const LOCALIZED_STRINGS = {
|
|
8
|
+
"zh-CN": {
|
|
9
|
+
prev: "上一页",
|
|
10
|
+
next: "下一页",
|
|
11
|
+
all: "全部",
|
|
12
|
+
posts: "文章",
|
|
13
|
+
tags: "标签",
|
|
14
|
+
category: "分类",
|
|
15
|
+
other: "其他",
|
|
16
|
+
archive: "归档",
|
|
17
|
+
more: "更多",
|
|
18
|
+
backToBlog: "博客首页",
|
|
19
|
+
details: "详情",
|
|
20
|
+
activity: "更新状态",
|
|
21
|
+
switchToNormalPage: "切换到普通页面",
|
|
22
|
+
switchToPostPage: "切换到文章页面"
|
|
23
|
+
},
|
|
24
|
+
en: {
|
|
25
|
+
prev: "Prev",
|
|
26
|
+
next: "Next",
|
|
27
|
+
all: "All",
|
|
28
|
+
posts: "POSTS",
|
|
29
|
+
tags: "TAGS",
|
|
30
|
+
category: "Category",
|
|
31
|
+
other: "Other",
|
|
32
|
+
archive: "Archive",
|
|
33
|
+
more: "More",
|
|
34
|
+
backToBlog: "Back to Blog",
|
|
35
|
+
details: "Details",
|
|
36
|
+
activity: "Activity",
|
|
37
|
+
switchToNormalPage: "Switch to Normal Page",
|
|
38
|
+
switchToPostPage: "Switch to Post Page"
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const normalizeLang = (lang) => {
|
|
42
|
+
if (!lang) return "en";
|
|
43
|
+
const lower = lang.toLowerCase();
|
|
44
|
+
if (lower.startsWith("zh")) return "zh-CN";
|
|
45
|
+
if (lower.startsWith("en")) return "en";
|
|
46
|
+
return "en";
|
|
47
|
+
};
|
|
48
|
+
function getLocalizedString(key, lang) {
|
|
49
|
+
const language = normalizeLang(lang);
|
|
50
|
+
return LOCALIZED_STRINGS[language]?.[key] || LOCALIZED_STRINGS.en[key];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
Object.defineProperty(exports, 'DEFAULT_PAGE_GROUP_SIZE', {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return DEFAULT_PAGE_GROUP_SIZE;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, 'DEFAULT_PAGE_SIZE', {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return DEFAULT_PAGE_SIZE;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, 'LOCALIZED_STRINGS', {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return LOCALIZED_STRINGS;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, 'MAX_DISPLAYED_TAGS', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return MAX_DISPLAYED_TAGS;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, 'getLocalizedString', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return getLocalizedString;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
const DEFAULT_PAGE_SIZE = 5;
|
|
3
|
+
const DEFAULT_PAGE_GROUP_SIZE = 5;
|
|
4
|
+
const MAX_DISPLAYED_TAGS = 20;
|
|
5
|
+
const LOCALIZED_STRINGS = {
|
|
6
|
+
"zh-CN": {
|
|
7
|
+
prev: "上一页",
|
|
8
|
+
next: "下一页",
|
|
9
|
+
all: "全部",
|
|
10
|
+
posts: "文章",
|
|
11
|
+
tags: "标签",
|
|
12
|
+
category: "分类",
|
|
13
|
+
other: "其他",
|
|
14
|
+
archive: "归档",
|
|
15
|
+
more: "更多",
|
|
16
|
+
backToBlog: "博客首页",
|
|
17
|
+
details: "详情",
|
|
18
|
+
activity: "更新状态",
|
|
19
|
+
switchToNormalPage: "切换到普通页面",
|
|
20
|
+
switchToPostPage: "切换到文章页面"
|
|
21
|
+
},
|
|
22
|
+
en: {
|
|
23
|
+
prev: "Prev",
|
|
24
|
+
next: "Next",
|
|
25
|
+
all: "All",
|
|
26
|
+
posts: "POSTS",
|
|
27
|
+
tags: "TAGS",
|
|
28
|
+
category: "Category",
|
|
29
|
+
other: "Other",
|
|
30
|
+
archive: "Archive",
|
|
31
|
+
more: "More",
|
|
32
|
+
backToBlog: "Back to Blog",
|
|
33
|
+
details: "Details",
|
|
34
|
+
activity: "Activity",
|
|
35
|
+
switchToNormalPage: "Switch to Normal Page",
|
|
36
|
+
switchToPostPage: "Switch to Post Page"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const normalizeLang = (lang) => {
|
|
40
|
+
if (!lang) return "en";
|
|
41
|
+
const lower = lang.toLowerCase();
|
|
42
|
+
if (lower.startsWith("zh")) return "zh-CN";
|
|
43
|
+
if (lower.startsWith("en")) return "en";
|
|
44
|
+
return "en";
|
|
45
|
+
};
|
|
46
|
+
function getLocalizedString(key, lang) {
|
|
47
|
+
const language = normalizeLang(lang);
|
|
48
|
+
return LOCALIZED_STRINGS[language]?.[key] || LOCALIZED_STRINGS.en[key];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, getLocalizedString };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const DEFAULT_PAGE_SIZE = 5;
|
|
3
|
+
declare const DEFAULT_PAGE_GROUP_SIZE = 5;
|
|
4
|
+
declare const MAX_DISPLAYED_TAGS = 20;
|
|
5
|
+
declare const LOCALIZED_STRINGS: {
|
|
6
|
+
readonly 'zh-CN': {
|
|
7
|
+
readonly prev: "上一页";
|
|
8
|
+
readonly next: "下一页";
|
|
9
|
+
readonly all: "全部";
|
|
10
|
+
readonly posts: "文章";
|
|
11
|
+
readonly tags: "标签";
|
|
12
|
+
readonly category: "分类";
|
|
13
|
+
readonly other: "其他";
|
|
14
|
+
readonly archive: "归档";
|
|
15
|
+
readonly more: "更多";
|
|
16
|
+
readonly backToBlog: "博客首页";
|
|
17
|
+
readonly details: "详情";
|
|
18
|
+
readonly activity: "更新状态";
|
|
19
|
+
readonly switchToNormalPage: "切换到普通页面";
|
|
20
|
+
readonly switchToPostPage: "切换到文章页面";
|
|
21
|
+
};
|
|
22
|
+
readonly en: {
|
|
23
|
+
readonly prev: "Prev";
|
|
24
|
+
readonly next: "Next";
|
|
25
|
+
readonly all: "All";
|
|
26
|
+
readonly posts: "POSTS";
|
|
27
|
+
readonly tags: "TAGS";
|
|
28
|
+
readonly category: "Category";
|
|
29
|
+
readonly other: "Other";
|
|
30
|
+
readonly archive: "Archive";
|
|
31
|
+
readonly more: "More";
|
|
32
|
+
readonly backToBlog: "Back to Blog";
|
|
33
|
+
readonly details: "Details";
|
|
34
|
+
readonly activity: "Activity";
|
|
35
|
+
readonly switchToNormalPage: "Switch to Normal Page";
|
|
36
|
+
readonly switchToPostPage: "Switch to Post Page";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type SupportedLanguage = keyof typeof LOCALIZED_STRINGS;
|
|
40
|
+
declare function getLocalizedString(key: keyof typeof LOCALIZED_STRINGS['en'], lang?: string): string; //#endregion
|
|
41
|
+
//#region src/types.d.ts
|
|
42
|
+
interface BlogFrontmatter {
|
|
43
|
+
title?: string;
|
|
44
|
+
date?: string | Date;
|
|
45
|
+
tags?: string[];
|
|
46
|
+
category?: string;
|
|
47
|
+
author?: string;
|
|
48
|
+
desc?: string;
|
|
49
|
+
cover?: string;
|
|
50
|
+
pin?: boolean;
|
|
51
|
+
draft?: boolean;
|
|
52
|
+
hidden?: boolean;
|
|
53
|
+
publish?: boolean;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
interface BlogPost {
|
|
57
|
+
frontmatter: BlogFrontmatter;
|
|
58
|
+
excerpt?: string;
|
|
59
|
+
url: string;
|
|
60
|
+
html?: string;
|
|
61
|
+
} //#endregion
|
|
62
|
+
//#region src/utils/date.d.ts
|
|
63
|
+
declare const parseDateValue: (value: unknown) => number;
|
|
64
|
+
declare const formatDate: (value: unknown, locale?: string) => string;
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE as DEFAULT_PAGE_GROUP_SIZE$1, DEFAULT_PAGE_SIZE as DEFAULT_PAGE_SIZE$1, LOCALIZED_STRINGS as LOCALIZED_STRINGS$1, MAX_DISPLAYED_TAGS as MAX_DISPLAYED_TAGS$1, SupportedLanguage, formatDate as formatDate$1, getLocalizedString as getLocalizedString$1, parseDateValue as parseDateValue$1 };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
declare const DEFAULT_PAGE_SIZE = 5;
|
|
3
|
+
declare const DEFAULT_PAGE_GROUP_SIZE = 5;
|
|
4
|
+
declare const MAX_DISPLAYED_TAGS = 20;
|
|
5
|
+
declare const LOCALIZED_STRINGS: {
|
|
6
|
+
readonly 'zh-CN': {
|
|
7
|
+
readonly prev: "上一页";
|
|
8
|
+
readonly next: "下一页";
|
|
9
|
+
readonly all: "全部";
|
|
10
|
+
readonly posts: "文章";
|
|
11
|
+
readonly tags: "标签";
|
|
12
|
+
readonly category: "分类";
|
|
13
|
+
readonly other: "其他";
|
|
14
|
+
readonly archive: "归档";
|
|
15
|
+
readonly more: "更多";
|
|
16
|
+
readonly backToBlog: "博客首页";
|
|
17
|
+
readonly details: "详情";
|
|
18
|
+
readonly activity: "更新状态";
|
|
19
|
+
readonly switchToNormalPage: "切换到普通页面";
|
|
20
|
+
readonly switchToPostPage: "切换到文章页面";
|
|
21
|
+
};
|
|
22
|
+
readonly en: {
|
|
23
|
+
readonly prev: "Prev";
|
|
24
|
+
readonly next: "Next";
|
|
25
|
+
readonly all: "All";
|
|
26
|
+
readonly posts: "POSTS";
|
|
27
|
+
readonly tags: "TAGS";
|
|
28
|
+
readonly category: "Category";
|
|
29
|
+
readonly other: "Other";
|
|
30
|
+
readonly archive: "Archive";
|
|
31
|
+
readonly more: "More";
|
|
32
|
+
readonly backToBlog: "Back to Blog";
|
|
33
|
+
readonly details: "Details";
|
|
34
|
+
readonly activity: "Activity";
|
|
35
|
+
readonly switchToNormalPage: "Switch to Normal Page";
|
|
36
|
+
readonly switchToPostPage: "Switch to Post Page";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type SupportedLanguage = keyof typeof LOCALIZED_STRINGS;
|
|
40
|
+
declare function getLocalizedString(key: keyof typeof LOCALIZED_STRINGS['en'], lang?: string): string; //#endregion
|
|
41
|
+
//#region src/types.d.ts
|
|
42
|
+
interface BlogFrontmatter {
|
|
43
|
+
title?: string;
|
|
44
|
+
date?: string | Date;
|
|
45
|
+
tags?: string[];
|
|
46
|
+
category?: string;
|
|
47
|
+
author?: string;
|
|
48
|
+
desc?: string;
|
|
49
|
+
cover?: string;
|
|
50
|
+
pin?: boolean;
|
|
51
|
+
draft?: boolean;
|
|
52
|
+
hidden?: boolean;
|
|
53
|
+
publish?: boolean;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
interface BlogPost {
|
|
57
|
+
frontmatter: BlogFrontmatter;
|
|
58
|
+
excerpt?: string;
|
|
59
|
+
url: string;
|
|
60
|
+
html?: string;
|
|
61
|
+
} //#endregion
|
|
62
|
+
//#region src/utils/date.d.ts
|
|
63
|
+
declare const parseDateValue: (value: unknown) => number;
|
|
64
|
+
declare const formatDate: (value: unknown, locale?: string) => string;
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, SupportedLanguage, formatDate, getLocalizedString, parseDateValue };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/utils/date.ts
|
|
2
|
+
const parseDateValue = (value) => {
|
|
3
|
+
if (!value) return 0;
|
|
4
|
+
if (value instanceof Date) return value.getTime();
|
|
5
|
+
const time = Date.parse(String(value));
|
|
6
|
+
return Number.isNaN(time) ? 0 : time;
|
|
7
|
+
};
|
|
8
|
+
const formatDate = (value, locale) => {
|
|
9
|
+
if (!value) return "";
|
|
10
|
+
const date = new Date(value);
|
|
11
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
12
|
+
const safeLocale = locale || "en-US";
|
|
13
|
+
return date.toLocaleDateString(safeLocale, {
|
|
14
|
+
year: "numeric",
|
|
15
|
+
month: "long",
|
|
16
|
+
day: "numeric"
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { formatDate, parseDateValue };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/date.ts
|
|
4
|
+
const parseDateValue = (value) => {
|
|
5
|
+
if (!value) return 0;
|
|
6
|
+
if (value instanceof Date) return value.getTime();
|
|
7
|
+
const time = Date.parse(String(value));
|
|
8
|
+
return Number.isNaN(time) ? 0 : time;
|
|
9
|
+
};
|
|
10
|
+
const formatDate = (value, locale) => {
|
|
11
|
+
if (!value) return "";
|
|
12
|
+
const date = new Date(value);
|
|
13
|
+
if (Number.isNaN(date.getTime())) return String(value);
|
|
14
|
+
const safeLocale = locale || "en-US";
|
|
15
|
+
return date.toLocaleDateString(safeLocale, {
|
|
16
|
+
year: "numeric",
|
|
17
|
+
month: "long",
|
|
18
|
+
day: "numeric"
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, 'formatDate', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return formatDate;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, 'parseDateValue', {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return parseDateValue;
|
|
33
|
+
}
|
|
34
|
+
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const require_constants = require('./constants-CnBvTOWr.cjs');
|
|
2
|
+
const require_date = require('./date-ygOc7hIU.cjs');
|
|
3
|
+
const require_post_helpers = require('./post-helpers-BygKdsMh.cjs');
|
|
4
|
+
|
|
5
|
+
exports.DEFAULT_PAGE_GROUP_SIZE = require_constants.DEFAULT_PAGE_GROUP_SIZE
|
|
6
|
+
exports.DEFAULT_PAGE_SIZE = require_constants.DEFAULT_PAGE_SIZE
|
|
7
|
+
exports.LOCALIZED_STRINGS = require_constants.LOCALIZED_STRINGS
|
|
8
|
+
exports.MAX_DISPLAYED_TAGS = require_constants.MAX_DISPLAYED_TAGS
|
|
9
|
+
exports.formatDate = require_date.formatDate
|
|
10
|
+
exports.getLocalizedString = require_constants.getLocalizedString
|
|
11
|
+
exports.normalizePosts = require_post_helpers.normalizePosts
|
|
12
|
+
exports.parseDateValue = require_date.parseDateValue
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, SupportedLanguage, formatDate, getLocalizedString, parseDateValue } from "./date-CCP55OAZ.cjs";
|
|
2
|
+
import { normalizePosts } from "./index-B6RX4u89.cjs";
|
|
3
|
+
export { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, SupportedLanguage, formatDate, getLocalizedString, normalizePosts, parseDateValue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE$1 as DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE$1 as DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS$1 as LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS$1 as MAX_DISPLAYED_TAGS, SupportedLanguage, formatDate$1 as formatDate, getLocalizedString$1 as getLocalizedString, parseDateValue$1 as parseDateValue } from "./date-BySfVUhd.js";
|
|
2
|
+
import { normalizePosts } from "./index-hfvJJTlf.js";
|
|
3
|
+
export { BlogFrontmatter, BlogPost, DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, SupportedLanguage, formatDate, getLocalizedString, normalizePosts, parseDateValue };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, getLocalizedString } from "./constants-Dc4Co5gF.js";
|
|
2
|
+
import { formatDate, parseDateValue } from "./date-DAUKykKr.js";
|
|
3
|
+
import { normalizePosts$1 as normalizePosts } from "./post-helpers-C_A-ioOF.js";
|
|
4
|
+
|
|
5
|
+
export { DEFAULT_PAGE_GROUP_SIZE, DEFAULT_PAGE_SIZE, LOCALIZED_STRINGS, MAX_DISPLAYED_TAGS, formatDate, getLocalizedString, normalizePosts, parseDateValue };
|
package/dist/loader.cjs
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
3
|
+
const require_date = require('./date-ygOc7hIU.cjs');
|
|
4
|
+
const require_post_helpers = require('./post-helpers-BygKdsMh.cjs');
|
|
5
|
+
const vitepress = require_chunk.__toESM(require("vitepress"));
|
|
6
|
+
|
|
7
|
+
//#region src/loader/posts.ts
|
|
8
|
+
const createPostsLoader = (pattern = "posts/**/*.md") => (0, vitepress.createContentLoader)(pattern, {
|
|
9
|
+
includeSrc: false,
|
|
10
|
+
render: false,
|
|
11
|
+
excerpt: true,
|
|
12
|
+
transform(rawData) {
|
|
13
|
+
return require_post_helpers.normalizePosts(rawData);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/loader/page-links.ts
|
|
19
|
+
const createPageLinksLoader = (patterns = ["**/*.md"]) => (0, vitepress.createContentLoader)(patterns, {
|
|
20
|
+
includeSrc: false,
|
|
21
|
+
transform(pages) {
|
|
22
|
+
const links = {};
|
|
23
|
+
for (const page of pages) {
|
|
24
|
+
const layout = page.frontmatter?.layout;
|
|
25
|
+
if (!links.blog && layout === "blog") links.blog = page.url;
|
|
26
|
+
if (!links.tags && layout === "tags") links.tags = page.url;
|
|
27
|
+
if (!links.categories && layout === "categories") links.categories = page.url;
|
|
28
|
+
if (!links.archive && layout === "archive") links.archive = page.url;
|
|
29
|
+
}
|
|
30
|
+
return links;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/loader/tags.ts
|
|
36
|
+
const createTagsLoader = (pattern = "posts/**/*.md") => (0, vitepress.createContentLoader)(pattern, {
|
|
37
|
+
includeSrc: false,
|
|
38
|
+
render: false,
|
|
39
|
+
excerpt: true,
|
|
40
|
+
transform(rawData) {
|
|
41
|
+
const posts = require_post_helpers.normalizePosts(rawData);
|
|
42
|
+
const tagsMap = { "": posts.length };
|
|
43
|
+
posts.forEach((post) => {
|
|
44
|
+
const tags = post.frontmatter.tags;
|
|
45
|
+
if (!tags) return;
|
|
46
|
+
tags.forEach((tag) => {
|
|
47
|
+
tagsMap[tag] = (tagsMap[tag] || 0) + 1;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const tagArray = Object.entries(tagsMap).sort((a, b) => b[1] - a[1]);
|
|
51
|
+
const uniqueTagCount = Object.keys(tagsMap).filter(Boolean).length;
|
|
52
|
+
const totalPosts = tagsMap[""] || posts.length;
|
|
53
|
+
return {
|
|
54
|
+
tagsMap,
|
|
55
|
+
tagArray,
|
|
56
|
+
uniqueTagCount,
|
|
57
|
+
totalPosts
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/loader/categories.ts
|
|
64
|
+
const extractCategoryFromUrl = (url, otherLabel) => {
|
|
65
|
+
const match = url.match(/^\/posts\/([^/]+)\//);
|
|
66
|
+
if (match && match[1]) return match[1];
|
|
67
|
+
if (url.startsWith("/posts/") && /^\/posts\/[^/]+(\.html)?$/.test(url)) return otherLabel;
|
|
68
|
+
return "";
|
|
69
|
+
};
|
|
70
|
+
const createCategoriesLoader = (pattern = "posts/**/*.md", options) => (0, vitepress.createContentLoader)(pattern, {
|
|
71
|
+
includeSrc: false,
|
|
72
|
+
render: false,
|
|
73
|
+
excerpt: true,
|
|
74
|
+
transform(rawData) {
|
|
75
|
+
const otherLabel = options?.otherLabel || "Other";
|
|
76
|
+
const posts = require_post_helpers.normalizePosts(rawData);
|
|
77
|
+
const categoriesMap = { "": posts.length };
|
|
78
|
+
posts.forEach((post) => {
|
|
79
|
+
const fmCategory = post.frontmatter?.category;
|
|
80
|
+
const category = fmCategory || extractCategoryFromUrl(post.url, otherLabel);
|
|
81
|
+
if (category) categoriesMap[category] = (categoriesMap[category] || 0) + 1;
|
|
82
|
+
});
|
|
83
|
+
const categoryArray = Object.entries(categoriesMap).sort((a, b) => {
|
|
84
|
+
if (a[0] === "") return -1;
|
|
85
|
+
if (b[0] === "") return 1;
|
|
86
|
+
return b[1] - a[1];
|
|
87
|
+
});
|
|
88
|
+
const uniqueCategoryCount = Object.keys(categoriesMap).filter(Boolean).length;
|
|
89
|
+
const totalPosts = categoriesMap[""] || posts.length;
|
|
90
|
+
return {
|
|
91
|
+
categoriesMap,
|
|
92
|
+
categoryArray,
|
|
93
|
+
uniqueCategoryCount,
|
|
94
|
+
totalPosts
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/loader/archive.ts
|
|
101
|
+
const createArchiveLoader = (pattern = "posts/**/*.md") => (0, vitepress.createContentLoader)(pattern, {
|
|
102
|
+
includeSrc: false,
|
|
103
|
+
render: false,
|
|
104
|
+
excerpt: true,
|
|
105
|
+
transform(rawData) {
|
|
106
|
+
const posts = require_post_helpers.normalizePosts(rawData);
|
|
107
|
+
const sortedPosts = [...posts].sort((a, b) => require_date.parseDateValue(b.frontmatter.date) - require_date.parseDateValue(a.frontmatter.date));
|
|
108
|
+
const yearMap = new Map();
|
|
109
|
+
sortedPosts.forEach((post) => {
|
|
110
|
+
const time = require_date.parseDateValue(post.frontmatter.date);
|
|
111
|
+
const date = new Date(time || 0);
|
|
112
|
+
const year = date.getFullYear();
|
|
113
|
+
const month = date.getMonth();
|
|
114
|
+
const monthName = date.toLocaleString("default", { month: "long" });
|
|
115
|
+
if (!yearMap.has(year)) yearMap.set(year, new Map());
|
|
116
|
+
const monthMap = yearMap.get(year);
|
|
117
|
+
if (!monthMap.has(month)) monthMap.set(month, {
|
|
118
|
+
month,
|
|
119
|
+
monthName,
|
|
120
|
+
posts: []
|
|
121
|
+
});
|
|
122
|
+
monthMap.get(month).posts.push(post);
|
|
123
|
+
});
|
|
124
|
+
const yearGroups = Array.from(yearMap.entries()).sort((a, b) => b[0] - a[0]).map(([year, monthMap]) => {
|
|
125
|
+
const months = Array.from(monthMap.values()).sort((a, b) => b.month - a.month);
|
|
126
|
+
const total = months.reduce((sum, m) => sum + m.posts.length, 0);
|
|
127
|
+
return {
|
|
128
|
+
year,
|
|
129
|
+
months,
|
|
130
|
+
total
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
return {
|
|
134
|
+
yearGroups,
|
|
135
|
+
totalPosts: sortedPosts.length
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
exports.createArchiveLoader = createArchiveLoader
|
|
142
|
+
exports.createCategoriesLoader = createCategoriesLoader
|
|
143
|
+
exports.createPageLinksLoader = createPageLinksLoader
|
|
144
|
+
exports.createPostsLoader = createPostsLoader
|
|
145
|
+
exports.createTagsLoader = createTagsLoader
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BlogPost } from "./date-CCP55OAZ.cjs";
|
|
2
|
+
import "./index-B6RX4u89.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/loader/posts.d.ts
|
|
5
|
+
declare const createPostsLoader: (pattern?: string) => {
|
|
6
|
+
watch: string | string[];
|
|
7
|
+
load: () => Promise<BlogPost[]>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/loader/page-links.d.ts
|
|
12
|
+
interface PageLinks {
|
|
13
|
+
tags?: string;
|
|
14
|
+
categories?: string;
|
|
15
|
+
archive?: string;
|
|
16
|
+
blog?: string;
|
|
17
|
+
}
|
|
18
|
+
declare const createPageLinksLoader: (patterns?: string[]) => {
|
|
19
|
+
watch: string | string[];
|
|
20
|
+
load: () => Promise<PageLinks>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/loader/tags.d.ts
|
|
25
|
+
interface TagsIndex {
|
|
26
|
+
tagsMap: Record<string, number>;
|
|
27
|
+
tagArray: [string, number][];
|
|
28
|
+
uniqueTagCount: number;
|
|
29
|
+
totalPosts: number;
|
|
30
|
+
}
|
|
31
|
+
declare const createTagsLoader: (pattern?: string) => {
|
|
32
|
+
watch: string | string[];
|
|
33
|
+
load: () => Promise<TagsIndex>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/loader/categories.d.ts
|
|
38
|
+
interface CategoriesIndex {
|
|
39
|
+
categoriesMap: Record<string, number>;
|
|
40
|
+
categoryArray: [string, number][];
|
|
41
|
+
uniqueCategoryCount: number;
|
|
42
|
+
totalPosts: number;
|
|
43
|
+
}
|
|
44
|
+
declare const createCategoriesLoader: (pattern?: string, options?: {
|
|
45
|
+
otherLabel?: string;
|
|
46
|
+
}) => {
|
|
47
|
+
watch: string | string[];
|
|
48
|
+
load: () => Promise<CategoriesIndex>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/loader/archive.d.ts
|
|
53
|
+
interface ArchiveMonthGroup {
|
|
54
|
+
month: number;
|
|
55
|
+
monthName: string;
|
|
56
|
+
posts: BlogPost[];
|
|
57
|
+
}
|
|
58
|
+
interface ArchiveYearGroup {
|
|
59
|
+
year: number;
|
|
60
|
+
months: ArchiveMonthGroup[];
|
|
61
|
+
total: number;
|
|
62
|
+
}
|
|
63
|
+
interface ArchiveIndex {
|
|
64
|
+
yearGroups: ArchiveYearGroup[];
|
|
65
|
+
totalPosts: number;
|
|
66
|
+
}
|
|
67
|
+
declare const createArchiveLoader: (pattern?: string) => {
|
|
68
|
+
watch: string | string[];
|
|
69
|
+
load: () => Promise<ArchiveIndex>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { ArchiveIndex, ArchiveMonthGroup, ArchiveYearGroup, CategoriesIndex, PageLinks, TagsIndex, createArchiveLoader, createCategoriesLoader, createPageLinksLoader, createPostsLoader, createTagsLoader };
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BlogPost } from "./date-BySfVUhd.js";
|
|
2
|
+
import "./index-hfvJJTlf.js";
|
|
3
|
+
|
|
4
|
+
//#region src/loader/posts.d.ts
|
|
5
|
+
declare const createPostsLoader: (pattern?: string) => {
|
|
6
|
+
watch: string | string[];
|
|
7
|
+
load: () => Promise<BlogPost[]>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/loader/page-links.d.ts
|
|
12
|
+
interface PageLinks {
|
|
13
|
+
tags?: string;
|
|
14
|
+
categories?: string;
|
|
15
|
+
archive?: string;
|
|
16
|
+
blog?: string;
|
|
17
|
+
}
|
|
18
|
+
declare const createPageLinksLoader: (patterns?: string[]) => {
|
|
19
|
+
watch: string | string[];
|
|
20
|
+
load: () => Promise<PageLinks>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/loader/tags.d.ts
|
|
25
|
+
interface TagsIndex {
|
|
26
|
+
tagsMap: Record<string, number>;
|
|
27
|
+
tagArray: [string, number][];
|
|
28
|
+
uniqueTagCount: number;
|
|
29
|
+
totalPosts: number;
|
|
30
|
+
}
|
|
31
|
+
declare const createTagsLoader: (pattern?: string) => {
|
|
32
|
+
watch: string | string[];
|
|
33
|
+
load: () => Promise<TagsIndex>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/loader/categories.d.ts
|
|
38
|
+
interface CategoriesIndex {
|
|
39
|
+
categoriesMap: Record<string, number>;
|
|
40
|
+
categoryArray: [string, number][];
|
|
41
|
+
uniqueCategoryCount: number;
|
|
42
|
+
totalPosts: number;
|
|
43
|
+
}
|
|
44
|
+
declare const createCategoriesLoader: (pattern?: string, options?: {
|
|
45
|
+
otherLabel?: string;
|
|
46
|
+
}) => {
|
|
47
|
+
watch: string | string[];
|
|
48
|
+
load: () => Promise<CategoriesIndex>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/loader/archive.d.ts
|
|
53
|
+
interface ArchiveMonthGroup {
|
|
54
|
+
month: number;
|
|
55
|
+
monthName: string;
|
|
56
|
+
posts: BlogPost[];
|
|
57
|
+
}
|
|
58
|
+
interface ArchiveYearGroup {
|
|
59
|
+
year: number;
|
|
60
|
+
months: ArchiveMonthGroup[];
|
|
61
|
+
total: number;
|
|
62
|
+
}
|
|
63
|
+
interface ArchiveIndex {
|
|
64
|
+
yearGroups: ArchiveYearGroup[];
|
|
65
|
+
totalPosts: number;
|
|
66
|
+
}
|
|
67
|
+
declare const createArchiveLoader: (pattern?: string) => {
|
|
68
|
+
watch: string | string[];
|
|
69
|
+
load: () => Promise<ArchiveIndex>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { ArchiveIndex, ArchiveMonthGroup, ArchiveYearGroup, CategoriesIndex, PageLinks, TagsIndex, createArchiveLoader, createCategoriesLoader, createPageLinksLoader, createPostsLoader, createTagsLoader };
|