-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
215 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ export default defineConfig({ | |
|
||
markdown, | ||
|
||
// buildEnd, | ||
buildEnd, | ||
|
||
vite, | ||
metaChunk: true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { execa } from "execa"; | ||
import fs from "fs-extra"; | ||
import { basename, dirname } from "path"; | ||
|
||
const cache = new Map<string, number>(); | ||
|
||
export function getGitTimestamp(file: string) { | ||
const cached = cache.get(file); | ||
if (cached) return cached; | ||
|
||
return new Promise<number>((resolve, reject) => { | ||
const cwd = dirname(file); | ||
if (!fs.existsSync(cwd)) return resolve(0); | ||
const fileName = basename(file); | ||
const child = execa("git", ["log", "-1", '--pretty="%ai"', fileName], { | ||
cwd, | ||
}); | ||
let output = ""; | ||
child.stdout.on("data", (d) => (output += String(d))); | ||
child.on("close", () => { | ||
const timestamp = +new Date(output); | ||
cache.set(file, timestamp); | ||
resolve(timestamp); | ||
}); | ||
child.on("error", reject); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 获取 markdown 内容中的标题 | ||
*/ | ||
export function getDefaultTitle(content: string) { | ||
const match = content.match(/^(#+)\s+(.+)/m); | ||
return match?.[2] || ""; | ||
} | ||
|
||
export function getTextSummary(text: string, count = 100) { | ||
return ( | ||
text | ||
// 去除frontmatter | ||
?.replace(/^---[\s\S]*?---/, "") | ||
// 首个标题 | ||
?.replace(/^#+\s+.*/, "") | ||
// 除去标题 | ||
?.replace(/#/g, "") | ||
// 除去图片 | ||
?.replace(/!\[.*?\]\(.*?\)/g, "") | ||
// 除去链接 | ||
?.replace(/\[(.*?)\]\(.*?\)/g, "$1") | ||
// 除去加粗 | ||
?.replace(/\*\*(.*?)\*\*/g, "$1") | ||
?.split("\n") | ||
?.filter((v) => !!v) | ||
?.join("\n") | ||
?.replace(/>(.*)/, "") | ||
?.replace(/</g, "<") | ||
.replace(/>/g, ">") | ||
?.trim() | ||
?.slice(0, count) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.