From eac2f4eca3cf2d7fb946bcaf7595f839401bfdcd Mon Sep 17 00:00:00 2001 From: Tianyi Shi Date: Mon, 11 May 2020 18:23:41 +0800 Subject: [PATCH] new post file name include date --- src/blogdown/commands/NewPost.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/blogdown/commands/NewPost.ts b/src/blogdown/commands/NewPost.ts index 58fa794..4d2d001 100644 --- a/src/blogdown/commands/NewPost.ts +++ b/src/blogdown/commands/NewPost.ts @@ -3,7 +3,7 @@ import * as vscode from "vscode"; import { MultiStepInput } from "../../common"; import { BaseCommand } from "../../common/BaseCommand"; import { promises as fsPromises, readFileSync, writeFileSync } from "fs"; -import { join } from "path"; +import * as path from "path"; import { slugify } from "../../utils/slugify"; const { readdir } = fsPromises; @@ -27,7 +27,7 @@ export class NewPost extends BaseCommand { return; } const slug = slugify(state.title!); - const newPostPath = join(state.category!, slug + ".Rmd"); + const newPostPath = path.join(state.category!, `${new Date().toISOString().slice(0, 10)}-${slug}.Rmd`); simpleNewPostGenerator(state.archetype!, newPostPath, state as NewPostOptions); vscode.workspace.openTextDocument(newPostPath).then((document) => vscode.window.showTextDocument(document)); } @@ -107,10 +107,10 @@ interface CategoryPickItem extends vscode.QuickPickItem { } async function getCategories(projectDir: string): Promise { - const categoriesParentDir = join(projectDir, "content"); + const categoriesParentDir = path.join(projectDir, "content"); const categories = await (await readdir(categoriesParentDir, { withFileTypes: true })).filter((p) => p.isDirectory()).map((p) => p.name); return Array.from(categories, (cat) => { - return { label: cat, fullPath: join(categoriesParentDir, cat) }; + return { label: cat, fullPath: path.join(categoriesParentDir, cat) }; }); } @@ -119,7 +119,7 @@ interface ArchetypePickItem extends vscode.QuickPickItem { } async function getArchetypes(projectDir: string): Promise { - const archetypesDir = join(projectDir, "archetypes"); + const archetypesDir = path.join(projectDir, "archetypes"); const archetypes = await (await readdir(archetypesDir, { withFileTypes: true })).filter((p) => p.isFile() && p.name.slice(p.name.length - 2) === "md").map((p) => p.name); return Array.from(archetypes, (arc) => { return { label: arc, fullPath: join(archetypesDir, arc) };