From 78002563be0ae5b813b84f185bece1ed43752865 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 3 Oct 2022 13:22:40 +0200 Subject: [PATCH] Clear cache command --- package.json | 5 ++++ src/commands/Cache.ts | 24 +++++++++++++++++++ src/commands/index.ts | 10 ++++++++ src/constants/Extension.ts | 3 +++ .../components/Contents/Item.tsx | 4 ++-- src/extension.ts | 4 ++++ src/services/PagesParser.ts | 14 +++++++++-- 7 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/commands/Cache.ts diff --git a/package.json b/package.json index 70f986d1..d67f9d0d 100644 --- a/package.json +++ b/package.json @@ -1742,6 +1742,11 @@ "command": "frontMatter.git.sync", "title": "Sync", "category": "Front Matter" + }, + { + "command": "frontMatter.cache.clear", + "title": "Clear cache", + "category": "Front Matter" } ], "menus": { diff --git a/src/commands/Cache.ts b/src/commands/Cache.ts new file mode 100644 index 00000000..5175f5b8 --- /dev/null +++ b/src/commands/Cache.ts @@ -0,0 +1,24 @@ +import { commands } from "vscode"; +import { COMMAND_NAME, ExtensionState } from "../constants"; +import { Extension, Notifications } from "../helpers"; + +export class Cache { + + public static async registerCommands() { + const ext = Extension.getInstance(); + const subscriptions = ext.subscriptions; + + subscriptions.push( + commands.registerCommand(COMMAND_NAME.clearCache, Cache.clear) + ); + } + + private static async clear() { + const ext = Extension.getInstance(); + + await ext.setState(ExtensionState.Dashboard.Pages.Cache, undefined, "workspace"); + await ext.setState(ExtensionState.Dashboard.Pages.Index, undefined, "workspace"); + + Notifications.info("Cache cleared"); + } +} \ No newline at end of file diff --git a/src/commands/index.ts b/src/commands/index.ts index d5aa6bdc..7c391ede 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,3 +1,13 @@ export * from './Article'; +export * from './Backers'; +export * from './Cache'; +export * from './Content'; +export * from './Dashboard'; +export * from './Diagnostics'; +export * from './Folders'; +export * from './Preview'; +export * from './Project'; export * from './Settings'; export * from './StatusListener'; +export * from './Template'; +export * from './Wysiwyg'; diff --git a/src/constants/Extension.ts b/src/constants/Extension.ts index 6e0eb252..4dc68df7 100644 --- a/src/constants/Extension.ts +++ b/src/constants/Extension.ts @@ -72,4 +72,7 @@ export const COMMAND_NAME = { // Config reloadConfig: getCommandName("config.reload"), + + // Cache + clearCache: getCommandName("cache.clear"), }; \ No newline at end of file diff --git a/src/dashboardWebView/components/Contents/Item.tsx b/src/dashboardWebView/components/Contents/Item.tsx index 3f140774..2b7f3d4a 100644 --- a/src/dashboardWebView/components/Contents/Item.tsx +++ b/src/dashboardWebView/components/Contents/Item.tsx @@ -95,9 +95,9 @@ export const Item: React.FunctionComponent = ({ fmFilePath, date, ti onOpen={openFile} /> - + - + { tags && tags.length > 0 && ( diff --git a/src/extension.ts b/src/extension.ts index f949b35c..40ec3644 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,6 +8,7 @@ import { Folders } from './commands/Folders'; import { Preview } from './commands/Preview'; import { Project } from './commands/Project'; import { Template } from './commands/Template'; +import { Cache } from './commands/Cache'; import { COMMAND_NAME, TelemetryEvent } from './constants'; import { TaxonomyType } from './models'; import { MarkdownFoldingProvider } from './providers/MarkdownFoldingProvider'; @@ -271,6 +272,9 @@ export async function activate(context: vscode.ExtensionContext) { DashboardSettings.get(); PagesParser.start(); + // Cache commands + Cache.registerCommands(); + // Subscribe all commands subscriptions.push( insertTags, diff --git a/src/services/PagesParser.ts b/src/services/PagesParser.ts index 4a7bb6c6..7c50b787 100644 --- a/src/services/PagesParser.ts +++ b/src/services/PagesParser.ts @@ -138,6 +138,16 @@ export class PagesParser { const staticFolder = Folders.getStaticFolderRelativePath(); + let escapedTitle = article?.data.title; + if (escapedTitle && typeof escapedTitle !== "string") { + escapedTitle = ""; + } + + let escapedDescription = article?.data[descriptionField] || ""; + if (escapedDescription && typeof escapedDescription !== "string") { + escapedDescription = ""; + } + const page: Page = { ...article.data, // Cache properties @@ -157,11 +167,11 @@ export class PagesParser { fmContentType: DEFAULT_CONTENT_TYPE_NAME, fmBody: article?.content || "", // Make sure these are always set - title: article?.data.title, + title: escapedTitle, slug: article?.data.slug, date: article?.data[dateField] || "", draft: article?.data.draft, - description: article?.data[descriptionField] || "", + description: escapedDescription, }; const contentType = ArticleHelper.getContentType(article.data);