Skip to content

Commit

Permalink
Revert "[WIP] Add local ignore pattern"
Browse files Browse the repository at this point in the history
This reverts commit 161132f.
  • Loading branch information
Moyf committed Dec 11, 2024
1 parent 161132f commit 407a6e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 136 deletions.
28 changes: 14 additions & 14 deletions src/models/PluginSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ export class PluginSettingsTab extends PluginSettingTab {
component.inputEl.cols = 50
})

new Setting(containerEl)
.setName("Excluded Patterns")
.setDesc("Files and folders matching these patterns will be excluded from the content renderer. Use * as wildcard. One pattern per line.")
.addTextArea(component => {
component.setPlaceholder("Assets\n*img*\n*.pdf")
.setValue(this.plugin.settings.excludePatterns.join("\n"))
.onChange(async (value) => {
this.plugin.settings.excludePatterns = value.split("\n")
await this.plugin.saveSettings()
})
component.inputEl.rows = 8
component.inputEl.cols = 50
})

new Setting(containerEl)
.setName("Automatically generate IndexFile")
.setDesc("This will automatically create an IndexFile when you create a new folder")
Expand Down Expand Up @@ -189,20 +203,6 @@ export class PluginSettingsTab extends PluginSettingTab {

containerEl.createEl('h2', {text: 'Content Renderer Settings'});

new Setting(containerEl)
.setName("Excluded Patterns")
.setDesc("Files and folders matching these patterns will be excluded from the content renderer. Use * as wildcard. One pattern per line.")
.addTextArea(component => {
component.setPlaceholder("Assets\n*img*\n*.pdf")
.setValue(this.plugin.settings.excludePatterns.join("\n"))
.onChange(async (value) => {
this.plugin.settings.excludePatterns = value.split("\n")
await this.plugin.saveSettings()
})
component.inputEl.rows = 8
component.inputEl.cols = 50
})

// new Setting(containerEl)
// .setName("Skip First Headline")
// .setDesc("This Option should not be used anymore, as Obsidian now shows the Filename itself " +
Expand Down
77 changes: 2 additions & 75 deletions src/modules/IndexContentProcessorModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {App, MarkdownRenderChild, MarkdownRenderer, TAbstractFile, TFile} from "obsidian";
import FolderIndexPlugin from "../main";
import {MarkdownTextRenderer} from "../types/MarkdownTextRenderer";
import {ExcludePatternManager} from "../types/ExcludePatternManager";


export class IndexContentProcessorModule extends MarkdownRenderChild {
constructor(
Expand Down Expand Up @@ -45,83 +45,10 @@ export class IndexContentProcessorModule extends MarkdownRenderChild {
const folder: TAbstractFile | null = this.app.vault.getAbstractFileByPath(this.filePath)
if (folder instanceof TFile) {
const files = folder.parent?.children ?? []
const renderer = new MarkdownTextRenderer(
this.plugin,
this.app,
new ExcludePatternManager(this.plugin)
)
const renderer = new MarkdownTextRenderer(this.plugin, this.app)
await MarkdownRenderer.renderMarkdown(renderer.buildMarkdownText(files), this.container, this.filePath, this)
}
}


}

export class CodeBlockProcessor extends MarkdownRenderChild {
constructor(
private readonly app: App,
private readonly plugin: FolderIndexPlugin,
private readonly filePath: string,
private readonly container: HTMLElement,
private readonly source: string
) {
super(container)
this.app = app
this.plugin = plugin
this.filePath = filePath
this.container = container
this.source = source
}

async onload() {
await 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)))
}

async onunload() {
this.plugin.eventManager.off("settingsUpdate", this.onSettingsUpdate.bind(this))
}

public onSettingsUpdate() {
this.render().then()
}

public triggerRerender() {
this.render().then()
}

private parseCodeBlockParameters(source: string): { ignore?: string } {
const lines = source.split('\n');
const params: { ignore?: string } = {};

for (const line of lines) {
const match = line.match(/^(\w+):\s*(.+)$/);
if (match) {
const [, key, value] = match;
params[key] = value.trim();
}
}

return params;
}

private async render() {
this.container.empty()
const folder: TAbstractFile | null = this.app.vault.getAbstractFileByPath(this.filePath)
if (folder instanceof TFile) {
const files = folder.parent?.children ?? []
const params = this.parseCodeBlockParameters(this.source);
const renderer = new MarkdownTextRenderer(
this.plugin,
this.app,
new ExcludePatternManager(this.plugin, params.ignore)
)
await MarkdownRenderer.renderMarkdown(renderer.buildMarkdownText(files), this.container, this.filePath, this)
}
}
}
34 changes: 0 additions & 34 deletions src/types/ExcludePatternManager.ts

This file was deleted.

18 changes: 5 additions & 13 deletions src/types/MarkdownTextRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {App, HeadingCache, TAbstractFile, TFile, TFolder} from "obsidian";
import FolderIndexPlugin from "../main";
import {ExcludePatternManager} from "./ExcludePatternManager";
import {isExcludedPath, isIndexFile} from "./Utilities";
import {SortBy} from "../models/PluginSettingsTab";

type FileTree = (TFile | TFolder)[]
Expand All @@ -11,14 +11,9 @@ type HeaderWrapper = {
}

export class MarkdownTextRenderer {
constructor(
private plugin: FolderIndexPlugin,
private app: App,
private excludeManager: ExcludePatternManager
) {
constructor(private plugin: FolderIndexPlugin, private app: App) {
this.plugin = plugin
this.app = app
this.excludeManager = excludeManager
}

public buildMarkdownText(filesInFolder: TAbstractFile[]): string {
Expand All @@ -30,7 +25,7 @@ export class MarkdownTextRenderer {
let markdownText = ""

for (const file of fileTree) {
if(this.excludeManager.isExcluded(file.path)){
if(isExcludedPath(file.path)){
continue
}
if (file instanceof TFolder && this.plugin.settings.recursiveIndexFiles) {
Expand All @@ -49,10 +44,7 @@ export class MarkdownTextRenderer {
}
}
if (file instanceof TFile) {
if (this.excludeManager.isExcluded(file.path)) {
continue;
}
if (this.plugin.settings.excludeIndexFiles && this.excludeManager.isIndexFile(file.path)) {
if (isIndexFile(file.path)) {
continue;
}
markdownText += this.buildContentMarkdownText(file, indentLevel)
Expand Down Expand Up @@ -146,7 +138,7 @@ export class MarkdownTextRenderer {
private checkIfFolderHasIndexFile(children: TAbstractFile[]): TFile | null {
for (const file of children) {
if (file instanceof TFile) {
if (this.excludeManager.isIndexFile(file.path)) {
if (isIndexFile(file.path)) {
return file
}
}
Expand Down

0 comments on commit 407a6e6

Please sign in to comment.