2024-01-22 11:35:11

This commit is contained in:
Isaac Shoebottom 2024-01-22 11:35:11 -04:00
parent 06ea15e82f
commit 896dc72e33
7 changed files with 16 additions and 950 deletions

View File

@ -1,6 +1,5 @@
[
"table-editor-obsidian",
"obsidian-icon-folder",
"obsidian-git",
"obsidian-folder-index"
"obsidian-git"
]

View File

@ -1,20 +0,0 @@
{
"disableHeadlines": false,
"graphOverwrite": false,
"rootIndexFile": "Dashboard.md",
"autoCreateIndexFile": true,
"autoRenameIndexFile": true,
"includeFileContent": false,
"hideIndexFiles": false,
"indexFileInitText": "---\ntags: MOCs\n---\n```folder-index-content\n```",
"autoPreviewMode": false,
"sortIndexFilesAlphabetically": true,
"sortHeadersAlphabetically": false,
"recursiveIndexFiles": false,
"renderFolderBold": true,
"renderFolderItalic": false,
"useBulletPoints": false,
"excludeFolders": [],
"recursionLimit": -1,
"headlineLimit": 6
}

View File

@ -1,901 +0,0 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/main.ts
__export(exports, {
default: () => FolderIndexPlugin
});
var import_obsidian6 = __toModule(require("obsidian"));
// src/modules/IndexContentProcessorModule.ts
var import_obsidian2 = __toModule(require("obsidian"));
// src/types/MarkdownTextRenderer.ts
var import_obsidian = __toModule(require("obsidian"));
// src/types/Utilities.ts
function isIndexFile(path) {
if (isExcludedPath(path))
return false;
const pathParts = path.split(/\//);
if (pathParts[0] == FolderIndexPlugin.PLUGIN.settings.rootIndexFile)
return true;
if (pathParts.length < 2)
return false;
const fileName = pathParts[pathParts.length - 1];
const folderName = pathParts[pathParts.length - 2] + ".md";
return fileName == folderName || fileName == FolderIndexPlugin.PLUGIN.settings.rootIndexFile;
}
function isExcludedPath(path) {
for (const excludedFolder of FolderIndexPlugin.PLUGIN.settings.excludeFolders) {
if (excludedFolder == "")
continue;
if (RegExp(`^${excludedFolder}$`).test(path))
return true;
}
return false;
}
// src/types/MarkdownTextRenderer.ts
var MarkdownTextRenderer = class {
constructor(plugin, app) {
this.plugin = plugin;
this.app = app;
this.plugin = plugin;
this.app = app;
}
buildMarkdownText(filesInFolder) {
const fileTree = this.buildFileTree(filesInFolder);
return this.buildStructureMarkdownText(fileTree, 0);
}
buildStructureMarkdownText(fileTree, indentLevel) {
let markdownText = "";
for (const file of fileTree) {
if (isExcludedPath(file.path)) {
continue;
}
if (file instanceof import_obsidian.TFolder && this.plugin.settings.recursiveIndexFiles) {
let children = file.children;
const indexFile = this.checkIfFolderHasIndexFile(file.children);
if (indexFile) {
children = file.children.filter((child) => child.path != indexFile.path);
markdownText += this.buildContentMarkdownText(indexFile, indentLevel, true);
} else {
markdownText += this.buildMarkdownLinkString(file.name, null, indentLevel, true);
}
if (this.plugin.settings.recursionLimit === -1 || indentLevel < this.plugin.settings.recursionLimit) {
markdownText += this.buildStructureMarkdownText(this.buildFileTree(children), indentLevel + 1);
}
}
if (file instanceof import_obsidian.TFile) {
if (isIndexFile(file.path)) {
continue;
}
markdownText += this.buildContentMarkdownText(file, indentLevel);
}
}
return markdownText;
}
buildContentMarkdownText(file, indentLevel, isFolder = false) {
var _a, _b;
let markdownText = "";
markdownText += this.buildMarkdownLinkString(this.getTitleFromPath(file.path), encodeURI(file.path), indentLevel, isFolder);
const headers = (_b = (_a = this.app.metadataCache.getFileCache(file)) == null ? void 0 : _a.headings) != null ? _b : [];
if (headers && !this.plugin.settings.disableHeadlines) {
const headerTree = this.buildHeaderTree(headers);
if (this.plugin.settings.headlineLimit !== 0) {
markdownText += this.buildHeaderMarkdownText(file, headerTree, indentLevel + 1, 1);
}
}
return markdownText;
}
buildHeaderMarkdownText(file, headerTree, indentLevel, headlineLevel) {
let markdownText = "";
if (this.plugin.settings.sortHeadersAlphabetically) {
headerTree.sort((a, b) => a.header.heading.localeCompare(b.header.heading));
}
for (const headerWrapper of headerTree) {
markdownText += this.buildMarkdownLinkString(headerWrapper.header.heading, encodeURI(file.path) + this.buildHeaderChain(headerWrapper), indentLevel);
if (headlineLevel < this.plugin.settings.headlineLimit) {
markdownText += this.buildHeaderMarkdownText(file, headerWrapper.children, indentLevel + 1, headlineLevel + 1);
}
}
return markdownText;
}
buildMarkdownLinkString(name, path, indentLevel, isFolder = false) {
const indentText = this.buildIndentLevel(indentLevel);
const settings = this.plugin.settings;
const symbol = settings.useBulletPoints ? "-" : "1.";
let link = `${indentText}${symbol} ${settings.includeFileContent ? "!" : ""}`;
if (isFolder) {
if (settings.renderFolderItalic) {
name = `*${name}*`;
}
if (settings.renderFolderBold) {
name = `**${name}**`;
}
}
if (path) {
link += `[${name}](${path})
`;
} else {
link += `${name}
`;
}
return link;
}
getTitleFromPath(path) {
var _a, _b;
const file = this.app.vault.getAbstractFileByPath(path);
if (file instanceof import_obsidian.TFile) {
const cache = this.app.metadataCache.getFileCache(file);
if (cache) {
return (_b = (_a = cache.frontmatter) == null ? void 0 : _a.title) != null ? _b : file.basename;
}
return file.basename;
}
return "Something went wrong. Please report this issue.";
}
buildHeaderChain(header) {
if (header.parent) {
return `${this.buildHeaderChain(header.parent)}#${encodeURI(header.header.heading)}`;
}
return `#${encodeURI(header.header.heading)}`;
}
checkIfFolderHasIndexFile(children) {
for (const file of children) {
if (file instanceof import_obsidian.TFile) {
if (isIndexFile(file.path)) {
return file;
}
}
}
return null;
}
buildHeaderTree(headers) {
const headerTree = [];
for (let i = 0; i < headers.length; i++) {
if (headers[i].level == 1) {
const wrappedHeader = {
parent: null,
header: headers[i],
children: []
};
wrappedHeader.children = this.getHeaderChildren(headers, i + 1, wrappedHeader);
headerTree.push(wrappedHeader);
}
}
return headerTree;
}
getHeaderChildren(headers, startIndex, parentHeader) {
const children = [];
if (startIndex > headers.length) {
return children;
}
for (let i = startIndex; i < headers.length; i++) {
if (headers[i].level <= parentHeader.header.level) {
return children;
}
if (headers[i].level == parentHeader.header.level + 1) {
const wrappedHeader = {
parent: parentHeader,
header: headers[i],
children: []
};
wrappedHeader.children = this.getHeaderChildren(headers, i + 1, wrappedHeader);
children.push(wrappedHeader);
}
}
return children;
}
buildFileTree(filesInFolder) {
const fileTree = [];
for (const file of filesInFolder) {
if (file instanceof import_obsidian.TFolder && this.plugin.settings.recursiveIndexFiles) {
fileTree.push(file);
}
if (file instanceof import_obsidian.TFile) {
fileTree.push(file);
}
}
if (this.plugin.settings.sortIndexFilesAlphabetically) {
fileTree.sort((a, b) => a.name.localeCompare(b.name));
}
return fileTree;
}
buildIndentLevel(indentLevel) {
let indentText = "";
for (let j = 0; j < indentLevel; j++) {
indentText += " ";
}
return indentText;
}
};
// src/modules/IndexContentProcessorModule.ts
var IndexContentProcessorModule = class extends import_obsidian2.MarkdownRenderChild {
constructor(app, plugin, filePath, container) {
super(container);
this.app = app;
this.plugin = plugin;
this.filePath = filePath;
this.container = container;
this.app = app;
this.plugin = plugin;
this.filePath = filePath;
this.container = container;
}
onload() {
return __async(this, null, function* () {
yield this.render();
this.plugin.eventManager.on("settingsUpdate", this.triggerRerender.bind(this));
this.plugin.registerEvent(this.app.vault.on("rename", this.triggerRerender.bind(this)));
this.app.workspace.onLayoutReady(() => {
this.plugin.registerEvent(this.app.vault.on("create", this.triggerRerender.bind(this)));
});
this.plugin.registerEvent(this.app.vault.on("delete", this.triggerRerender.bind(this)));
});
}
onunload() {
return __async(this, null, function* () {
this.plugin.eventManager.off("settingsUpdate", this.onSettingsUpdate.bind(this));
});
}
onSettingsUpdate() {
this.render().then();
}
triggerRerender() {
this.render().then();
}
render() {
return __async(this, null, function* () {
var _a, _b;
this.container.empty();
const folder = this.app.vault.getAbstractFileByPath(this.filePath);
if (folder instanceof import_obsidian2.TFile) {
const files = (_b = (_a = folder.parent) == null ? void 0 : _a.children) != null ? _b : [];
const renderer = new MarkdownTextRenderer(this.plugin, this.app);
yield import_obsidian2.MarkdownRenderer.renderMarkdown(renderer.buildMarkdownText(files), this.container, this.filePath, this);
}
});
}
};
// src/modules/GraphManipulatorModule.ts
var import_obsidian3 = __toModule(require("obsidian"));
var GraphManipulatorModule = class {
constructor(app, plugin) {
this.app = app;
this.plugin = plugin;
this.app = app;
this.plugin = plugin;
this.graphsLeafs = [];
this.oldGraphOverwrite = this.plugin.settings.graphOverwrite;
this.load();
}
onLayoutChange() {
this.graphsLeafs = this.app.workspace.getLeavesOfType("graph");
this.plugin.eventManager.emit("graphLeafUpdate", this.graphsLeafs);
}
onLeafUpdate(leaves) {
leaves.forEach((value) => {
const engine = this.getEngine(value);
if (engine.oldRender == null) {
engine.oldRender = engine.render;
engine.render = () => {
if (this.plugin.settings.graphOverwrite) {
this.render(engine);
} else {
if (engine.oldRender)
engine.oldRender();
}
};
if (this.plugin.settings.graphOverwrite) {
this.clearGraph(engine);
this.render(engine);
}
}
});
}
onSettingsUpdate() {
if (this.oldGraphOverwrite != this.plugin.settings.graphOverwrite) {
this.redrawAllGraphs();
this.oldGraphOverwrite = this.plugin.settings.graphOverwrite;
}
}
load() {
this.oldGraphOverwrite = this.plugin.settings.graphOverwrite;
this.plugin.eventManager.on("onLayoutChange", this.onLayoutChange.bind(this));
this.plugin.eventManager.on("graphLeafUpdate", this.onLeafUpdate.bind(this));
this.plugin.eventManager.on("settingsUpdate", this.onSettingsUpdate.bind(this));
this.onLayoutChange();
if (this.plugin.settings.graphOverwrite) {
this.clearAllGraphs();
this.redrawAllGraphs();
}
}
unload() {
this.graphsLeafs.forEach((value) => {
const engine = this.getEngine(value);
if (engine.oldRender != null) {
engine.render = engine.oldRender;
delete engine.oldRender;
this.clearGraph(engine);
engine.render();
}
});
}
render(engine) {
const renderSettings = engine.getOptions();
const graph = {};
this.app.vault.getFiles().forEach((file) => __async(this, null, function* () {
var _a, _b, _c;
if (Object.keys(engine.fileFilter).length > 0 && !engine.fileFilter[file.path]) {
return;
}
const edges = {};
const cache = this.app.metadataCache.getFileCache(file);
if (((_a = file.parent) == null ? void 0 : _a.name) + ".md" == file.name || file.name == this.plugin.settings.rootIndexFile) {
(_b = file.parent) == null ? void 0 : _b.children.forEach((otherFile) => {
if (otherFile instanceof import_obsidian3.TFile && file.path != otherFile.path) {
edges[otherFile.path] = true;
}
if (otherFile instanceof import_obsidian3.TFolder) {
const subIndex = otherFile.children.find((value) => value.name == otherFile.name + ".md");
if (subIndex != null) {
edges[subIndex.path] = true;
}
}
});
}
if (cache != null) {
if (cache.links != null) {
cache.links.forEach((link) => {
if (link.link.contains("#")) {
link.link = link.link.split(/#/)[0];
}
const linkedFile = this.app.metadataCache.getFirstLinkpathDest(link.link, file.path);
if (linkedFile == null) {
edges[link.link] = true;
if (!renderSettings.hideUnresolved) {
graph[link.link] = {
links: {},
type: "unresolved"
};
}
} else {
edges[linkedFile.path] = true;
}
});
}
if (cache.frontmatter != null) {
const frontMatterTags = (0, import_obsidian3.parseFrontMatterTags)(cache.frontmatter);
if (frontMatterTags != null && renderSettings.showTags) {
frontMatterTags.forEach((tag) => {
graph[tag] = {
links: {},
type: "tag"
};
edges[tag] = true;
});
}
}
if (cache.tags != null && renderSettings.showTags) {
cache.tags.forEach((tag) => {
graph[tag.tag] = {
links: {},
type: "tag"
};
edges[tag.tag] = true;
});
}
if (cache.embeds != null) {
cache.embeds.forEach((embed) => {
const linkedFile = this.app.metadataCache.getFirstLinkpathDest(embed.link, file.path);
if (linkedFile == null) {
edges[embed.link] = true;
graph[embed.link] = {
links: {},
type: "unresolved"
};
} else {
edges[linkedFile.path] = true;
}
});
}
}
let type = "";
if (this.app.workspace.getActiveFile() != null && ((_c = this.app.workspace.getActiveFile()) == null ? void 0 : _c.path) == file.path) {
type = "focused";
} else if (file.extension != "md") {
type = "attachment";
}
if (type == "attachment" && !renderSettings.showAttachments) {
return;
}
graph[file.path] = {
links: edges,
type
};
}));
if (!renderSettings.showOrphans) {
let allLinks = [];
for (const graphKey in graph) {
if (Object.keys(graph[graphKey]["links"]).length > 0) {
allLinks.push(graphKey);
}
allLinks = allLinks.concat(Object.keys(graph[graphKey]["links"]));
}
for (const graphKey in graph) {
if (!allLinks.includes(graphKey)) {
delete graph[graphKey];
}
}
}
function AddColorTag(filePath, nodeType) {
const searchQueries = engine.searchQueries;
const engineOptions = engine.options;
const fileFilter = engine.fileFilter;
return !searchQueries || (nodeType === "" ? filePath === engineOptions.localFile || (fileFilter.hasOwnProperty(filePath) ? fileFilter[filePath] : !engine.hasFilter) : nodeType === "tag" ? searchQueries.every(function(e) {
return !!e.color || !!e.query.matchTag(filePath);
}) : nodeType !== "attachment" || searchQueries.every(function(e) {
return !!e.color || !!e.query.matchFilepath(filePath);
}));
}
for (const graphKey in graph) {
const returnValue = AddColorTag(graphKey, graph[graphKey].type);
if (returnValue === true)
continue;
graph[graphKey].color = returnValue;
}
engine.renderer.setData({
nodes: graph
});
}
redrawAllGraphs() {
this.clearAllGraphs();
this.graphsLeafs.forEach((value) => this.getEngine(value).render());
}
clearAllGraphs() {
this.graphsLeafs.forEach((value) => this.getEngine(value).renderer.setData({
nodes: {}
}));
}
getEngine(leaf) {
return leaf.view.dataEngine;
}
clearGraph(engine) {
engine.renderer.setData({
nodes: {}
});
}
};
// src/main.ts
var import_events = __toModule(require("events"));
// src/models/PluginSettingsTab.ts
var import_obsidian4 = __toModule(require("obsidian"));
var DEFAULT_SETTINGS = {
disableHeadlines: false,
graphOverwrite: false,
rootIndexFile: "Dashboard.md",
autoCreateIndexFile: true,
autoRenameIndexFile: true,
includeFileContent: false,
hideIndexFiles: false,
indexFileInitText: "---\ntags: MOCs\n---\n```folder-index-content\n```",
autoPreviewMode: false,
sortIndexFilesAlphabetically: true,
sortHeadersAlphabetically: false,
recursiveIndexFiles: false,
renderFolderBold: true,
renderFolderItalic: false,
useBulletPoints: false,
excludeFolders: [],
recursionLimit: -1,
headlineLimit: 6
};
var PluginSettingsTab = class extends import_obsidian4.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Graph Settings" });
new import_obsidian4.Setting(containerEl).setName("Overwrite Graph View").setDesc("This will overwrite the default graph view and link files based on their index as well as their normal links").addToggle((component) => component.setValue(this.plugin.settings.graphOverwrite).onChange((value) => __async(this, null, function* () {
this.plugin.settings.graphOverwrite = value;
yield this.plugin.saveSettings();
})));
containerEl.createEl("h2", { text: "Index File Settings" });
new import_obsidian4.Setting(containerEl).setName("Root Index File").setDesc("The File that is used for the Root Index File").addText((component) => component.setValue(this.plugin.settings.rootIndexFile).setPlaceholder("dashboard.md").onChange((value) => __async(this, null, function* () {
this.plugin.settings.rootIndexFile = value;
yield this.plugin.saveSettings();
})));
let textFeld = null;
new import_obsidian4.Setting(containerEl).setName("Initial Content").setDesc("Set the initial content for new folder indexes.").addButton((component) => component.setButtonText("Reset").setWarning().setTooltip("Reset to default").onClick(() => __async(this, null, function* () {
this.plugin.settings.indexFileInitText = DEFAULT_SETTINGS.indexFileInitText;
textFeld == null ? void 0 : textFeld.setValue(this.plugin.settings.indexFileInitText);
yield this.plugin.saveSettings();
}))).addTextArea((component) => {
textFeld = component;
component.setPlaceholder("About the folder.").setValue(this.plugin.settings.indexFileInitText).onChange((value) => __async(this, null, function* () {
this.plugin.settings.indexFileInitText = value;
yield this.plugin.saveSettings();
}));
component.inputEl.rows = 8;
component.inputEl.cols = 50;
});
new import_obsidian4.Setting(containerEl).setName("Excluded Folders").setDesc("These Folders will not automatically create an IndexFile").addTextArea((component) => {
component.setPlaceholder("Folder1\nFolder2/Foo\nFolder3/Foo/Bar").setValue(this.plugin.settings.excludeFolders.join("\n")).onChange((value) => __async(this, null, function* () {
this.plugin.settings.excludeFolders = value.split("\n");
yield this.plugin.saveSettings();
}));
component.inputEl.rows = 8;
component.inputEl.cols = 50;
});
new import_obsidian4.Setting(containerEl).setName("Automatically generate IndexFile").setDesc("This will automatically create an IndexFile when you create a new folder").addToggle((component) => component.setValue(this.plugin.settings.autoCreateIndexFile).onChange((value) => __async(this, null, function* () {
this.plugin.settings.autoCreateIndexFile = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Automatically Rename IndexFile").setDesc("This will automatically rename the folders index file as you rename folders").addToggle((component) => component.setValue(this.plugin.settings.autoRenameIndexFile).onChange((value) => __async(this, null, function* () {
this.plugin.settings.autoRenameIndexFile = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Hide IndexFile").setDesc("This will hide IndexFiles from the file explorer (Disabled as it causes bugs right now)").addToggle((component) => component.setValue(this.plugin.settings.hideIndexFiles).onChange((value) => __async(this, null, function* () {
this.plugin.settings.hideIndexFiles = value;
yield this.plugin.saveSettings();
})).setDisabled(true));
containerEl.createEl("h2", { text: "Content Renderer Settings" });
new import_obsidian4.Setting(containerEl).setName("Auto include preview").setDesc("This will automatically include previews when creating index files (!) ").addToggle((component) => component.setValue(this.plugin.settings.includeFileContent).onChange((value) => __async(this, null, function* () {
this.plugin.settings.includeFileContent = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Disable Headlines").setDesc("This will disable listing headlines within the index file").addToggle((component) => component.setValue(this.plugin.settings.disableHeadlines).onChange((value) => __async(this, null, function* () {
this.plugin.settings.disableHeadlines = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Headline Limit").setDesc("Limit the Depth of Headlines Displayed").addText((component) => component.setValue(this.plugin.settings.headlineLimit.toString()).setPlaceholder("6").onChange((value) => __async(this, null, function* () {
let numValue = Number.parseInt(value);
if (!isNaN(numValue)) {
if (numValue < 0) {
numValue = 0;
} else if (numValue > 6) {
numValue = 6;
}
} else {
numValue = 6;
}
this.plugin.settings.headlineLimit = numValue;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Automatic Preview mode").setDesc("This will automatically swap to preview mode when opening an index file").addToggle((component) => component.setValue(this.plugin.settings.autoPreviewMode).onChange((value) => __async(this, null, function* () {
this.plugin.settings.autoPreviewMode = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Sort Files Alphabetically").setDesc("This will sort the Files alphabetically").addToggle((component) => component.setValue(this.plugin.settings.sortIndexFilesAlphabetically).onChange((value) => __async(this, null, function* () {
this.plugin.settings.sortIndexFilesAlphabetically = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Sort Headers Alphabetically").setDesc("This will sort the Headers within a file alphabetically").addToggle((component) => component.setValue(this.plugin.settings.sortHeadersAlphabetically).onChange((value) => __async(this, null, function* () {
this.plugin.settings.sortHeadersAlphabetically = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Build IndexFiles Recursively").setDesc("This will show all files within a folder and its subfolders").addToggle((component) => component.setValue(this.plugin.settings.recursiveIndexFiles).onChange((value) => __async(this, null, function* () {
this.plugin.settings.recursiveIndexFiles = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Subfolder Limit").setDesc("Limit the Depth of Subfolders(-1 for no limit)").addText((component) => component.setValue(this.plugin.settings.recursionLimit.toString()).setPlaceholder("-1").onChange((value) => __async(this, null, function* () {
let numValue = Number.parseInt(value);
if (isNaN(numValue) || numValue < 0) {
numValue = -1;
}
this.plugin.settings.recursionLimit = numValue;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Render Folders Bold").setDesc("This will render folders in **bold**").addToggle((component) => component.setValue(this.plugin.settings.renderFolderBold).onChange((value) => __async(this, null, function* () {
this.plugin.settings.renderFolderBold = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Render Folder Italic").setDesc("This will render folders in *italic*").addToggle((component) => component.setValue(this.plugin.settings.renderFolderItalic).onChange((value) => __async(this, null, function* () {
this.plugin.settings.renderFolderItalic = value;
yield this.plugin.saveSettings();
})));
new import_obsidian4.Setting(containerEl).setName("Use bullet-points instead of list").setDesc("This will render the index file as a bullet-point list instead of a numbered list").addToggle((component) => component.setValue(this.plugin.settings.useBulletPoints).onChange((value) => __async(this, null, function* () {
this.plugin.settings.useBulletPoints = value;
yield this.plugin.saveSettings();
})));
}
};
// src/modules/FolderNoteModule.ts
var import_obsidian5 = __toModule(require("obsidian"));
var FolderNoteModule = class {
constructor(app, plugin) {
this.app = app;
this.plugin = plugin;
this.viewModeByPlugin = false;
this.previousState = null;
this.app = app;
this.plugin = plugin;
this.load();
}
load() {
this.app.workspace.onLayoutReady(() => {
this.plugin.registerEvent(this.app.vault.on("create", this.onCreate.bind(this)));
});
this.plugin.registerEvent(this.app.workspace.on("layout-change", this.onLayoutChange.bind(this)));
this.plugin.registerDomEvent(document, "click", this.onClick.bind(this));
this.plugin.registerEvent(this.app.vault.on("rename", this.onRename.bind(this)));
}
unload() {
}
getTargetFromEvent(event) {
var _a, _b, _c, _d, _e;
if (!(event.target instanceof HTMLElement)) {
return null;
}
const target = event.target;
const activePlugins = this.app.plugins.enabledPlugins;
if (activePlugins.has("file-tree-alternative")) {
if (target.classList.contains("oz-folder-name")) {
return (_c = (_b = (_a = target.parentElement) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.parentElement) != null ? _c : null;
}
if (target.classList.contains("oz-folder-block")) {
return (_e = (_d = target.parentElement) == null ? void 0 : _d.parentElement) != null ? _e : null;
}
}
if (target.classList.contains("nav-folder-title"))
return target;
if (target.classList.contains("nav-folder-title-content")) {
return target.parentElement;
}
return null;
}
onClick(event) {
return __async(this, null, function* () {
const target = this.getTargetFromEvent(event);
if (target == null)
return;
const dataPathAttribute = target.attributes.getNamedItem("data-path");
let dataPath;
if (dataPathAttribute == null) {
return;
} else {
dataPath = dataPathAttribute.value;
}
const folderName = dataPath.split("/").pop();
let indexFilePath = dataPath + "/" + folderName + ".md";
if (indexFilePath == "//.md") {
indexFilePath = this.plugin.settings.rootIndexFile;
}
if (!this.doesFileExist(indexFilePath)) {
if (yield this.createIndexFile(indexFilePath)) {
yield this.openIndexFile(indexFilePath);
}
} else {
yield this.openIndexFile(indexFilePath);
}
});
}
doesFileExist(path) {
return this.app.vault.getAbstractFileByPath(path) != null;
}
openIndexFile(path) {
return __async(this, null, function* () {
if (!isIndexFile(path)) {
return;
}
const file = this.app.vault.getAbstractFileByPath(path);
if (file instanceof import_obsidian5.TFile) {
yield this.app.workspace.getLeaf().openFile(file);
}
});
}
createIndexFile(path) {
return __async(this, null, function* () {
if (isExcludedPath(path))
return false;
if (this.plugin.settings.autoCreateIndexFile) {
const name = path.split(/\//).last();
try {
if (!name)
return false;
const file = yield this.app.vault.create(path, this.plugin.settings.indexFileInitText.replace("{{folder}}", name));
new import_obsidian5.Notice(`Created index file ${file.basename}`);
return true;
} catch (e) {
new import_obsidian5.Notice(`Failed to create index file ${name}`);
}
}
return false;
});
}
onRename(file, oldPath) {
return __async(this, null, function* () {
if (!this.plugin.settings.autoRenameIndexFile) {
return;
}
if (file instanceof import_obsidian5.TFile) {
return;
}
if (oldPath.split("/").pop() == file.name) {
return;
}
const oldIndexFileName = oldPath.split("/").pop();
if (!this.doesFileExist(`${oldPath}/${oldIndexFileName}.md`))
return;
const oldIndexFile = this.app.vault.getAbstractFileByPath(`${oldPath}/${oldIndexFileName}.md`);
if (!isIndexFile(oldIndexFile.path))
return;
oldIndexFile.path = `${file.path}/${oldIndexFileName}.md`;
try {
yield this.app.vault.rename(oldIndexFile, `${file.path}/${file.name}.md`);
new import_obsidian5.Notice(`Renamed index file ${oldIndexFileName} to ${file.name}`);
} catch (e) {
new import_obsidian5.Notice(`Failed to rename index file ${oldIndexFileName} to ${file.name}. ${file.name} will be used as the index file.`);
}
});
}
onLayoutChange() {
return __async(this, null, function* () {
try {
if (this.previousState == null) {
this.previousState = this.app.workspace.getLeaf().getViewState();
}
if (!this.plugin.settings.autoPreviewMode) {
return;
}
const currentState = this.app.workspace.getLeaf().getViewState();
if (!(currentState.type == "markdown" && this.previousState.type == "markdown")) {
return;
}
if (currentState.state.file == this.previousState.state.file)
return;
const currentFile = this.app.vault.getAbstractFileByPath(currentState.state.file);
if (!isIndexFile(currentFile.path)) {
if (this.viewModeByPlugin) {
this.viewModeByPlugin = false;
currentState.state.mode = "source";
yield this.app.workspace.getLeaf().setViewState(currentState);
}
return;
}
if (this.previousState.state.mode == "preview") {
return;
} else {
currentState.state.mode = "preview";
this.viewModeByPlugin = true;
yield this.app.workspace.getLeaf().setViewState(currentState);
}
} finally {
const currentState = this.app.workspace.getLeaf().getViewState();
if (currentState.type == "markdown")
this.previousState = currentState;
}
});
}
onCreate(file) {
return __async(this, null, function* () {
if (file instanceof import_obsidian5.TFolder) {
yield this.createIndexFile(`${file.path}/${file.name}.md`);
}
});
}
};
// src/main.ts
var FolderIndexPlugin = class extends import_obsidian6.Plugin {
constructor(app, manifest) {
super(app, manifest);
this.oldGraphSetting = false;
FolderIndexPlugin.PLUGIN = this;
}
onload() {
return __async(this, null, function* () {
console.log("Loading FolderTableContent");
this.eventManager = new import_events.EventEmitter();
yield this.loadSettings();
this.settings.hideIndexFiles = false;
yield this.saveSettings();
this.oldGraphSetting = this.settings.graphOverwrite;
this.addSettingTab(new PluginSettingsTab(this.app, this));
this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this));
this.registerEvent(this.app.workspace.on("layout-change", this.onLayoutChange.bind(this)));
this.eventManager.on("settingsUpdate", this.onSettingsUpdate.bind(this));
this.registerMarkdownCodeBlockProcessor("folder-index-content", (_source, el, ctx) => {
ctx.addChild(new IndexContentProcessorModule(this.app, this, ctx.sourcePath, el));
});
this.folderNodeModule = new FolderNoteModule(this.app, this);
if (this.settings.graphOverwrite) {
this.graphManipulator = new GraphManipulatorModule(this.app, this);
}
});
}
onSettingsUpdate() {
if (this.settings.graphOverwrite != this.oldGraphSetting) {
if (this.settings.graphOverwrite) {
this.graphManipulator = new GraphManipulatorModule(this.app, this);
} else {
if (this.graphManipulator)
this.graphManipulator.unload();
}
this.oldGraphSetting = this.settings.graphOverwrite;
}
}
onLayoutChange() {
this.eventManager.emit("onLayoutChange");
}
onLayoutReady() {
this.eventManager.emit("onLayoutReady");
}
onunload() {
return __async(this, null, function* () {
console.log("Unloading FolderTableContent");
this.eventManager.removeAllListeners();
if (this.graphManipulator != null) {
this.graphManipulator.unload();
}
this.folderNodeModule.unload();
});
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
this.eventManager.emit("settingsUpdate", this.settings);
});
}
};

