mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 09:23:00 +02:00
#18 - Updates to support custom fields
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user