akosbalasko / zoottelkeeper-obsidian-plugin

Obsidian plugin of Zoottelkeeper: An automated folder-level index file generator and maintainer.
183 stars 11 forks source link

How does the "Folders included" option work? #42

Closed claremacrae closed 2 years ago

claremacrae commented 2 years ago

I've got mine set to a specific sub-directory "Work/Agile" where Work/ is at the root of my vault - yet many other Index files are created, such as:

But it doesn't create them in all sub-directories - and I'm not seeing the pattern as to what it's choosing.

cotemaxime commented 2 years ago

I ran into this too and looked at some of the code to see, it looks like there's some logics issue in the keepTheZooClean function (great name btw).

It filters out the file based on the exclusion correctly but then it goes and add the parents without filtering, which turns out in my case re-add most of my vault. From there it generate the indexes and then delete the index files from the excluded folders.

So for getting the expected result I think you could exclude all the folders you want cleaned and it might work, for my part I changed the code to add additional filtering and block the creation of index in excluded folder (instead of cleaning) I included it below though use with caution I have no idea of the implication on other parts of the plugins.

DANGER BELOW

async keepTheZooClean(triggeredManually) {
        console.debug('keeping the zoo clean...');
        if (this.lastVault || triggeredManually) {
            const vaultFilePathsSet = new Set(this.app.vault.getMarkdownFiles().map((file) => file.path));
            try {
                // getting the changed files using symmetric diff
                let changedFiles = new Set([
                    ...Array.from(vaultFilePathsSet).filter((currentFile) => !this.lastVault.has(currentFile)),
                    ...Array.from(this.lastVault).filter((currentVaultFile) => !vaultFilePathsSet.has(currentVaultFile)),
                ]);
                console.debug(`changedFiles: ${JSON.stringify(Array.from(changedFiles))}`);
                // getting index files to be updated
                const indexFiles2BUpdated = new Set();
                for (const changedFile of Array.from(changedFiles)) {
                    const indexFilePath = this.getIndexFilePath(changedFile);
                    if (indexFilePath
                        && isInAllowedFolder(this.settings, indexFilePath)
                        && !isInDisAllowedFolder(this.settings, indexFilePath)) {
                        indexFiles2BUpdated.add(indexFilePath);
                    }
                    // getting the parents' index notes of each changed file in order to update their links as well (hierarhical backlinks)
                    const parentIndexFilePath = this.getIndexFilePath(this.getParentFolder(changedFile));
                    if (parentIndexFilePath
                        && isInAllowedFolder(this.settings, parentIndexFilePath)
                        && !isInDisAllowedFolder(this.settings, parentIndexFilePath))
                        indexFiles2BUpdated.add(parentIndexFilePath);
                }
                console.debug(`Index files to be updated: ${JSON.stringify(Array.from(indexFiles2BUpdated))}`);
                // update index files
                for (const indexFile of Array.from(indexFiles2BUpdated)) {
                    if (isInAllowedFolder(this.settings, indexFilePath)) {
                        await this.generateIndexContents(indexFile);
                    }
                }
                await this.cleanDisallowedFolders();
            }
            catch (e) { }
        }
        this.lastVault = new Set(this.app.vault.getMarkdownFiles().map((file) => file.path));
    }
claremacrae commented 2 years ago

Thanks very much indeed for looking at this @cotemaxime.

akosbalasko commented 2 years ago

Hi @claremacrae ,

I think the problem is that the folders must be absolute paths currently separated by commas. The same stands for the exclusion as well, the must be absolute paths. So I'm afraid adding just a parent folder to let the index files be created for all of the subdirs won't work, please specify all folders separately.

Thank you, and sorry for the inconviences.

claremacrae commented 2 years ago

Hi, thanks for the reply. In a vault with 3000 files and hundreds of folders, that isn't going to be feasible.

(sorry to say this, but I ended up writing a Python script to create the indexes. It means they don't get updated every time I add a file, so won't suit everyone, but it was the only way I could get reproducible behaviour for my size of vault.)

Thanks again.

akosbalasko commented 2 years ago

@claremacrae Yeah, that's right. No worries, I'll inform you if I have time to implement a more usable solution.

SerafinDinges commented 2 years ago

I don't really understand your answer here. If I just want one directory indexed, shouldn't that be possible by setting "Folders included" to that one directory. Say I have a folder Zettelkasten sat at the root of my directory and I just want all files in that folder indexed but nothing else, what do I do? Because I've tried all sorts of ways (Zettelkasten,Vault/Zettelkasten, /Zettelkasten, Zettelkasten/) to enter the variable but I always get random index files in other folders as well.

akosbalasko commented 2 years ago

Hi all,

in version 0.18.0 I tried to improve the include/exclude feature, now it accepts absolute folders with or without starting '/' characters, moreover if you type '*' at the end of the folder, it means that the folder and its recursive subfolders are excluded/included. Sorry for the problems, I hope it is a bit more clear now.