diff --git a/src/commands/Article.ts b/src/commands/Article.ts index 349c3182..1848054a 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -150,7 +150,8 @@ export class Article { ): ParsedFrontMatter | undefined { const article = ArticleHelper.getFrontMatterFromDocument(document); - if (!article) { + // Only set the date, if there is already front matter set + if (!article || !article.data || Object.keys(article.data).length === 0) { return; } diff --git a/src/hooks/useContentType.tsx b/src/hooks/useContentType.tsx index 5ca5951f..02111a63 100644 --- a/src/hooks/useContentType.tsx +++ b/src/hooks/useContentType.tsx @@ -1,10 +1,10 @@ import { useState, useEffect, useCallback, useMemo } from 'react'; import { DEFAULT_CONTENT_TYPE, DEFAULT_CONTENT_TYPE_NAME } from '../constants/ContentType'; import { Settings } from '../dashboardWebView/models'; -import { ContentType, Field, PanelSettings } from '../models'; +import { ContentType, PanelSettings } from '../models'; export default function useContentType(settings: PanelSettings | Settings | undefined | null, metadata: any) { - const [contentType, setContentType] = useState(DEFAULT_CONTENT_TYPE); + const [contentType, setContentType] = useState(null); useEffect(() => { if (settings) { diff --git a/src/listeners/panel/DataListener.ts b/src/listeners/panel/DataListener.ts index cf3af34e..4fd9a5c9 100644 --- a/src/listeners/panel/DataListener.ts +++ b/src/listeners/panel/DataListener.ts @@ -134,7 +134,7 @@ export class DataListener extends BaseListener { } const article = ArticleHelper.getFrontMatter(editor); - if (!article || !article.data || Object.keys(article.data).length === 0) { + if (!article) { return; } diff --git a/src/panelWebView/components/Fields/WrapperField.tsx b/src/panelWebView/components/Fields/WrapperField.tsx index 728373a7..d723f60d 100644 --- a/src/panelWebView/components/Fields/WrapperField.tsx +++ b/src/panelWebView/components/Fields/WrapperField.tsx @@ -84,10 +84,14 @@ export const WrapperField: React.FunctionComponent = ({ value = field.default; if (field.type === 'datetime') { + if (value === "{{now}}") { + value = new Date(); + } + value = getDate(value) || null; } - onSendUpdate(field.name, value, parentFields); + //onSendUpdate(field.name, value, parentFields); } // Check if the field value contains a placeholder diff --git a/src/panelWebView/components/Metadata.tsx b/src/panelWebView/components/Metadata.tsx index f055be8c..bae2b7a1 100644 --- a/src/panelWebView/components/Metadata.tsx +++ b/src/panelWebView/components/Metadata.tsx @@ -82,7 +82,7 @@ const Metadata: React.FunctionComponent = ({settings, metadata, { - renderFields(contentType?.fields, metadata) + renderFields(contentType?.fields || [], metadata) } {