精简若干功能,优化slug生成规则
This commit is contained in:
1 parent
05bf116c20
commit
f9b2a0e77b
15 files changed
+76
-41
No files matched your search
@@ -155,7 +155,7 @@ 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 (Chinese-friendly)
|
||||
// Folder name: date + sanitized title (human-readable on disk)
|
||||
const titlePart = (frontMatter.title || "untitled")
|
||||
.replace(/[^\w一-鿿㐀-䶿]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
@@ -202,7 +202,11 @@ export function updatePost(
|
||||
const newDate = new Date(merged.date || post.frontMatter.date);
|
||||
const newYear = newDate.getFullYear().toString();
|
||||
const newDateStr = newDate.toISOString().slice(0, 10);
|
||||
const newDirName = `${newDateStr}-${frontMatter.slug}`;
|
||||
const titlePart = (merged.title || "untitled")
|
||||
.replace(/[^\w一-鿿㐀-䶿]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.toLowerCase() || "post";
|
||||
const newDirName = `${newDateStr}-${titlePart}`;
|
||||
const newDirPath = path.join(CONTENT_DIR, newYear, newDirName);
|
||||
|
||||
if (fs.existsSync(newDirPath) && newDirPath !== post.dirPath) {
|
||||
|
||||
Reference in new issue
Block a user