0041
This commit is contained in:
1 parent
737d153761
commit
c81cb0db18
8 files changed
+39
-14
No files matched your search
@@ -155,12 +155,13 @@ export function createPost(frontMatter: PostFrontMatter, content: string): strin
|
||||
const date = new Date(frontMatter.date || new Date());
|
||||
const year = date.getFullYear().toString();
|
||||
const dateStr = date.toISOString().slice(0, 10);
|
||||
// Folder name: date + sanitized title (human-readable on disk)
|
||||
const titlePart = (frontMatter.title || "untitled")
|
||||
.replace(/[^\w一-鿿㐀-䶿]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.toLowerCase() || "post";
|
||||
const dirName = `${dateStr}-${titlePart}`;
|
||||
// 用 slug 或时间戳确保目录唯一
|
||||
const uniquePart = frontMatter.slug || Date.now().toString(36);
|
||||
const dirName = `${dateStr}-${titlePart}-${uniquePart}`;
|
||||
const dirPath = path.join(CONTENT_DIR, year, dirName);
|
||||
|
||||
if (fs.existsSync(path.join(dirPath, "index.md"))) {
|
||||
@@ -206,7 +207,7 @@ export function updatePost(
|
||||
.replace(/[^\w一-鿿㐀-䶿]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.toLowerCase() || "post";
|
||||
const newDirName = `${newDateStr}-${titlePart}`;
|
||||
const newDirName = `${newDateStr}-${titlePart}-${frontMatter.slug}`;
|
||||
const newDirPath = path.join(CONTENT_DIR, newYear, newDirName);
|
||||
|
||||
if (fs.existsSync(newDirPath) && newDirPath !== post.dirPath) {
|
||||
|
||||
Reference in new issue
Block a user