#158 - Update boolean field check

This commit is contained in:
Elio Struyf
2021-10-27 11:42:57 +02:00
parent 263ccab311
commit b96722dd69
2 changed files with 24 additions and 13 deletions
+8 -8
View File
@@ -91,12 +91,6 @@
"configuration": {
"title": "Front Matter: use frontmatter.json for shared team settings",
"properties": {
"frontMatter.site.baseURL": {
"type": "string",
"default": "",
"markdownDescription": "Specify the base URL of your site, this will be used for SEO checks. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.site.baseURL)",
"scope": "Site"
},
"frontMatter.content.autoUpdateDate": {
"type": "boolean",
"default": false,
@@ -117,7 +111,7 @@
"boolean",
"choice"
],
"description": "Define the type of field"
"description": ""
},
"name": {
"type": "string",
@@ -262,6 +256,12 @@
"markdownDescription": "Specify the path you want to add after the host and before your slug. This can be used for instance to include the year/month like: `yyyy/MM`. The date will be generated based on the article its date field value. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.preview.pathname)",
"scope": "Site preview"
},
"frontMatter.site.baseURL": {
"type": "string",
"default": "",
"markdownDescription": "Specify the base URL of your site, this will be used for SEO checks. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.site.baseURL)",
"scope": "Site"
},
"frontMatter.taxonomy.alignFilename": {
"type": "boolean",
"default": false,
@@ -783,4 +783,4 @@
"dependencies": {
"@docsearch/js": "^3.0.0-alpha.40"
}
}
}
+16 -5
View File
@@ -7,7 +7,6 @@ import { Questions } from "./Questions";
import { writeFileSync } from "fs";
import { Notifications } from "./Notifications";
import { DEFAULT_CONTENT_TYPE_NAME } from "../constants/ContentType";
import { GrayMatterFile } from "gray-matter";
export class ContentType {
@@ -31,15 +30,27 @@ export class ContentType {
* @returns
*/
public static getDraftStatus(data: { [field: string]: any }) {
const draftField = ContentType.getDraftField();
if (draftField && data && data[draftField.name]) {
const fieldValue = data[draftField.name];
if (draftField.type === "boolean") {
const contentType = ArticleHelper.getContentType(data);
const draftSetting = ContentType.getDraftField();
const draftField = contentType.fields.find(f => f.type === "draft");
let fieldValue = null;
if (draftField) {
fieldValue = data[draftField.name];
} else if (draftSetting && data && data[draftSetting.name]) {
fieldValue = data[draftSetting.name];
}
if (draftSetting && fieldValue) {
if (draftSetting.type === "boolean") {
return fieldValue ? "Draft" : "Published";
} else {
return fieldValue;
}
}
return null;
}