74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// main.ts
|
|
var main_exports = {};
|
|
__export(main_exports, {
|
|
default: () => RemoveEmptyFoldersPlugin
|
|
});
|
|
module.exports = __toCommonJS(main_exports);
|
|
var import_obsidian = require("obsidian");
|
|
var RemoveEmptyFoldersPlugin = class extends import_obsidian.Plugin {
|
|
async onload() {
|
|
this.registerEvent(
|
|
this.app.workspace.on("files-menu", (menu, files) => {
|
|
menu.addItem((item) => {
|
|
item.setTitle("Remove empty folders").onClick(async () => {
|
|
files.forEach((file) => {
|
|
if (file instanceof import_obsidian.TFolder) {
|
|
removeEmptyFolders(this.app, file);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
})
|
|
);
|
|
this.registerEvent(
|
|
this.app.workspace.on("file-menu", (menu, file) => {
|
|
if (file instanceof import_obsidian.TFolder) {
|
|
menu.addItem((item) => {
|
|
item.setTitle("Remove empty folders").onClick(async () => {
|
|
const notice = new import_obsidian.Notice(`Removing empty folders !!`);
|
|
console.log("Removing empty folders !!");
|
|
removeEmptyFolders(this.app, file);
|
|
notice.hide();
|
|
new import_obsidian.Notice(`Empty folders removed !!`);
|
|
console.log("Empty folders removed !!");
|
|
});
|
|
});
|
|
}
|
|
})
|
|
);
|
|
}
|
|
};
|
|
var removeEmptyFolders = (app, folder) => {
|
|
folder.children.forEach((child) => {
|
|
if (child instanceof import_obsidian.TFolder) {
|
|
removeEmptyFolders(app, child);
|
|
}
|
|
});
|
|
if (folder.children.length === 0) {
|
|
app.vault.adapter.trashLocal(folder.path);
|
|
}
|
|
};
|