mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 17:32:58 +02:00
#34 - Fix for last modified time on template creation
This commit is contained in:
+22
-7
@@ -101,14 +101,11 @@ export class Article {
|
||||
const config = vscode.workspace.getConfiguration(CONFIG_KEY);
|
||||
const dateFormat = config.get(SETTING_DATE_FORMAT) as string;
|
||||
const dateField = config.get(SETTING_DATE_FIELD) as string || "date";
|
||||
const modField = config.get(SETTING_MODIFIED_FIELD) as string || "date";
|
||||
|
||||
article = this.articleDate(article, dateFormat, dateField, forceCreate);
|
||||
article = this.articleDate(article, dateFormat, modField, false);
|
||||
|
||||
if (typeof article.data[dateField] !== "undefined" || forceCreate) {
|
||||
if (dateFormat && typeof dateFormat === "string") {
|
||||
article.data[dateField] = format(new Date(), dateFormat);
|
||||
} else {
|
||||
article.data[dateField] = new Date();
|
||||
}
|
||||
}
|
||||
return article;
|
||||
}
|
||||
|
||||
@@ -185,4 +182,22 @@ export class Article {
|
||||
article.data["draft"] = newDraftStatus;
|
||||
ArticleHelper.update(editor, article);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the article date and return it
|
||||
* @param article
|
||||
* @param dateFormat
|
||||
* @param field
|
||||
* @param forceCreate
|
||||
*/
|
||||
private static articleDate(article: matter.GrayMatterFile<string>, dateFormat: string, field: string, forceCreate: boolean) {
|
||||
if (typeof article.data[field] !== "undefined" || forceCreate) {
|
||||
if (dateFormat && typeof dateFormat === "string") {
|
||||
article.data[field] = format(new Date(), dateFormat);
|
||||
} else {
|
||||
article.data[field] = new Date();
|
||||
}
|
||||
}
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user