From 3d08672ec83bcdd92821d7a7b9c1e0ebfddb6cd4 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Mon, 24 Mar 2025 23:44:17 +1100 Subject: [PATCH] Added obsidian plugin for name highlight --- docs/.obsidian/plugins/docs-viewer/main.js | 93 +++++++++++++++++++ .../plugins/docs-viewer/manifest.json | 12 +++ docs/.obsidian/plugins/docs-viewer/styles.css | 40 ++++++++ 3 files changed, 145 insertions(+) create mode 100644 docs/.obsidian/plugins/docs-viewer/main.js create mode 100644 docs/.obsidian/plugins/docs-viewer/manifest.json create mode 100644 docs/.obsidian/plugins/docs-viewer/styles.css diff --git a/docs/.obsidian/plugins/docs-viewer/main.js b/docs/.obsidian/plugins/docs-viewer/main.js new file mode 100644 index 0000000..6b625fb --- /dev/null +++ b/docs/.obsidian/plugins/docs-viewer/main.js @@ -0,0 +1,93 @@ +const obsidian = require('obsidian'); + +class TitleAppenderPlugin extends obsidian.Plugin { + async onload() { + console.log('Loading TitleAppender plugin'); + + // Create stylesheet element only once during initialization + try { + this.styleEl = document.head.createEl('style'); + this.styleEl.id = 'title-appender-styles'; + } catch (error) { + console.error('Error creating style element:', error); + return; + } + + // Wait for layout to be ready + this.app.workspace.onLayoutReady(() => { + this.registerEvents(); + this.updateAllTitles(); + }); + } + + registerEvents() { + // Update styles when files change + this.registerEvent( + this.app.metadataCache.on('changed', () => { + this.updateAllTitles(); + }) + ); + + // Update on file explorer changes + this.registerEvent( + this.app.workspace.on('file-menu', () => { + this.updateAllTitles(); + }) + ); + + // Update when layout changes + this.registerEvent( + this.app.workspace.on('layout-change', () => { + this.updateAllTitles(); + }) + ); + } + + updateAllTitles() { + try { + // Get all markdown files + const files = this.app.vault.getMarkdownFiles(); + let cssRules = []; + + // Create CSS rules for each file with a frontmatter title + files.forEach(file => { + try { + const metadata = this.app.metadataCache.getFileCache(file); + const title = metadata?.frontmatter?.title; + + if (title) { + const escapedPath = CSS.escape(file.path); + const escapedTitle = title.replace(/"/g, '\\"'); + + cssRules.push(` + .nav-file-title[data-path="${escapedPath}"] .nav-file-title-content::after { + content: " (${escapedTitle})"; + color: var(--color-orange); + font-size: 0.85em; + opacity: 0.8; + } + `); + } + } catch (e) { + console.error('Error processing file:', file?.path, e); + } + }); + + // Update stylesheet content + if (this.styleEl) { + this.styleEl.textContent = cssRules.join("\n"); + } + } catch (error) { + console.error('Error updating titles:', error); + } + } + + onunload() { + console.log('Unloading TitleAppender plugin'); + if (this.styleEl) { + this.styleEl.remove(); + } + } +} + +module.exports = TitleAppenderPlugin; diff --git a/docs/.obsidian/plugins/docs-viewer/manifest.json b/docs/.obsidian/plugins/docs-viewer/manifest.json new file mode 100644 index 0000000..1095cc7 --- /dev/null +++ b/docs/.obsidian/plugins/docs-viewer/manifest.json @@ -0,0 +1,12 @@ +{ + "id": "docs-viewer", + "name": "docs-viewer", + "version": "2.9.2", + "minAppVersion": "1.1.6", + "description": "An Obsidian plugin to edit and view Docs-Viewer metadata", + "author": "Litruv", + "authorUrl": "https://lit.ruv.wtf", + "fundingUrl": "https://ko-fi.com/zsolt", + "helpUrl": "https://github.com/zsviczian/obsidian-excalidraw-plugin#readme", + "isDesktopOnly": false +} diff --git a/docs/.obsidian/plugins/docs-viewer/styles.css b/docs/.obsidian/plugins/docs-viewer/styles.css new file mode 100644 index 0000000..7804986 --- /dev/null +++ b/docs/.obsidian/plugins/docs-viewer/styles.css @@ -0,0 +1,40 @@ +.title-appended { + color: var(--text-normal); + display: inline; +} + +.title-metadata { + color: var(--color-orange); + font-size: 0.85em; + opacity: 0.8; + margin-left: 0; +} + +/* Icon and title styling */ +.title-icon { + margin-right: 5px; + font-size: 0.9em; + color: var(--color-orange); + flex-shrink: 0; +} + +.has-icon { + display: flex; + align-items: center; +} + + + +.nav-file-title-content { + padding: 0; + line-height: 1.1; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +/* Reduce indent for child items */ +.nav-folder .nav-folder .nav-file-title, +.nav-folder .nav-folder .nav-folder-title { + padding-left: 12px !important; +}