-
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: Update sidebar layout and add explorer panel, replacing the fil…
…e_tree.html panel
- Loading branch information
1 parent
3a17a1d
commit bc4ebd6
Showing
4 changed files
with
133 additions
and
110 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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<body> | ||
<!-- <div id="container"> --> | ||
<div id="vault-name">{{ site.obsidian_vault }}</div> | ||
<div id="file-tree"></div> | ||
<!-- </div> --> | ||
</body> | ||
|
||
<script lang="text/javascript"> | ||
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 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 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 { | ||
const nestedUl = li.querySelector('ul'); | ||
if (nestedUl) { | ||
li.removeChild(nestedUl); | ||
} | ||
} | ||
}); | ||
} else if (child.type === 'file') { | ||
li.classList.add('file'); | ||
button.addEventListener('click', () => { | ||
console.log(child.path); | ||
var vaultpath = '/' + '{{ site.obsidian_vault | escape }}' | ||
var event = new CustomEvent('obisidianFileSelected', { detail: vaultpath + child.path }); | ||
document.dispatchEvent(event); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
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; | ||
} | ||
|
||
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 }}') | ||
</script> | ||
|
||
<style> | ||
/* #container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-start; | ||
width: 20%; | ||
} | ||
#file-tree { | ||
overflow-y: auto; | ||
max-height: 100vh; | ||
width: 100%; | ||
} */ | ||
|
||
ul { | ||
list-style-type: none; | ||
padding-left: 5px; | ||
margin-left: 5px; | ||
} | ||
|
||
ul ul { | ||
padding-left: 10px; | ||
} | ||
</style> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<body> | ||
<div> | ||
amogus</div> | ||
</body> |
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