mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 06:44:07 -06:00
move elements into drawTree()
This commit is contained in:
parent
962a7c9c88
commit
3396e972a5
@ -80,12 +80,35 @@ tree.forEach((el) => {
|
|||||||
parentEl.children = [...(parentEl.children || []), el];
|
parentEl.children = [...(parentEl.children || []), el];
|
||||||
});
|
});
|
||||||
|
|
||||||
// display tree structure
|
|
||||||
// from https://www.cssscript.com/folder-tree-json/
|
|
||||||
|
|
||||||
// keep track of the original node objects
|
|
||||||
const structure = root.children;
|
const structure = root.children;
|
||||||
|
|
||||||
|
// a temporary function to traverse the tree and allowing to display something
|
||||||
|
function* traverse(o, path = []) {
|
||||||
|
for (var i in o) {
|
||||||
|
const itemPath = path.concat(i);
|
||||||
|
yield [i, o[i], itemPath, o];
|
||||||
|
if (o[i] !== null && typeof o[i] == "object") {
|
||||||
|
//going one step down in the object tree!!
|
||||||
|
yield* traverse(o[i], itemPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log(structure)
|
||||||
|
for (var [key, value, path] of traverse(structure)) {
|
||||||
|
// console.log(key);
|
||||||
|
// console.log(value);
|
||||||
|
// console.log(path);
|
||||||
|
// console.log("---");
|
||||||
|
let doc = document.getElementById("tree").innerHTML
|
||||||
|
if (value?.type == "folder") {
|
||||||
|
document.getElementById("tree").innerHTML = doc + '<h3>'+value.name + '</h3>'
|
||||||
|
}
|
||||||
|
if (value?.type == "page") {
|
||||||
|
document.getElementById("tree").innerHTML = doc + ' <a href="' + value.href + '">'+ value.name+'</a><br/>'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return structure
|
return structure
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,41 +156,19 @@
|
|||||||
throwOnError : false
|
throwOnError : false
|
||||||
});
|
});
|
||||||
|
|
||||||
const siteBaseURL = new URL(BASE_URL);
|
// When the user clicks anywhere outside of the modal, close it
|
||||||
const pathBase = siteBaseURL.pathname;
|
window.onclick = function(event) {
|
||||||
|
if (event.target == modal) {
|
||||||
|
modal.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// a temporary function to traverse the tree and allowing to display something
|
{{end}}
|
||||||
function* traverse(o, path = []) {
|
|
||||||
for (var i in o) {
|
|
||||||
const itemPath = path.concat(i);
|
|
||||||
yield [i, o[i], itemPath, o];
|
|
||||||
if (o[i] !== null && typeof o[i] == "object") {
|
|
||||||
//going one step down in the object tree!!
|
|
||||||
yield* traverse(o[i], itemPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{{if $.Site.Data.config.enableColumnLayout}}
|
{{if $.Site.Data.config.enableColumnLayout}}
|
||||||
drawTree(pathBase).then(
|
const siteBaseURL = new URL(BASE_URL);
|
||||||
function(structure) {
|
const pathBase = siteBaseURL.pathname;
|
||||||
// console.log(structure)
|
drawTree(pathBase)
|
||||||
for (var [key, value, path] of traverse(structure)) {
|
|
||||||
// console.log(key);
|
|
||||||
// console.log(value);
|
|
||||||
// console.log(path);
|
|
||||||
// console.log("---");
|
|
||||||
let doc = document.getElementById("tree").innerHTML
|
|
||||||
if (value?.type == "folder") {
|
|
||||||
document.getElementById("tree").innerHTML = doc + '<h3>'+value.name + '</h3>'
|
|
||||||
}
|
|
||||||
if (value?.type == "page") {
|
|
||||||
document.getElementById("tree").innerHTML = doc + ' <a href="' + value.href + '">'+ value.name+'</a><br/>'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
// Get the modal
|
// Get the modal
|
||||||
var modal = document.getElementById("myModal");
|
var modal = document.getElementById("myModal");
|
||||||
@ -210,16 +188,8 @@
|
|||||||
span.onclick = function() {
|
span.onclick = function() {
|
||||||
modal.style.display = "none";
|
modal.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the user clicks anywhere outside of the modal, close it
|
|
||||||
window.onclick = function(event) {
|
|
||||||
if (event.target == modal) {
|
|
||||||
modal.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
{{if $.Site.Data.config.enableSPA}}
|
{{if $.Site.Data.config.enableSPA}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user