-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove unused SVG widgets and update file_tree layout
- Loading branch information
1 parent
6e7c4e8
commit de906cc
Showing
6 changed files
with
74 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,73 @@ | ||
document.addEventListener("DOMContentLoaded", function() { | ||
function renderFileTree(container, nodes) { | ||
nodes.forEach(node => { | ||
const element = document.createElement('div'); | ||
element.classList.add('file-tree-node'); | ||
element.textContent = node.name; | ||
|
||
if (node.type === 'directory') { | ||
element.classList.add('directory'); | ||
const childrenContainer = document.createElement('div'); | ||
childrenContainer.classList.add('children'); | ||
renderFileTree(childrenContainer, node.children); | ||
element.appendChild(childrenContainer); | ||
function buildFileTree(element, tree) { | ||
const ul = document.createElement('ul'); | ||
element.appendChild(ul); | ||
|
||
tree.forEach(child => { | ||
const li = document.createElement('li'); | ||
ul.appendChild(li); | ||
|
||
const button = document.createElement('button'); | ||
button.textContent = child.name; | ||
li.appendChild(button); | ||
|
||
if (child.type === 'dir') { | ||
li.classList.add('dir'); | ||
const svgCollapsed = '<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m9 5 7 7-7 7"/></svg>'; | ||
const svgExpanded = '<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>'; | ||
button.innerHTML = svgCollapsed + button.textContent; | ||
|
||
var expanded = false; | ||
button.addEventListener('click', () => { | ||
expanded = !expanded; | ||
button.innerHTML = (expanded ? svgExpanded : svgCollapsed) + button.textContent; | ||
|
||
if (expanded) { | ||
// Check if the child nodes have already been created | ||
if (!li.querySelector('ul')) { | ||
buildFileTree(li, child.children); | ||
} | ||
} else { | ||
element.classList.add('file'); | ||
const nestedUl = li.querySelector('ul'); | ||
if (nestedUl) { | ||
li.removeChild(nestedUl); | ||
} | ||
} | ||
|
||
container.appendChild(element); | ||
}); | ||
} else if (child.type === 'file') { | ||
li.classList.add('file'); | ||
button.addEventListener('click', () => { | ||
console.log(child.path); | ||
}); | ||
} | ||
|
||
const fileTreeContainer = document.getElementById('file-tree'); | ||
renderFileTree(fileTreeContainer, fileTreeData); | ||
}); | ||
} | ||
|
||
//STUFF | ||
|
||
// function buildFileTree(element, tree) { | ||
// const ul = document.createElement('ul'); | ||
// element.appendChild(ul); | ||
|
||
// tree.forEach(child => { | ||
// const li = document.createElement('li'); | ||
// ul.appendChild(li); | ||
|
||
// const button = document.createElement('button'); | ||
// button.textContent = child.name; | ||
// li.appendChild(button); | ||
|
||
// if (child.type === 'dir') { | ||
// var expanded = false; | ||
// button.addEventListener('click', () => { | ||
// expanded = !expanded; | ||
// if (expanded) { | ||
// // Check if the child nodes have already been created | ||
// if (!li.querySelector('ul')) { | ||
// buildFileTree(li, child.children); | ||
// } | ||
// } else { | ||
// const nestedUl = li.querySelector('ul'); | ||
// if (nestedUl) { | ||
// li.removeChild(nestedUl); // Corrected line | ||
// } | ||
// } | ||
// }); | ||
// } else if (child.type === 'file') { | ||
// button.addEventListener('click', () => { | ||
// console.log(child.path); | ||
// }); | ||
// } | ||
// }); | ||
// } | ||
|
||
// var obsidianFilesJson = '{{ site.data.obsidian_files_json | escape }}'; | ||
// var parsedObsidianFilesJson = JSON.parse(obsidianFilesJson.replace(/"/g, '"')); | ||
|
||
// document.addEventListener('DOMContentLoaded', () => { | ||
// const rootElement = document.getElementById('fileTree'); | ||
// buildFileTree(rootElement, parsedObsidianFilesJson); | ||
// }); | ||
var obsidianFilesJson = '{{ site.data.obsidian_files_json | escape }}'; | ||
var parsedObsidianFilesJson = JSON.parse(obsidianFilesJson.replace(/"/g, '"')); | ||
|
||
function sortObsidianFiles(tree) { | ||
tree.sort((a, b) => { | ||
if (a.type === 'dir' && b.type === 'file') { | ||
return -1; | ||
} else if (a.type === 'file' && b.type === 'dir') { | ||
return 1; | ||
} else { | ||
return a.name.localeCompare(b.name); | ||
} | ||
}); | ||
tree.forEach(child => { | ||
if (child.type === 'dir') { | ||
sortObsidianFiles(child.children); | ||
} | ||
}); | ||
return tree; | ||
} | ||
|
||
// const fileTreeElement = document.getElementById('fileTree'); | ||
// createFileTree(fileTreeElement, tree); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const rootElement = document.getElementById('file-tree'); | ||
const sortedFiles = sortObsidianFiles(parsedObsidianFilesJson); | ||
buildFileTree(rootElement, sortedFiles); | ||
}); | ||
console.log(parsedObsidianFilesJson); | ||
console.log("DIR root " + '{{ site.obsidian_vault | escape }}') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters