mirror of
https://github.com/Steffo99/appunti-magistrali.git
synced 2024-11-25 03:34:17 +00:00
149 lines
6.4 KiB
JavaScript
149 lines
6.4 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);
|
|
var __accessCheck = (obj, member, msg) => {
|
|
if (!member.has(obj))
|
|
throw TypeError("Cannot " + msg);
|
|
};
|
|
var __privateGet = (obj, member, getter) => {
|
|
__accessCheck(obj, member, "read from private field");
|
|
return getter ? getter.call(obj) : member.get(obj);
|
|
};
|
|
var __privateAdd = (obj, member, value) => {
|
|
if (member.has(obj))
|
|
throw TypeError("Cannot add the same private member more than once");
|
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
};
|
|
|
|
// main.ts
|
|
var main_exports = {};
|
|
__export(main_exports, {
|
|
default: () => SteffoFileIndexPlugin
|
|
});
|
|
module.exports = __toCommonJS(main_exports);
|
|
var import_obsidian = require("obsidian");
|
|
var _reloadIgnoreRegExpsIfIgnoreFileChangedBinding, _recreateFileIndexBinding;
|
|
var _SteffoFileIndexPlugin = class extends import_obsidian.Plugin {
|
|
constructor() {
|
|
super(...arguments);
|
|
this.ignoreRegExps = [];
|
|
__privateAdd(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding, this.reloadIgnoreRegExpsIfIgnoreFileChanged.bind(this));
|
|
__privateAdd(this, _recreateFileIndexBinding, this.recreateFileIndex.bind(this));
|
|
}
|
|
async reloadIgnoreRegExps() {
|
|
const ignoreFile = this.app.vault.getAbstractFileByPath(_SteffoFileIndexPlugin.FILE_IGNORE_PATH);
|
|
if (ignoreFile === null) {
|
|
console.debug("[SteffoFileIndexPlugin] Ignore file does not exist, not ignoring anything:", _SteffoFileIndexPlugin.FILE_IGNORE_PATH);
|
|
this.ignoreRegExps = [];
|
|
} else if (ignoreFile instanceof import_obsidian.TFolder) {
|
|
console.debug("[SteffoFileIndexPlugin] Ignore file is actually a folder, not ignoring anything:", _SteffoFileIndexPlugin.FILE_IGNORE_PATH);
|
|
this.ignoreRegExps = [];
|
|
} else if (ignoreFile instanceof import_obsidian.TFile) {
|
|
const ignoreJSON = await this.app.vault.cachedRead(ignoreFile);
|
|
const ignoreContents = JSON.parse(ignoreJSON);
|
|
this.ignoreRegExps = ignoreContents.map((re) => new RegExp(re));
|
|
console.debug("[SteffoFileIndexPlugin] Determined ignore list to be:", this.ignoreRegExps);
|
|
} else {
|
|
console.error("[SteffoFileIndexPlugin] Ignore file is of an unknown type, not doing anything:", _SteffoFileIndexPlugin.FILE_IGNORE_PATH);
|
|
}
|
|
}
|
|
async reloadIgnoreRegExpsIfIgnoreFileChanged(file) {
|
|
if (file.path === _SteffoFileIndexPlugin.FILE_IGNORE_PATH) {
|
|
await this.reloadIgnoreRegExps();
|
|
}
|
|
}
|
|
async recreateFileIndex() {
|
|
const files = this.app.vault.getFiles();
|
|
const basenames = {};
|
|
const paths = [];
|
|
for (const file of files) {
|
|
let ignored = false;
|
|
for (const regexp of this.ignoreRegExps) {
|
|
if (file.path.match(regexp)) {
|
|
ignored = true;
|
|
break;
|
|
}
|
|
}
|
|
if (ignored) {
|
|
continue;
|
|
}
|
|
paths.push(file.path);
|
|
const basename = file.basename.toLocaleLowerCase();
|
|
if (basenames.hasOwnProperty(basename)) {
|
|
console.warn("[SteffoFileIndexPlugin] Multiple files with the same basename detected:", basenames[basename], file.path);
|
|
}
|
|
basenames[basename] = file.path;
|
|
}
|
|
paths.sort();
|
|
const index = { basenames, paths };
|
|
console.debug("[SteffoFileIndexPlugin] Determined index to be:", index);
|
|
const indexContents = JSON.stringify(index, null, " ");
|
|
const indexFile = this.app.vault.getAbstractFileByPath(_SteffoFileIndexPlugin.FILE_INDEX_PATH);
|
|
if (indexFile === null) {
|
|
console.debug("[SteffoFileIndexPlugin] File index does not exist, creating it right now at:", _SteffoFileIndexPlugin.FILE_INDEX_PATH);
|
|
await this.app.vault.create(_SteffoFileIndexPlugin.FILE_INDEX_PATH, indexContents);
|
|
} else if (indexFile instanceof import_obsidian.TFolder) {
|
|
console.debug("[SteffoFileIndexPlugin] Cannot create file index, as there's a folder at:", _SteffoFileIndexPlugin.FILE_INDEX_PATH);
|
|
} else if (indexFile instanceof import_obsidian.TFile) {
|
|
console.debug("[SteffoFileIndexPlugin] File index already exists, overwriting contents of:", _SteffoFileIndexPlugin.FILE_INDEX_PATH);
|
|
await this.app.vault.modify(indexFile, indexContents);
|
|
} else {
|
|
console.error("[SteffoFileIndexPlugin] File index is of an unknown type, not doing anything:", _SteffoFileIndexPlugin.FILE_INDEX_PATH);
|
|
}
|
|
}
|
|
async onload() {
|
|
this.addCommand({
|
|
id: "steffo-file-index-recreate",
|
|
name: "Force file index recreation",
|
|
callback: this.recreateFileIndex.bind(this)
|
|
});
|
|
this.app.workspace.onLayoutReady(async () => {
|
|
await this.reloadIgnoreRegExps();
|
|
await this.recreateFileIndex();
|
|
this.registerEvent(
|
|
this.app.vault.on("create", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding))
|
|
);
|
|
this.registerEvent(
|
|
this.app.vault.on("delete", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding))
|
|
);
|
|
this.registerEvent(
|
|
this.app.vault.on("rename", __privateGet(this, _reloadIgnoreRegExpsIfIgnoreFileChangedBinding))
|
|
);
|
|
this.registerEvent(
|
|
this.app.vault.on("create", __privateGet(this, _recreateFileIndexBinding))
|
|
);
|
|
this.registerEvent(
|
|
this.app.vault.on("delete", __privateGet(this, _recreateFileIndexBinding))
|
|
);
|
|
this.registerEvent(
|
|
this.app.vault.on("rename", __privateGet(this, _recreateFileIndexBinding))
|
|
);
|
|
});
|
|
}
|
|
onunload() {
|
|
}
|
|
};
|
|
var SteffoFileIndexPlugin = _SteffoFileIndexPlugin;
|
|
_reloadIgnoreRegExpsIfIgnoreFileChangedBinding = new WeakMap();
|
|
_recreateFileIndexBinding = new WeakMap();
|
|
SteffoFileIndexPlugin.FILE_IGNORE_PATH = "steffo-file-index-ignore.json";
|
|
SteffoFileIndexPlugin.FILE_INDEX_PATH = "steffo-file-index.json";
|