View File

@ -1,11 +0,0 @@
{
"id": "obsidian-folder-index",
"name": "Folder Index",
"version": "1.0.22",
"minAppVersion": "1.1.16",
"description": "This Plugin will automatically generate a TOC for the current Folder.",
"author": "turulix",
"authorUrl": "https://turulix.de/",
"fundingUrl": "https://www.buymeacoffee.com/turulix",
"isDesktopOnly": false
}

View File

@ -1,4 +0,0 @@
/*Idk maybe this fixes it?*/
div.hide-index-folder-note {
display: none;
}

View File

@ -4,16 +4,16 @@
"type": "split",
"children": [
{
"id": "25d0716e9a09ee27",
"id": "c0c8d0798199c14a",
"type": "tabs",
"children": [
{
"id": "8eba00a0b3c31b5f",
"id": "38642519e0ef3cbe",
"type": "leaf",
"state": {
"type": "markdown",
"state": {
"file": "README.md",
"file": "UNB/Year 4/Semester 2/CS3873/CS2024-01-22.md",
"mode": "source",
"source": false
}
@ -85,7 +85,7 @@
"state": {
"type": "backlink",
"state": {
"file": "README.md",
"file": "UNB/Year 4/Semester 2/CS3873/CS2024-01-22.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
@ -102,7 +102,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "README.md",
"file": "UNB/Year 4/Semester 2/CS3873/CS2024-01-22.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
@ -125,7 +125,7 @@
"state": {
"type": "outline",
"state": {
"file": "README.md"
"file": "UNB/Year 4/Semester 2/CS3873/CS2024-01-22.md"
}
}
},
@ -156,12 +156,14 @@
"table-editor-obsidian:Advanced Tables Toolbar": false
}
},
"active": "8eba00a0b3c31b5f",
"active": "38642519e0ef3cbe",
"lastOpenFiles": [
"UNB.md",
"README.md",
"Year 4.md",
"UNB/Year 4/Semester 2/STAT2593/2024-01-22.md",
"UNB/Year 4/Semester 2/CS3873/CS2024-01-22.md",
"README.md",
"UNB/UNB.md",
"UNB.md",
"Year 4.md",
"UNB/Year 4/Semester 2/STAT2593/2024-01-19.md",
"UNB/Year 4/Semester 1/CS2418/9-15-2023.md",
"gcm-diagnose.log",
@ -189,8 +191,6 @@
"Semester 1/CS2418/10-25-2023.md",
"Semester 1/CS2418/10-23-2023.md",
"Semester 1/CS3418/10-25-2023.md",
"Semester 1/CS2418/10-18-2023.md",
"Semester 1/CS2418/10-20-2023.md",
"Semester 1/CS2418",
"Semester 1/CS3418"
]

View File

@ -0,0 +1,3 @@
Lecture Topic:
Packet Switching: Congestion