utils#isUrl TypeScript Examples

The following examples show how to use utils#isUrl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: annotatorView.tsx    From obsidian-annotator with GNU Affero General Public License v3.0 6 votes vote down vote up
getAnnotationTarget(file: TFile): string {
        const annotationTargetPropertyValue = this.plugin.getPropertyValue(ANNOTATION_TARGET_PROPERTY, file);
        if (!annotationTargetPropertyValue) {
            this.plugin.log('Invalid annotation target!');
            return '';
        }
        for (let target of [
            annotationTargetPropertyValue,
            `${this.plugin.settings.customDefaultPath}${annotationTargetPropertyValue}`
        ]) {
            //unpack target if it is is an array (For Metaedit compatability)
            if (Array.isArray(target)) {
                target = target[0];
            }

            if (isUrl(target)) {
                return target;
            }
            let destFile: TFile;
            try {
                destFile = this.app.metadataCache.getFirstLinkpathDest(target, file?.path || '');
            } finally {
                if (destFile) {
                    return destFile.path;
                }
            }
        }

        //unpack target if it is is an array (For Metaedit compatability)
        if (Array.isArray(annotationTargetPropertyValue)) {
            return annotationTargetPropertyValue[0];
        }

        return annotationTargetPropertyValue;
    }