mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-07 09:23:00 +02:00
Clear cache command
This commit is contained in:
@@ -1742,6 +1742,11 @@
|
||||
"command": "frontMatter.git.sync",
|
||||
"title": "Sync",
|
||||
"category": "Front Matter"
|
||||
},
|
||||
{
|
||||
"command": "frontMatter.cache.clear",
|
||||
"title": "Clear cache",
|
||||
"category": "Front Matter"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
@@ -72,4 +72,7 @@ export const COMMAND_NAME = {
|
||||
|
||||
// Config
|
||||
reloadConfig: getCommandName("config.reload"),
|
||||
|
||||
// Cache
|
||||
clearCache: getCommandName("cache.clear"),
|
||||
};
|
||||
@@ -95,9 +95,9 @@ export const Item: React.FunctionComponent<IItemProps> = ({ fmFilePath, date, ti
|
||||
onOpen={openFile} />
|
||||
</div>
|
||||
|
||||
<button onClick={openFile} className={`text-left`}><h2 className="mt-2 mb-2 font-bold">{escapedTitle}</h2></button>
|
||||
<button onClick={openFile} className={`text-left block`}><h2 className="mt-2 mb-2 font-bold">{escapedTitle}</h2></button>
|
||||
|
||||
<button onClick={openFile} className={`text-left`}><p className="text-xs text-vulcan-200 dark:text-whisper-800">{escapedDescription}</p></button>
|
||||
<button onClick={openFile} className={`text-left block`}><p className="text-xs text-vulcan-200 dark:text-whisper-800">{escapedDescription}</p></button>
|
||||
|
||||
{
|
||||
tags && tags.length > 0 && (
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -138,6 +138,16 @@ export class PagesParser {
|
||||
|
||||
const staticFolder = Folders.getStaticFolderRelativePath();
|
||||
|
||||
let escapedTitle = article?.data.title;
|
||||
if (escapedTitle && typeof escapedTitle !== "string") {
|
||||
escapedTitle = "<invalid title>";
|
||||
}
|
||||
|
||||
let escapedDescription = article?.data[descriptionField] || "";
|
||||
if (escapedDescription && typeof escapedDescription !== "string") {
|
||||
escapedDescription = "<invalid title>";
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user