Skip to content

Commit 45648e7

Browse files
committed
updates
1 parent 3d08672 commit 45648e7

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

docs/.obsidian/plugins/docs-viewer/main.js

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ class TitleAppenderPlugin extends obsidian.Plugin {
44
async onload() {
55
console.log('Loading TitleAppender plugin');
66

7-
// Create stylesheet element only once during initialization
8-
try {
9-
this.styleEl = document.head.createEl('style');
10-
this.styleEl.id = 'title-appender-styles';
11-
} catch (error) {
12-
console.error('Error creating style element:', error);
13-
return;
14-
}
15-
167
// Wait for layout to be ready
178
this.app.workspace.onLayoutReady(() => {
189
this.registerEvents();
@@ -47,46 +38,58 @@ class TitleAppenderPlugin extends obsidian.Plugin {
4738
try {
4839
// Get all markdown files
4940
const files = this.app.vault.getMarkdownFiles();
50-
let cssRules = [];
5141

52-
// Create CSS rules for each file with a frontmatter title
42+
// First, reset all previously set classes and attributes
43+
document.querySelectorAll('.has-sort-value, .has-title').forEach(el => {
44+
el.classList.remove('has-sort-value', 'has-title');
45+
el.removeAttribute('data-sort-value');
46+
el.removeAttribute('data-title');
47+
});
48+
49+
// Apply classes and attributes for each file with frontmatter
5350
files.forEach(file => {
5451
try {
5552
const metadata = this.app.metadataCache.getFileCache(file);
56-
const title = metadata?.frontmatter?.title;
53+
const frontmatter = metadata?.frontmatter;
54+
const title = frontmatter?.title;
55+
const sortValue = frontmatter?.sort;
5756

58-
if (title) {
57+
if (title || sortValue) {
5958
const escapedPath = CSS.escape(file.path);
60-
const escapedTitle = title.replace(/"/g, '\\"');
59+
const fileElement = document.querySelector(`.nav-file-title[data-path="${escapedPath}"] .nav-file-title-content`);
6160

62-
cssRules.push(`
63-
.nav-file-title[data-path="${escapedPath}"] .nav-file-title-content::after {
64-
content: " (${escapedTitle})";
65-
color: var(--color-orange);
66-
font-size: 0.85em;
67-
opacity: 0.8;
61+
if (fileElement) {
62+
// Add sort value if available
63+
if (sortValue !== undefined) {
64+
fileElement.classList.add('has-sort-value');
65+
fileElement.setAttribute('data-sort-value', `[${sortValue}] `);
6866
}
69-
`);
67+
68+
// Add title if available
69+
if (title) {
70+
fileElement.classList.add('has-title');
71+
fileElement.setAttribute('data-title', ` (${title})`);
72+
}
73+
}
7074
}
7175
} catch (e) {
7276
console.error('Error processing file:', file?.path, e);
7377
}
7478
});
75-
76-
// Update stylesheet content
77-
if (this.styleEl) {
78-
this.styleEl.textContent = cssRules.join("\n");
79-
}
8079
} catch (error) {
8180
console.error('Error updating titles:', error);
8281
}
8382
}
8483

8584
onunload() {
8685
console.log('Unloading TitleAppender plugin');
87-
if (this.styleEl) {
88-
this.styleEl.remove();
89-
}
86+
87+
// Clean up any added classes when unloading
88+
document.querySelectorAll('.has-sort-value, .has-title').forEach(el => {
89+
el.classList.remove('has-sort-value', 'has-title');
90+
el.removeAttribute('data-sort-value');
91+
el.removeAttribute('data-title');
92+
});
9093
}
9194
}
9295

docs/.obsidian/plugins/docs-viewer/styles.css

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@
1010
margin-left: 0;
1111
}
1212

13-
/* Icon and title styling */
14-
.title-icon {
15-
margin-right: 5px;
16-
font-size: 0.9em;
17-
color: var(--color-orange);
18-
flex-shrink: 0;
19-
}
20-
21-
.has-icon {
22-
display: flex;
23-
align-items: center;
13+
/* Sort value styling */
14+
.nav-file-title-content::before {
15+
margin-right: 4px;
2416
}
2517

26-
27-
2818
.nav-file-title-content {
2919
padding: 0;
3020
line-height: 1.1;
@@ -38,3 +28,18 @@
3828
.nav-folder .nav-folder .nav-folder-title {
3929
padding-left: 12px !important;
4030
}
31+
32+
/* Sort value styling */
33+
.has-sort-value::before {
34+
content: attr(data-sort-value);
35+
color: var(--color-yellow);
36+
margin-right: 2px;
37+
}
38+
39+
/* Title styling */
40+
.has-title::after {
41+
content: attr(data-title);
42+
color: var(--color-orange);
43+
font-size: 0.85em;
44+
opacity: 0.8;
45+
}

0 commit comments

Comments
 (0)