mirror of
https://github.com/litruv/Docs-Viewer.git
synced 2026-07-24 10:46:09 +10:00
Add folder configuration options and update Font Awesome version
This commit is contained in:
26
README.md
26
README.md
@@ -79,10 +79,34 @@ styles.css # Custom styling
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Configuring Folders
|
||||||
|
You can control whether a folder is expanded by default using `defaultOpen`. You can also specify a Font Awesome `icon`.
|
||||||
|
Both properties (`defaultOpen` and `icon`) are optional — if you omit them, the folder will use default behavior.
|
||||||
|
|
||||||
|
Example in index.json:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"title": "Folder 1",
|
||||||
|
"defaultOpen": true,
|
||||||
|
"icon": "fa-folder",
|
||||||
|
"documents": [
|
||||||
|
{
|
||||||
|
"title": "Document 1",
|
||||||
|
"path": "docs/Document1.md"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
- [marked](https://github.com/markedjs/marked) for Markdown parsing.
|
- [marked](https://github.com/markedjs/marked) for Markdown parsing.
|
||||||
- [Prism](https://prismjs.com/) for syntax highlighting.
|
- [highlight.js](https://highlightjs.org/) for syntax highlighting.
|
||||||
|
- [Font Awesome](https://fontawesome.com/) for icons
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<meta name="twitter:description" content="Documentation for Litruv's tools and projects">
|
<meta name="twitter:description" content="Documentation for Litruv's tools and projects">
|
||||||
|
|
||||||
<link rel="stylesheet" href="styles.css">
|
<link rel="stylesheet" href="styles.css">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.1/css/all.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github-dark.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github-dark.min.css">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
27
index.js
27
index.js
@@ -54,8 +54,11 @@ function createFileIndexItem(doc, container, level = 0) {
|
|||||||
|
|
||||||
const folderHeader = document.createElement('div');
|
const folderHeader = document.createElement('div');
|
||||||
folderHeader.className = 'folder-header';
|
folderHeader.className = 'folder-header';
|
||||||
|
|
||||||
|
// Use custom icon if provided, otherwise use default folder icon
|
||||||
|
const iconClass = doc.icon || `fas fa-folder${doc.defaultOpen !== false ? '-open' : ''}`;
|
||||||
folderHeader.innerHTML = `
|
folderHeader.innerHTML = `
|
||||||
<i class="fas fa-folder${doc.defaultOpen !== false ? '-open' : ''} folder-icon"></i>
|
<i class="${iconClass} folder-icon"></i>
|
||||||
<span>${doc.title}</span>
|
<span>${doc.title}</span>
|
||||||
`;
|
`;
|
||||||
folderDiv.appendChild(folderHeader);
|
folderDiv.appendChild(folderHeader);
|
||||||
@@ -67,8 +70,10 @@ function createFileIndexItem(doc, container, level = 0) {
|
|||||||
|
|
||||||
folderHeader.addEventListener('click', () => {
|
folderHeader.addEventListener('click', () => {
|
||||||
folderDiv.classList.toggle('open');
|
folderDiv.classList.toggle('open');
|
||||||
folderHeader.querySelector('.folder-icon').classList.toggle('fa-folder-closed');
|
if (!doc.icon) { // Only toggle folder icon if using default
|
||||||
folderHeader.querySelector('.folder-icon').classList.toggle('fa-folder-open');
|
folderHeader.querySelector('.folder-icon').classList.toggle('fa-folder-closed');
|
||||||
|
folderHeader.querySelector('.folder-icon').classList.toggle('fa-folder-open');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
container.appendChild(folderDiv);
|
container.appendChild(folderDiv);
|
||||||
@@ -348,10 +353,20 @@ async function loadDocument(path) {
|
|||||||
const svg = toggleBtn.querySelector('svg');
|
const svg = toggleBtn.querySelector('svg');
|
||||||
const isFolded = svg.style.transform === 'rotate(90deg)';
|
const isFolded = svg.style.transform === 'rotate(90deg)';
|
||||||
svg.style.transform = isFolded ? 'rotate(0deg)' : 'rotate(90deg)';
|
svg.style.transform = isFolded ? 'rotate(0deg)' : 'rotate(90deg)';
|
||||||
|
const currentLevel = parseInt(heading.tagName[1]);
|
||||||
let next = heading.nextElementSibling;
|
let next = heading.nextElementSibling;
|
||||||
while (next && !/^H[1-6]$/.test(next.tagName)) {
|
while (next) {
|
||||||
next.style.display = isFolded ? 'none' : '';
|
if (!/^H[1-6]$/.test(next.tagName)) {
|
||||||
next = next.nextElementSibling;
|
next.style.display = isFolded ? 'none' : '';
|
||||||
|
next = next.nextElementSibling;
|
||||||
|
} else {
|
||||||
|
const nextLevel = parseInt(next.tagName[1]);
|
||||||
|
if (nextLevel <= currentLevel) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next.style.display = isFolded ? 'none' : '';
|
||||||
|
next = next.nextElementSibling;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user