diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c93f2d4c..6c9010c5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,6 +12,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -23,16 +24,11 @@ A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] +**Device:** -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] +- OS: [e.g. iOS] +- Front Matter CMS Version [e.g. 10.2.0] +- Browser [e.g. chrome, safari] **Additional context** Add any other context about the problem here. diff --git a/.vscode/launch.json b/.vscode/launch.json index 03fa15a5..6fd45c2d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,9 @@ "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", - "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", "--disable-extension=eliostruyf.vscode-front-matter" + ], "outFiles": ["${workspaceFolder}/dist/**/*.js"], "preLaunchTask": "npm: build:ext" }, @@ -19,7 +21,9 @@ "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", - "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", "--disable-extension=eliostruyf.vscode-front-matter" + ], "outFiles": ["${workspaceFolder}/dist/**/*.js"] } ] diff --git a/.vscode/settings.json b/.vscode/settings.json index c2383302..24f5c98b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,15 @@ // Place your settings in this file to overwrite default and user settings. { + "commitHelper.messages": [ + { + "type": "👨‍💻 apps", + "values": ["#search", "#profile"] + }, + { + "type": "⚙️ tasks", + "values": ["#build", "#deploy", "#skip"] + } + ], "workbench.colorCustomizations": { "titleBar.activeBackground": "#15c2cb", "titleBar.inactiveBackground": "#44ffd299", diff --git a/CHANGELOG.md b/CHANGELOG.md index c0bf402f..6098947d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [10.2.0] - 2024-xx-xx +## [10.2.0] - 2024-06-12 - [Release notes](https://beta.frontmatter.codes/updates/v10.2.0) ### ✨ New features @@ -9,15 +9,15 @@ ### 🎨 Enhancements - [#441](https://github.com/estruyf/vscode-front-matter/issues/441): Show input descriptions for snippet and data forms -- [#442](https://github.com/estruyf/vscode-front-matter/issues/442): Hide sidebar on data view when data file is selecte + show dropdown of data files +- [#442](https://github.com/estruyf/vscode-front-matter/issues/442): Hide sidebar on data view when data file is selected + show dropdown of data files - [#788](https://github.com/estruyf/vscode-front-matter/issues/788): Show a warning on setting update when it exists in an extended configuration - [#798](https://github.com/estruyf/vscode-front-matter/issues/798): Changed dialog to slide-over for the snippet forms -- [#799](https://github.com/estruyf/vscode-front-matter/issues/799): Added `frontMatter.logging` setting to define the logging output. Options are `info`, `warn`, `error`, and `verbose`. Default is `info`. +- [#799](https://github.com/estruyf/vscode-front-matter/issues/799): Added `frontMatter.logging` setting to define the logging output. Options are `info`, `warn`, `error`, and `verbose`. The default is `info`. - [#800](https://github.com/estruyf/vscode-front-matter/issues/800): Add colors for the Front Matter CMS output - [#808](https://github.com/estruyf/vscode-front-matter/issues/808): Add support to generate field groups and `block` fields in content type generation - [#810](https://github.com/estruyf/vscode-front-matter/issues/810): Update the tab title based on the view - [#811](https://github.com/estruyf/vscode-front-matter/issues/811): Added `panel.gitActions` view mode option to hide the Git actions in the panel -- [#812](https://github.com/estruyf/vscode-front-matter/issues/812): Added the `{{locale}}` placeholder which can be used in the `previewPath` property +- [#812](https://github.com/estruyf/vscode-front-matter/issues/812): Added the `{{locale}}` placeholder, which can be used in the `previewPath` property ### ⚡️ Optimizations diff --git a/package.json b/package.json index b6529f63..0784479f 100644 --- a/package.json +++ b/package.json @@ -1176,7 +1176,7 @@ "scope": "Site preview" }, "frontMatter.preview.trailingSlash": { - "type": "string", + "type": "boolean", "default": "", "markdownDescription": "%setting.frontMatter.preview.trailingSlash.markdownDescription%", "scope": "Site preview" diff --git a/src/commands/Article.ts b/src/commands/Article.ts index dc536f57..ffb19993 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -27,6 +27,7 @@ import { CustomPlaceholder, Field } from '../models'; import { format } from 'date-fns'; import { ArticleHelper, + Logger, Settings, SlugHelper, processArticlePlaceholdersFromData, @@ -133,6 +134,7 @@ export class Article { private static async setLastModifiedDateInner( document: TextDocument ): Promise { + Logger.verbose(`Article:setLastModifiedDateInner:Start`); const article = ArticleHelper.getFrontMatterFromDocument(document); // Only set the date, if there is already front matter set @@ -142,9 +144,16 @@ export class Article { const cloneArticle = Object.assign({}, article); const dateField = await ArticleHelper.getModifiedDateField(article); + Logger.verbose(`Article:setLastModifiedDateInner:DateField - ${JSON.stringify(dateField)}`); + try { const fieldName = dateField?.name || DefaultFields.LastModified; - cloneArticle.data[fieldName] = Article.formatDate(new Date(), dateField?.dateFormat); + const fieldValue = Article.formatDate(new Date(), dateField?.dateFormat); + cloneArticle.data[fieldName] = fieldValue; + Logger.verbose( + `Article:setLastModifiedDateInner:DateField name - ${fieldName} - value - ${fieldValue}` + ); + Logger.verbose(`Article:setLastModifiedDateInner:End`); return cloneArticle; } catch (e: unknown) { Notifications.error( @@ -352,7 +361,7 @@ export class Article { const autoUpdate = Settings.get(SETTING_AUTO_UPDATE_DATE); // Is article located in one of the content folders - const folders = await Folders.get(); + const folders = Folders.getCached(); const documentPath = parseWinPath(document.fileName); const folder = folders.find((f) => documentPath.startsWith(f.path)); if (!folder) { @@ -371,11 +380,16 @@ export class Article { public static formatDate(dateValue: Date, fieldDateFormat?: string): string { const dateFormat = Settings.get(SETTING_DATE_FORMAT) as string; + Logger.verbose(`Article:formatDate:Start`); + if (fieldDateFormat) { + Logger.verbose(`Article:formatDate:FieldDateFormat - ${fieldDateFormat}`); return format(dateValue, DateHelper.formatUpdate(fieldDateFormat) as string); } else if (dateFormat && typeof dateFormat === 'string') { + Logger.verbose(`Article:formatDate:DateFormat - ${dateFormat}`); return format(dateValue, DateHelper.formatUpdate(dateFormat) as string); } else { + Logger.verbose(`Article:formatDate:toISOString - ${dateValue}`); return typeof dateValue.toISOString === 'function' ? dateValue.toISOString() : dateValue?.toString(); diff --git a/src/commands/Diagnostics.ts b/src/commands/Diagnostics.ts index 8268dbd6..147c063c 100644 --- a/src/commands/Diagnostics.ts +++ b/src/commands/Diagnostics.ts @@ -33,7 +33,10 @@ export class Diagnostics { const fileTypes = Diagnostics.getFileTypes(); - const logging = `# Front Matter CMS - Diagnostics + const logging = `# ${Extension.getInstance().displayName} - Diagnostics + +Beta: \`${Extension.getInstance().isBetaVersion()}\` +Version: \`${Extension.getInstance().version}\` ## Project name diff --git a/src/commands/Folders.ts b/src/commands/Folders.ts index 89df4710..e2efee57 100644 --- a/src/commands/Folders.ts +++ b/src/commands/Folders.ts @@ -448,6 +448,14 @@ export class Folders { return Folders._folders; } + /** + * Get the cached folder settings + * @returns {ContentFolder[]} - The cached folder settings + */ + public static getCached(): ContentFolder[] { + return Folders._folders; + } + /** * Update the folder settings * @param folders diff --git a/src/commands/Preview.ts b/src/commands/Preview.ts index 568b5e61..0072ad4b 100644 --- a/src/commands/Preview.ts +++ b/src/commands/Preview.ts @@ -13,7 +13,6 @@ import { join, parse } from 'path'; import { commands, env, Uri, ViewColumn, window, WebviewPanel, extensions } from 'vscode'; import { ArticleHelper, - DateHelper, Extension, parseWinPath, processI18nPlaceholders, @@ -21,10 +20,10 @@ import { processFmPlaceholders, processPathPlaceholders, Settings, - Telemetry + Telemetry, + processDateTimePlaceholders } from '../helpers'; import { ContentFolder, ContentType, PreviewSettings } from '../models'; -import { format } from 'date-fns'; import { Article } from '.'; import { WebviewHelper } from '@estruyf/vscode'; import { Folders } from './Folders'; @@ -33,6 +32,7 @@ import { getLocalizationFile } from '../utils/getLocalizationFile'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../localization'; import { joinUrl } from '../utils'; +import { i18n } from './i18n'; export class Preview { public static filePath: string | undefined = undefined; @@ -250,9 +250,7 @@ export class Preview { // Check if there is a pathname defined on content folder level const folders = await Folders.get(); if (folders.length > 0) { - const foldersWithPath = folders.filter((folder) => folder.previewPath); - - for (const folder of foldersWithPath) { + for (const folder of folders) { const folderPath = parseWinPath(folder.path); if (filePath.startsWith(folderPath)) { if (!selectedFolder || selectedFolder.path.length < folderPath.length) { @@ -298,6 +296,11 @@ export class Preview { slug = Article.getSlug(); } + const locale = await i18n.getLocale(filePath); + if (locale && locale.path === slug) { + slug = ''; + } + if (pathname) { // Known placeholders const dateFormat = Settings.get(SETTING_DATE_FORMAT) as string; @@ -336,10 +339,8 @@ export class Preview { try { const articleDate = await ArticleHelper.getDate(article); - slug = join( - format(articleDate || new Date(), DateHelper.formatUpdate(pathname) as string), - slug - ); + pathname = processDateTimePlaceholders(pathname, dateFormat, articleDate); + slug = join(pathname, slug); } catch (error) { slug = join(pathname, slug); } diff --git a/src/constants/DefaultFeatureFlags.ts b/src/constants/DefaultFeatureFlags.ts new file mode 100644 index 00000000..28e43bf7 --- /dev/null +++ b/src/constants/DefaultFeatureFlags.ts @@ -0,0 +1,12 @@ +import { FEATURE_FLAG } from './Features'; + +export const DEFAULT_PANEL_FEATURE_FLAGS = Object.values(FEATURE_FLAG.panel).filter( + (v) => v !== FEATURE_FLAG.panel.globalSettings +); + +export const DEFAULT_DASHBOARD_FEATURE_FLAGS = [ + FEATURE_FLAG.dashboard.data.view, + FEATURE_FLAG.dashboard.taxonomy.view, + FEATURE_FLAG.dashboard.snippets.view, + FEATURE_FLAG.dashboard.snippets.manage +]; diff --git a/src/dashboardWebView/components/Header/Tabs.tsx b/src/dashboardWebView/components/Header/Tabs.tsx index 18870588..bfd984c9 100644 --- a/src/dashboardWebView/components/Header/Tabs.tsx +++ b/src/dashboardWebView/components/Header/Tabs.tsx @@ -9,6 +9,7 @@ import { Tab } from './Tab'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; import { PageIcon } from '../../../panelWebView/components/Icons'; +import { DEFAULT_DASHBOARD_FEATURE_FLAGS } from '../../../constants/DefaultFeatureFlags'; export interface ITabsProps { onNavigate: (navigationType: NavigationType) => void; @@ -19,12 +20,6 @@ export const Tabs: React.FunctionComponent = ({ }: React.PropsWithChildren) => { const mode = useRecoilValue(ModeAtom); - const allDashboardVIews = [ - FEATURE_FLAG.dashboard.snippets.view, - FEATURE_FLAG.dashboard.data.view, - FEATURE_FLAG.dashboard.taxonomy.view - ]; - return (
    = ({ {l10n.t(LocalizationKey.dashboardHeaderTabsMedia)} - +
  • @@ -51,7 +46,7 @@ export const Tabs: React.FunctionComponent = ({
  • - +
  • @@ -59,7 +54,7 @@ export const Tabs: React.FunctionComponent = ({
  • - +
  • diff --git a/src/dashboardWebView/components/SnippetsView/Item.tsx b/src/dashboardWebView/components/SnippetsView/Item.tsx index b3473af7..ec82a2b6 100644 --- a/src/dashboardWebView/components/SnippetsView/Item.tsx +++ b/src/dashboardWebView/components/SnippetsView/Item.tsx @@ -19,6 +19,7 @@ import { LocalizationKey } from '../../../localization'; import { FooterActions } from './FooterActions'; import { ItemMenu } from './ItemMenu'; import { SlideOver } from '../Modals/SlideOver'; +import { DEFAULT_DASHBOARD_FEATURE_FLAGS } from '../../../constants/DefaultFeatureFlags'; export interface IItemProps { snippetKey: string; @@ -163,7 +164,7 @@ export const Item: React.FunctionComponent = ({ = ({ = ( return ( +
    { + if (value && typeof value === 'string') { + if (value.includes(`{{date|`)) { + const regex = /{{date\|[^}]*}}/g; + const matches = value.match(regex); + if (matches) { + for (const match of matches) { + const placeholderParts = match.split('|'); + if (placeholderParts.length > 1) { + let dateFormat = placeholderParts[1].trim().replace('}}', ''); + + if (dateFormat) { + if (dateFormat && typeof dateFormat === 'string') { + value = value.replace( + match, + format(articleDate || new Date(), DateHelper.formatUpdate(dateFormat) as string) + ); + } else { + value = value.replace(match, (articleDate || new Date()).toISOString()); + } + } + } + } + } + } + } + + return value; +}; diff --git a/src/helpers/processTimePlaceholders.ts b/src/helpers/processTimePlaceholders.ts index 33ca60f7..1bcb8898 100644 --- a/src/helpers/processTimePlaceholders.ts +++ b/src/helpers/processTimePlaceholders.ts @@ -4,10 +4,10 @@ import { DateHelper } from './DateHelper'; /** * Replace the time placeholders * @param value - * @param title + * @param dateFormat * @returns */ -export const processTimePlaceholders = (value: string, dateFormat?: string) => { +export const processTimePlaceholders = (value: string, dateFormat?: string, articleDate?: Date) => { if (value && typeof value === 'string') { if (value.includes('{{now}}')) { const regex = new RegExp('{{now}}', 'g'); @@ -15,46 +15,46 @@ export const processTimePlaceholders = (value: string, dateFormat?: string) => { if (dateFormat && typeof dateFormat === 'string') { value = value.replace( regex, - format(new Date(), DateHelper.formatUpdate(dateFormat) as string) + format(articleDate || new Date(), DateHelper.formatUpdate(dateFormat) as string) ); } else { - value = value.replace(regex, new Date().toISOString()); + value = value.replace(regex, (articleDate || new Date()).toISOString()); } } if (value.includes('{{year}}')) { const regex = new RegExp('{{year}}', 'g'); - value = value.replace(regex, format(new Date(), 'yyyy')); + value = value.replace(regex, format(articleDate || new Date(), 'yyyy')); } if (value.includes('{{month}}')) { const regex = new RegExp('{{month}}', 'g'); - value = value.replace(regex, format(new Date(), 'MM')); + value = value.replace(regex, format(articleDate || new Date(), 'MM')); } if (value.includes('{{day}}')) { const regex = new RegExp('{{day}}', 'g'); - value = value.replace(regex, format(new Date(), 'dd')); + value = value.replace(regex, format(articleDate || new Date(), 'dd')); } if (value.includes('{{hour12}}')) { const regex = new RegExp('{{hour12}}', 'g'); - value = value.replace(regex, format(new Date(), 'hh')); + value = value.replace(regex, format(articleDate || new Date(), 'hh')); } if (value.includes('{{hour24}}')) { const regex = new RegExp('{{hour24}}', 'g'); - value = value.replace(regex, format(new Date(), 'HH')); + value = value.replace(regex, format(articleDate || new Date(), 'HH')); } if (value.includes('{{ampm}}')) { const regex = new RegExp('{{ampm}}', 'g'); - value = value.replace(regex, format(new Date(), 'aaa')); + value = value.replace(regex, format(articleDate || new Date(), 'aaa')); } if (value.includes('{{minute}}')) { const regex = new RegExp('{{minute}}', 'g'); - value = value.replace(regex, format(new Date(), 'mm')); + value = value.replace(regex, format(articleDate || new Date(), 'mm')); } } diff --git a/src/listeners/dashboard/PagesListener.ts b/src/listeners/dashboard/PagesListener.ts index 56b75a66..26d12e22 100644 --- a/src/listeners/dashboard/PagesListener.ts +++ b/src/listeners/dashboard/PagesListener.ts @@ -71,7 +71,7 @@ export class PagesListener extends BaseListener { // Optimize the list of recently changed files DataListener.getFoldersAndFiles(doc.uri); // Trigger the metadata update - this.watcherExec(doc.uri); + this.watcherExec(doc.uri, 'save'); } }); } @@ -103,9 +103,9 @@ export class PagesListener extends BaseListener { false, false ); - watcher.onDidCreate(async (uri: Uri) => this.watcherExec(uri)); - watcher.onDidChange(async (uri: Uri) => this.watcherExec(uri)); - watcher.onDidDelete(async (uri: Uri) => this.watcherExec(uri)); + watcher.onDidCreate(async (uri: Uri) => this.watcherExec(uri, 'create')); + watcher.onDidChange(async (uri: Uri) => this.watcherExec(uri, 'change')); + watcher.onDidDelete(async (uri: Uri) => this.watcherExec(uri, 'delete')); this.watchers[folderUri.fsPath] = watcher; } } @@ -162,10 +162,10 @@ export class PagesListener extends BaseListener { * Watcher for processing page updates * @param file */ - private static async watcherExec(file: Uri) { + private static async watcherExec(file: Uri, type?: 'create' | 'change' | 'delete' | 'save') { const progressFile = async (file: Uri) => { const ext = Extension.getInstance(); - Logger.info(`File watcher execution for: ${file.fsPath}`); + Logger.info(`File watcher execution for (${type}): ${file.fsPath}`); const pageIdx = this.lastPages.findIndex((p) => p.fmFilePath === file.fsPath); if (pageIdx !== -1) { diff --git a/src/panelWebView/ViewPanel.tsx b/src/panelWebView/ViewPanel.tsx index 67a4bf25..44f306f4 100644 --- a/src/panelWebView/ViewPanel.tsx +++ b/src/panelWebView/ViewPanel.tsx @@ -17,6 +17,7 @@ import { usePrevious } from './hooks/usePrevious'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../localization'; import { InitializeAction } from './components/InitializeAction'; +import { DEFAULT_PANEL_FEATURE_FLAGS } from '../constants/DefaultFeatureFlags'; export interface IViewPanelProps { } @@ -37,10 +38,6 @@ export const ViewPanel: React.FunctionComponent = ( const prevMediaSelection = usePrevious(mediaSelecting); const [scrollY, setScrollY] = useState(0); - const allPanelValues = useMemo(() => { - return Object.values(FEATURE_FLAG.panel).filter(v => v !== FEATURE_FLAG.panel.globalSettings) - }, [FEATURE_FLAG.panel]); - const scollListener = useCallback((e: Event) => { if (!mediaSelecting) { setScrollY(window.scrollY); @@ -48,7 +45,7 @@ export const ViewPanel: React.FunctionComponent = ( }, [mediaSelecting]); const isSomethingShown = useMemo(() => { - const panelModeValues = (mode?.features || [...allPanelValues]).filter(v => v.startsWith('panel.')); + const panelModeValues = (mode?.features || DEFAULT_PANEL_FEATURE_FLAGS).filter(v => v.startsWith('panel.')); if (panelModeValues.length === 0) { return false; @@ -125,19 +122,19 @@ export const ViewPanel: React.FunctionComponent = (
    - + {!loading && ()} - + { !loading && metadata && settings && settings.seo && ( - + = ( } {!loading && settings && ( - + = ( { !loading && metadata && ( - + ) } - + - + diff --git a/src/panelWebView/components/Metadata.tsx b/src/panelWebView/components/Metadata.tsx index 843e498d..68bf484f 100644 --- a/src/panelWebView/components/Metadata.tsx +++ b/src/panelWebView/components/Metadata.tsx @@ -12,6 +12,7 @@ import { FEATURE_FLAG, GeneralCommands } from '../../constants'; import { Messenger } from '@estruyf/vscode/dist/client'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../localization'; +import { DEFAULT_PANEL_FEATURE_FLAGS } from '../../constants/DefaultFeatureFlags'; export interface IMetadata { [prop: string]: string[] | string | null | IMetadata; @@ -95,7 +96,7 @@ const Metadata: React.FunctionComponent = ({ id={`tags`} title={`${l10n.t(LocalizationKey.panelMetadataTitle)}${contentType?.name ? ` (${contentType?.name})` : ""}`} className={`inherit z-20`}> - +