mirror of
https://github.com/Steffo99/appunti-magistrali.git
synced 2024-11-25 19:44:18 +00:00
147 lines
16 KiB
JavaScript
147 lines
16 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);
|
||
|
basenames[file.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";
|
||
|
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibWFpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0IHtQbHVnaW4sIFRGaWxlLCBURm9sZGVyfSBmcm9tIFwib2JzaWRpYW5cIlxuXG5cbmV4cG9ydCBpbnRlcmZhY2UgU3RlZmZvRmlsZUluZGV4IHtcblx0YmFzZW5hbWVzOiB7W2Jhc2VuYW1lOiBzdHJpbmddOiBzdHJpbmd9LFxuXHRwYXRoczogc3RyaW5nW10sXG59XG5cblxuZXhwb3J0IGRlZmF1bHQgY2xhc3MgU3RlZmZvRmlsZUluZGV4UGx1Z2luIG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