|
@@ -155,10 +155,17 @@ function parsePostMetadata(content) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Helper function to generate filename from title
|
|
// Helper function to generate filename from title
|
|
|
-function generateFilename(title) {
|
|
|
|
|
|
|
+function generateFilename(title, dateOverride = null) {
|
|
|
// Create date-based filename similar to existing pattern
|
|
// Create date-based filename similar to existing pattern
|
|
|
- const date = new Date();
|
|
|
|
|
- const dateStr = date.toISOString().slice(0, 10).replace(/-/g, "");
|
|
|
|
|
|
|
+ // Use override if provided, otherwise current date
|
|
|
|
|
+ let dateStr;
|
|
|
|
|
+ if (dateOverride) {
|
|
|
|
|
+ dateStr = dateOverride;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const date = new Date();
|
|
|
|
|
+ dateStr = date.toISOString().slice(0, 10).replace(/-/g, "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const slug = title
|
|
const slug = title
|
|
|
.toLowerCase()
|
|
.toLowerCase()
|
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
@@ -564,8 +571,14 @@ app.put("/api/posts/:slug", requireAuth, async (req, res) => {
|
|
|
.json({ error: "Title and content are required" });
|
|
.json({ error: "Title and content are required" });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Generate new filename if title changed
|
|
|
|
|
- const newFilename = generateFilename(title);
|
|
|
|
|
|
|
+ // Extract date from existing slug/filename to preserve it
|
|
|
|
|
+ // Filename format: YYYYMMDD-slug.md
|
|
|
|
|
+ // We assume the first 8 chars are the date if they are digits
|
|
|
|
|
+ const dateMatch = slug.match(/^(\d{8})-/);
|
|
|
|
|
+ const originalDate = dateMatch ? dateMatch[1] : null;
|
|
|
|
|
+
|
|
|
|
|
+ // Generate new filename if title changed, but PRESERVE original date
|
|
|
|
|
+ const newFilename = generateFilename(title, originalDate);
|
|
|
const newFilePath = path.join(POSTS_DIR, newFilename);
|
|
const newFilePath = path.join(POSTS_DIR, newFilename);
|
|
|
|
|
|
|
|
// Format the post content
|
|
// Format the post content
|