diff --git a/CHANGELOG.md b/CHANGELOG.md index f7004412..7c22c3ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Change Log -## [X.X.X] - 2021-11-XX +## [5.4.0] - 2021-11-XX ### 🎨 Enhancements - [#166](https://github.com/estruyf/vscode-front-matter/issues/166): Added preview button to the panel base view +- [#167](https://github.com/estruyf/vscode-front-matter/issues/167): Allow to set the preview path per content type ## [5.3.1] - 2021-10-29 diff --git a/package.json b/package.json index 38d4b88b..0f536977 100644 --- a/package.json +++ b/package.json @@ -384,6 +384,14 @@ "type": "boolean", "default": false, "description": "Specify if you want to create a folder when creating new content." + }, + "previewPath": { + "type": [ + "null", + "string" + ], + "default": null, + "description": "Defines a custom preview path for the content type." } }, "additionalProperties": false, diff --git a/src/commands/Preview.ts b/src/commands/Preview.ts index 100a0c9e..4b559335 100644 --- a/src/commands/Preview.ts +++ b/src/commands/Preview.ts @@ -34,16 +34,25 @@ export class Preview { const article = editor ? ArticleHelper.getFrontMatter(editor) : null; let slug = article?.data ? article.data.slug : ""; + let pathname = settings.pathname; + if (article?.data) { + const contentType = ArticleHelper.getContentType(article.data); + if (contentType && contentType.previewPath) { + pathname = contentType.previewPath; + } + } + if (!slug) { slug = Article.getSlug(); } - if (settings.pathname) { + if (pathname) { const articleDate = ArticleHelper.getDate(article); + try { - slug = join(format(articleDate || new Date(), DateHelper.formatUpdate(settings.pathname) as string), slug); + slug = join(format(articleDate || new Date(), DateHelper.formatUpdate(pathname) as string), slug); } catch (error) { - slug = join(settings.pathname, slug); + slug = join(pathname, slug); } } diff --git a/src/constants/ContentType.ts b/src/constants/ContentType.ts index 5f243b15..daf1e852 100644 --- a/src/constants/ContentType.ts +++ b/src/constants/ContentType.ts @@ -5,6 +5,7 @@ export const DEFAULT_CONTENT_TYPE_NAME = 'default'; export const DEFAULT_CONTENT_TYPE: ContentType = { "name": "default", "pageBundle": false, + "previewPath": null, "fields": [ { "title": "Title", diff --git a/src/models/PanelSettings.ts b/src/models/PanelSettings.ts index 86c52ac3..1c571046 100644 --- a/src/models/PanelSettings.ts +++ b/src/models/PanelSettings.ts @@ -25,6 +25,7 @@ export interface ContentType { name: string; fields: Field[]; + previewPath?: string | null; pageBundle?: boolean; }