import { App , CachedMetadata , getAllTags , iterateCacheRefs } from "obsidian" ; export class Utils { private fileCache : CachedMetadata ; param app param filePath param tagsToIgnore param linksToIgnore param directoriesToIgnore param filesToIgnore param ignoreDirectories constructor ( private app , private filePath , private tagsToIgnore , private linksToIgnore , private directoriesToIgnore , private filesToIgnore , private ignoreDirectories = true ) { this . fileCache = app . metadataCache . getCache ( filePath ) ; } private hasTagsToIgnore ( ) { const tags = getAllTags ( this . fileCache ) ; return tags ?. find ( ( tag ) => this . tagsToIgnore . contains ( tag . substring ( 1 ) ) ) !== undefined ; } private hasLinksToIgnore ( ) { if ( ( this . fileCache ?. embeds != null || this . fileCache ?. links != null ) && this . linksToIgnore [ 0 ] == "*" ) { return true ; } return iterateCacheRefs ( this . fileCache , cb => { const link = this . app . metadataCache . getFirstLinkpathDest ( cb . link , this . filePath ) ?. path ; return this . linksToIgnore . contains ( link ) ; } ) ; } private checkDirectory ( ) { const contains = this . directoriesToIgnore . find ( ( value ) => this . filePath . startsWith ( value ) && value . length != 0 ) !== undefined ; if ( this . ignoreDirectories ) { return contains ; } else { return ! contains ; } } private isFileToIgnore ( ) { return this . filesToIgnore . contains ( this . filePath ) ; } public isValid ( ) { return ! this . hasTagsToIgnore ( ) && ! this . hasLinksToIgnore ( ) && ! this . checkDirectory ( ) && ! this . isFileToIgnore ( ) ; } param app param outputFileName param text static async writeAndOpenFile ( app , outputFileName , text ) { await app . vault . adapter . write ( outputFileName , text ) ; let fileIsAlreadyOpened = false ; app . workspace . iterateAllLeaves ( leaf => { if ( leaf . getDisplayText ( ) != "" && outputFileName . startsWith ( leaf . getDisplayText ( ) ) ) { fileIsAlreadyOpened = true ; } } ) ; if ( ! fileIsAlreadyOpened ) app . workspace . openLinkText ( outputFileName , "/" , true ) ; } }