update plugin to work

This commit is contained in:
2025-03-25 00:14:06 +11:00
parent d919db86d7
commit 4f21edecc7
2 changed files with 51 additions and 13 deletions

View File

@@ -44,6 +44,10 @@ class TitleAppenderPlugin extends obsidian.Plugin {
el.classList.remove('has-sort-value', 'has-title');
el.removeAttribute('data-sort-value');
el.removeAttribute('data-title');
// Also remove any added elements
const sortSuffix = el.querySelector('.sort-suffix');
if (sortSuffix) sortSuffix.remove();
});
// Apply classes and attributes for each file with frontmatter
@@ -59,17 +63,28 @@ class TitleAppenderPlugin extends obsidian.Plugin {
const fileElement = document.querySelector(`.nav-file-title[data-path="${escapedPath}"] .nav-file-title-content`);
if (fileElement) {
// Add sort value if available
if (sortValue !== undefined) {
fileElement.classList.add('has-sort-value');
fileElement.setAttribute('data-sort-value', `[${sortValue}] `);
}
// Add title if available
if (title) {
fileElement.classList.add('has-title');
fileElement.setAttribute('data-title', ` (${title})`);
}
// Add sort value if available
if (sortValue !== undefined) {
fileElement.classList.add('has-sort-value');
// If both title and sort exist, create a span for the sort value
if (title) {
// Create a span for the sort value to apply different color
const sortSpan = document.createElement('span');
sortSpan.className = 'sort-suffix';
sortSpan.textContent = `[${sortValue}]`;
fileElement.appendChild(sortSpan);
} else {
// If only sort exists, use the attribute
fileElement.setAttribute('data-sort-value', `[${sortValue}]`);
}
}
}
}
} catch (e) {