mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-12 03:43:01 +02:00
#569 - Remove folder when using page bundle
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
- [#558](https://github.com/estruyf/vscode-front-matter/issues/558): Moved the tags and categories to a `.frontmatter/database/taxonomyDb.json` file
|
||||
- [#566](https://github.com/estruyf/vscode-front-matter/issues/566): Keep the panel context on the live preview
|
||||
- [#568](https://github.com/estruyf/vscode-front-matter/issues/568): Update the preview URL if the slug changes
|
||||
- [#569](https://github.com/estruyf/vscode-front-matter/issues/569): Remove the page bundle folder on content removal
|
||||
- [#586](https://github.com/estruyf/vscode-front-matter/issues/586): Allow to specify the content card fields
|
||||
- [#588](https://github.com/estruyf/vscode-front-matter/issues/588): Added extensibility support to override card fields
|
||||
- [#591](https://github.com/estruyf/vscode-front-matter/issues/591): Support for date format in the `datetime` field
|
||||
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
import { DashboardCommand } from '../../dashboardWebView/DashboardCommand';
|
||||
import { DashboardMessage } from '../../dashboardWebView/DashboardMessage';
|
||||
import { Page } from '../../dashboardWebView/models';
|
||||
import { ArticleHelper, Extension, Logger, Settings } from '../../helpers';
|
||||
import { ArticleHelper, Extension, Logger, parseWinPath, Settings } from '../../helpers';
|
||||
import { BaseListener } from './BaseListener';
|
||||
import { DataListener } from '../panel';
|
||||
import Fuse from 'fuse.js';
|
||||
import { PagesParser } from '../../services/PagesParser';
|
||||
import { unlinkAsync } from '../../utils';
|
||||
import { unlinkAsync, rmdirAsync } from '../../utils';
|
||||
|
||||
export class PagesListener extends BaseListener {
|
||||
private static watchers: { [path: string]: FileSystemWatcher } = {};
|
||||
@@ -114,10 +114,38 @@ export class PagesListener extends BaseListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the content type of the page
|
||||
const article = await ArticleHelper.getFrontMatterByPath(path);
|
||||
if (!article) {
|
||||
return;
|
||||
}
|
||||
const contentType = ArticleHelper.getContentType(article.data);
|
||||
|
||||
Logger.info(`Deleting file: ${path}`);
|
||||
|
||||
await unlinkAsync(path);
|
||||
|
||||
// Check if the content type is a page bundle
|
||||
if (contentType.pageBundle) {
|
||||
const absPath = parseWinPath(path);
|
||||
const folder = absPath.substring(0, absPath.lastIndexOf('/') + 1);
|
||||
try {
|
||||
// Check if the folder is empty
|
||||
const files = await workspace.fs.readDirectory(Uri.file(folder));
|
||||
if (files.length > 0) {
|
||||
// Remove each file
|
||||
for (const file of files) {
|
||||
await unlinkAsync(`${folder}${file[0]}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the folder
|
||||
await rmdirAsync(folder);
|
||||
} catch (e) {
|
||||
console.log((e as any).message);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastPages = this.lastPages.filter((p) => p.fmFilePath !== path);
|
||||
this.sendPageData(this.lastPages);
|
||||
|
||||
|
||||
@@ -7,5 +7,6 @@ export * from './mkdirAsync';
|
||||
export * from './readFileAsync';
|
||||
export * from './readdirAsync';
|
||||
export * from './renameAsync';
|
||||
export * from './rmdirAsync';
|
||||
export * from './unlinkAsync';
|
||||
export * from './writeFileAsync';
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { promisify } from 'util';
|
||||
import { rmdir as rmdirCb } from 'fs';
|
||||
|
||||
export const rmdirAsync = promisify(rmdirCb);
|
||||
Reference in New Issue
Block a user