From 933108848d098a3fa7f1a6295954caa7788c28e2 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 30 Sep 2020 09:55:20 +0200 Subject: [PATCH] #18 - Updates to support custom fields --- CHANGELOG.md | 4 ++++ README.md | 35 +++++++++++++++++++++++++++++------ package.json | 10 ++++++++++ src/commands/Article.ts | 13 ++++++++----- src/constants/settings.ts | 2 ++ 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d542ab7..a67dbdb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.7.0] - 2020-09-30 + +- [#18](https://github.com/estruyf/vscode-front-matter/issues/18): Added date and modified date field names settings to be able to change the extension its behavior + ## [1.6.0] - 2020-09-23 - Syntax highlighting for Hugo shortcodes has been added diff --git a/README.md b/README.md index 5e856fa8..512e8eb4 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,9 @@ The tags and categories are stored in the project VSCode user settings. You can The extension has more settings that allow you to configure it to your needs further. Here is a list of settings which you can set: -- `frontMatter.taxonomy.frontMatterType` - - Specify which Front Matter language you want to use. The extension supports `YAML` (default) and `TOML`. +### `frontMatter.taxonomy.frontMatterType` + +Specify which Front Matter language you want to use. The extension supports `YAML` (default) and `TOML`. ```json { @@ -88,8 +89,9 @@ The extension has more settings that allow you to configure it to your needs fur } ``` -- `frontMatter.taxonomy.indentArrays` - - Specify if arrays in the front matter are indented. Default: `true`. If you do not want to indent the array values, you can update it with the following setting change: +### `frontMatter.taxonomy.indentArrays` + +Specify if arrays in the front matter are indented. Default: `true`. If you do not want to indent the array values, you can update it with the following setting change: ```json { @@ -97,8 +99,9 @@ The extension has more settings that allow you to configure it to your needs fur } ``` -- `frontMatter.taxonomy.noPropertyValueQuotes` - - Specify the property names of which you want to remove the quotes in the output value. **Warning**: only use this when you know what you are doing. If you want to, for instance, remove the quotes from the date property, you can add the following: +### `frontMatter.taxonomy.noPropertyValueQuotes` + +Specify the property names of which you want to remove the quotes in the output value. **Warning**: only use this when you know what you are doing. If you want to, for instance, remove the quotes from the date property, you can add the following: ```json { @@ -106,6 +109,26 @@ The extension has more settings that allow you to configure it to your needs fur } ``` +### `frontMatter.taxonomy.dateField` + +Specifies the date field name to use in your Front Matter. Default value: `date`. + +```json +{ + "frontMatter.taxonomy.dateField": "date" +} +``` + +### `frontMatter.taxonomy.modifiedField` + +Specifies the modified date field name to use in your Front Matter. Default value: `lastmod`. + +```json +{ + "frontMatter.taxonomy.modifiedField": "lastmod" +} +``` + ## Usage - Start by opening the command prompt: diff --git a/package.json b/package.json index e6e77178..1a3372d4 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,16 @@ "configuration": { "title": "Front Matter: Configuration", "properties": { + "frontMatter.taxonomy.dateField": { + "type": "string", + "default": "date", + "description": "Specifies the date field name to use in your Front Matter" + }, + "frontMatter.taxonomy.modifiedField": { + "type": "string", + "default": "lastmod", + "description": "Specifies the modified date field name to use in your Front Matter" + }, "frontMatter.taxonomy.tags": { "type": "array", "description": "Specifies the tags which can be used in the Front Matter" diff --git a/src/commands/Article.ts b/src/commands/Article.ts index 3fa0ae88..e42a9ac4 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -1,6 +1,7 @@ +import { SETTING_MODIFIED_FIELD } from './../constants/settings'; import * as vscode from 'vscode'; import { TaxonomyType } from "../models"; -import { CONFIG_KEY, SETTING_DATE_FORMAT, EXTENSION_NAME, SETTING_SLUG_PREFIX, SETTING_SLUG_SUFFIX } from "../constants/settings"; +import { CONFIG_KEY, SETTING_DATE_FORMAT, EXTENSION_NAME, SETTING_SLUG_PREFIX, SETTING_SLUG_SUFFIX, SETTING_DATE_FIELD } from "../constants/settings"; import { format } from "date-fns"; import { ArticleHelper, SettingsHelper } from '../helpers'; @@ -83,11 +84,12 @@ export class Article { } const dateFormat = config.get(SETTING_DATE_FORMAT) as string; + const dateField = config.get(SETTING_DATE_FIELD) as string || "date"; try { if (dateFormat && typeof dateFormat === "string") { - article.data["date"] = format(new Date(), dateFormat); + article.data[dateField] = format(new Date(), dateFormat); } else { - article.data["date"] = new Date(); + article.data[dateField] = new Date(); } ArticleHelper.update(editor, article); @@ -113,11 +115,12 @@ export class Article { } const dateFormat = config.get(SETTING_DATE_FORMAT) as string; + const dateField = config.get(SETTING_MODIFIED_FIELD) as string || "lastmod"; try { if (dateFormat && typeof dateFormat === "string") { - article.data["lastmod"] = format(new Date(), dateFormat); + article.data[dateField] = format(new Date(), dateFormat); } else { - article.data["lastmod"] = new Date(); + article.data[dateField] = new Date(); } ArticleHelper.update(editor, article); diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 1f931c70..2dc6230d 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -5,6 +5,8 @@ export const CONFIG_KEY = "frontMatter"; export const SETTING_TAXONOMY_TAGS = "taxonomy.tags"; export const SETTING_TAXONOMY_CATEGORIES = "taxonomy.categories"; export const SETTING_DATE_FORMAT = "taxonomy.dateFormat"; +export const SETTING_DATE_FIELD = "taxonomy.dateField"; +export const SETTING_MODIFIED_FIELD = "taxonomy.modifiedField"; export const SETTING_SLUG_PREFIX = "taxonomy.slugPrefix"; export const SETTING_SLUG_SUFFIX = "taxonomy.slugSuffix";