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
package/dist/loader.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { parseDateValue } from "./date-DAUKykKr.js";
|
|
2
|
+
import { normalizePosts$1 as normalizePosts } from "./post-helpers-C_A-ioOF.js";
|
|
3
|
+
import { createContentLoader } from "vitepress";
|
|
4
|
+
|
|
5
|
+
//#region src/loader/posts.ts
|
|
6
|
+
const createPostsLoader = (pattern = "posts/**/*.md") => createContentLoader(pattern, {
|
|
7
|
+
includeSrc: false,
|
|
8
|
+
render: false,
|
|
9
|
+
excerpt: true,
|
|
10
|
+
transform(rawData) {
|
|
11
|
+
return normalizePosts(rawData);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/loader/page-links.ts
|
|
17
|
+
const createPageLinksLoader = (patterns = ["**/*.md"]) => createContentLoader(patterns, {
|
|
18
|
+
includeSrc: false,
|
|
19
|
+
transform(pages) {
|
|
20
|
+
const links = {};
|
|
21
|
+
for (const page of pages) {
|
|
22
|
+
const layout = page.frontmatter?.layout;
|
|
23
|
+
if (!links.blog && layout === "blog") links.blog = page.url;
|
|
24
|
+
if (!links.tags && layout === "tags") links.tags = page.url;
|
|
25
|
+
if (!links.categories && layout === "categories") links.categories = page.url;
|
|
26
|
+
if (!links.archive && layout === "archive") links.archive = page.url;
|
|
27
|
+
}
|
|
28
|
+
return links;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/loader/tags.ts
|
|
34
|
+
const createTagsLoader = (pattern = "posts/**/*.md") => createContentLoader(pattern, {
|
|
35
|
+
includeSrc: false,
|
|
36
|
+
render: false,
|
|
37
|
+
excerpt: true,
|
|
38
|
+
transform(rawData) {
|
|
39
|
+
const posts = normalizePosts(rawData);
|
|
40
|
+
const tagsMap = { "": posts.length };
|
|
41
|
+
posts.forEach((post) => {
|
|
42
|
+
const tags = post.frontmatter.tags;
|
|
43
|
+
if (!tags) return;
|
|
44
|
+
tags.forEach((tag) => {
|
|
45
|
+
tagsMap[tag] = (tagsMap[tag] || 0) + 1;
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const tagArray = Object.entries(tagsMap).sort((a, b) => b[1] - a[1]);
|
|
49
|
+
const uniqueTagCount = Object.keys(tagsMap).filter(Boolean).length;
|
|
50
|
+
const totalPosts = tagsMap[""] || posts.length;
|
|
51
|
+
return {
|
|
52
|
+
tagsMap,
|
|
53
|
+
tagArray,
|
|
54
|
+
uniqueTagCount,
|
|
55
|
+
totalPosts
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/loader/categories.ts
|
|
62
|
+
const extractCategoryFromUrl = (url, otherLabel) => {
|
|
63
|
+
const match = url.match(/^\/posts\/([^/]+)\//);
|
|
64
|
+
if (match && match[1]) return match[1];
|
|
65
|
+
if (url.startsWith("/posts/") && /^\/posts\/[^/]+(\.html)?$/.test(url)) return otherLabel;
|
|
66
|
+
return "";
|
|
67
|
+
};
|
|
68
|
+
const createCategoriesLoader = (pattern = "posts/**/*.md", options) => createContentLoader(pattern, {
|
|
69
|
+
includeSrc: false,
|
|
70
|
+
render: false,
|
|
71
|
+
excerpt: true,
|
|
72
|
+
transform(rawData) {
|
|
73
|
+
const otherLabel = options?.otherLabel || "Other";
|
|
74
|
+
const posts = normalizePosts(rawData);
|
|
75
|
+
const categoriesMap = { "": posts.length };
|
|
76
|
+
posts.forEach((post) => {
|
|
77
|
+
const fmCategory = post.frontmatter?.category;
|
|
78
|
+
const category = fmCategory || extractCategoryFromUrl(post.url, otherLabel);
|
|
79
|
+
if (category) categoriesMap[category] = (categoriesMap[category] || 0) + 1;
|
|
80
|
+
});
|
|
81
|
+
const categoryArray = Object.entries(categoriesMap).sort((a, b) => {
|
|
82
|
+
if (a[0] === "") return -1;
|
|
83
|
+
if (b[0] === "") return 1;
|
|
84
|
+
return b[1] - a[1];
|
|
85
|
+
});
|
|
86
|
+
const uniqueCategoryCount = Object.keys(categoriesMap).filter(Boolean).length;
|
|
87
|
+
const totalPosts = categoriesMap[""] || posts.length;
|
|
88
|
+
return {
|
|
89
|
+
categoriesMap,
|
|
90
|
+
categoryArray,
|
|
91
|
+
uniqueCategoryCount,
|
|
92
|
+
totalPosts
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/loader/archive.ts
|
|
99
|
+
const createArchiveLoader = (pattern = "posts/**/*.md") => createContentLoader(pattern, {
|
|
100
|
+
includeSrc: false,
|
|
101
|
+
render: false,
|
|
102
|
+
excerpt: true,
|
|
103
|
+
transform(rawData) {
|
|
104
|
+
const posts = normalizePosts(rawData);
|
|
105
|
+
const sortedPosts = [...posts].sort((a, b) => parseDateValue(b.frontmatter.date) - parseDateValue(a.frontmatter.date));
|
|
106
|
+
const yearMap = new Map();
|
|
107
|
+
sortedPosts.forEach((post) => {
|
|
108
|
+
const time = parseDateValue(post.frontmatter.date);
|
|
109
|
+
const date = new Date(time || 0);
|
|
110
|
+
const year = date.getFullYear();
|
|
111
|
+
const month = date.getMonth();
|
|
112
|
+
const monthName = date.toLocaleString("default", { month: "long" });
|
|
113
|
+
if (!yearMap.has(year)) yearMap.set(year, new Map());
|
|
114
|
+
const monthMap = yearMap.get(year);
|
|
115
|
+
if (!monthMap.has(month)) monthMap.set(month, {
|
|
116
|
+
month,
|
|
117
|
+
monthName,
|
|
118
|
+
posts: []
|
|
119
|
+
});
|
|
120
|
+
monthMap.get(month).posts.push(post);
|
|
121
|
+
});
|
|
122
|
+
const yearGroups = Array.from(yearMap.entries()).sort((a, b) => b[0] - a[0]).map(([year, monthMap]) => {
|
|
123
|
+
const months = Array.from(monthMap.values()).sort((a, b) => b.month - a.month);
|
|
124
|
+
const total = months.reduce((sum, m) => sum + m.posts.length, 0);
|
|
125
|
+
return {
|
|
126
|
+
year,
|
|
127
|
+
months,
|
|
128
|
+
total
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
yearGroups,
|
|
133
|
+
totalPosts: sortedPosts.length
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
export { createArchiveLoader, createCategoriesLoader, createPageLinksLoader, createPostsLoader, createTagsLoader };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const require_date = require('./date-ygOc7hIU.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/post-helpers.ts
|
|
5
|
+
const defaultFrontmatter = {
|
|
6
|
+
title: "Untitled",
|
|
7
|
+
date: "1970-01-01"
|
|
8
|
+
};
|
|
9
|
+
const isHiddenPost = (frontmatter) => {
|
|
10
|
+
if (!frontmatter) return false;
|
|
11
|
+
if (frontmatter.draft) return true;
|
|
12
|
+
if (frontmatter.hidden) return true;
|
|
13
|
+
if (frontmatter.publish === false) return true;
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
const comparePosts = (a, b) => {
|
|
17
|
+
const pinA = Boolean(a.frontmatter.pin);
|
|
18
|
+
const pinB = Boolean(b.frontmatter.pin);
|
|
19
|
+
if (pinA !== pinB) return pinA ? -1 : 1;
|
|
20
|
+
const dateA = require_date.parseDateValue(a.frontmatter.date);
|
|
21
|
+
const dateB = require_date.parseDateValue(b.frontmatter.date);
|
|
22
|
+
return dateB - dateA;
|
|
23
|
+
};
|
|
24
|
+
const normalizePosts = (rawData) => {
|
|
25
|
+
return rawData.filter((page) => !isHiddenPost(page?.frontmatter)).map((page) => ({
|
|
26
|
+
frontmatter: {
|
|
27
|
+
...defaultFrontmatter,
|
|
28
|
+
...page?.frontmatter || {}
|
|
29
|
+
},
|
|
30
|
+
excerpt: page?.excerpt,
|
|
31
|
+
url: page?.url,
|
|
32
|
+
html: page?.html
|
|
33
|
+
})).sort(comparePosts);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
Object.defineProperty(exports, 'normalizePosts', {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return normalizePosts;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseDateValue } from "./date-DAUKykKr.js";
|
|
2
|
+
|
|
3
|
+
//#region src/post-helpers.ts
|
|
4
|
+
const defaultFrontmatter = {
|
|
5
|
+
title: "Untitled",
|
|
6
|
+
date: "1970-01-01"
|
|
7
|
+
};
|
|
8
|
+
const isHiddenPost = (frontmatter) => {
|
|
9
|
+
if (!frontmatter) return false;
|
|
10
|
+
if (frontmatter.draft) return true;
|
|
11
|
+
if (frontmatter.hidden) return true;
|
|
12
|
+
if (frontmatter.publish === false) return true;
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
const comparePosts = (a, b) => {
|
|
16
|
+
const pinA = Boolean(a.frontmatter.pin);
|
|
17
|
+
const pinB = Boolean(b.frontmatter.pin);
|
|
18
|
+
if (pinA !== pinB) return pinA ? -1 : 1;
|
|
19
|
+
const dateA = parseDateValue(a.frontmatter.date);
|
|
20
|
+
const dateB = parseDateValue(b.frontmatter.date);
|
|
21
|
+
return dateB - dateA;
|
|
22
|
+
};
|
|
23
|
+
const normalizePosts = (rawData) => {
|
|
24
|
+
return rawData.filter((page) => !isHiddenPost(page?.frontmatter)).map((page) => ({
|
|
25
|
+
frontmatter: {
|
|
26
|
+
...defaultFrontmatter,
|
|
27
|
+
...page?.frontmatter || {}
|
|
28
|
+
},
|
|
29
|
+
excerpt: page?.excerpt,
|
|
30
|
+
url: page?.url,
|
|
31
|
+
html: page?.html
|
|
32
|
+
})).sort(comparePosts);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { normalizePosts as normalizePosts$1 };
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vitepress-velonor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "open17 <opensci@163.com>",
|
|
7
|
+
"repository": "https://github.com/open17/vitepress-theme-open17.git",
|
|
8
|
+
"homepage": "https://vitepress.open17.vip",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./loader": {
|
|
22
|
+
"types": "./dist/loader.d.ts",
|
|
23
|
+
"import": "./dist/loader.js",
|
|
24
|
+
"require": "./dist/loader.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./client": {
|
|
27
|
+
"types": "./dist/client.d.ts",
|
|
28
|
+
"import": "./dist/client.js",
|
|
29
|
+
"require": "./dist/client.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"vitepress": "^1.0.0",
|
|
34
|
+
"vue": "^3.3.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsdown": "^0.9.0",
|
|
38
|
+
"typescript": "^5.6.3"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
|
+
"prepublishOnly": "npm run build"
|
|
44
|
+
}
|
|
45
|
+
}
|