Added obsidian plugin for name highlight

This commit is contained in:
2025-03-24 23:44:17 +11:00
parent 8265accca7
commit 3d08672ec8
3 changed files with 145 additions and 0 deletions

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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;
}