mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 14:34:23 +02:00
Compare commits
10 Commits
b5bf5e23a5
...
0855a3821b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0855a3821b | ||
![]() |
91189dfd2f | ||
![]() |
fbc45548f7 | ||
![]() |
883f4e6068 | ||
![]() |
e525f859c3 | ||
![]() |
cfcce875a9 | ||
![]() |
fafdb2719a | ||
![]() |
57e6af3a34 | ||
![]() |
799c8c4fc1 | ||
![]() |
fc901e1084 |
@ -36,6 +36,7 @@ Component.Graph({
|
|||||||
opacityScale: 1, // how quickly do we fade out the labels when zooming out?
|
opacityScale: 1, // how quickly do we fade out the labels when zooming out?
|
||||||
removeTags: [], // what tags to remove from the graph
|
removeTags: [], // what tags to remove from the graph
|
||||||
showTags: true, // whether to show tags in the graph
|
showTags: true, // whether to show tags in the graph
|
||||||
|
enableRadial: false, // whether to constrain the graph, similar to Obsidian
|
||||||
},
|
},
|
||||||
globalGraph: {
|
globalGraph: {
|
||||||
drag: true,
|
drag: true,
|
||||||
@ -49,6 +50,7 @@ Component.Graph({
|
|||||||
opacityScale: 1,
|
opacityScale: 1,
|
||||||
removeTags: [], // what tags to remove from the graph
|
removeTags: [], // what tags to remove from the graph
|
||||||
showTags: true, // whether to show tags in the graph
|
showTags: true, // whether to show tags in the graph
|
||||||
|
enableRadial: true, // whether to constrain the graph, similar to Obsidian
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -27,7 +27,7 @@ export const defaultContentPageLayout: PageLayout = {
|
|||||||
Component.MobileOnly(Component.Spacer()),
|
Component.MobileOnly(Component.Spacer()),
|
||||||
Component.Search(),
|
Component.Search(),
|
||||||
Component.Darkmode(),
|
Component.Darkmode(),
|
||||||
Component.DesktopOnly(Component.Explorer()),
|
Component.Explorer(),
|
||||||
],
|
],
|
||||||
right: [
|
right: [
|
||||||
Component.Graph(),
|
Component.Graph(),
|
||||||
@ -44,7 +44,7 @@ export const defaultListPageLayout: PageLayout = {
|
|||||||
Component.MobileOnly(Component.Spacer()),
|
Component.MobileOnly(Component.Spacer()),
|
||||||
Component.Search(),
|
Component.Search(),
|
||||||
Component.Darkmode(),
|
Component.Darkmode(),
|
||||||
Component.DesktopOnly(Component.Explorer()),
|
Component.Explorer(),
|
||||||
],
|
],
|
||||||
right: [],
|
right: [],
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Date, getDate } from "./Date"
|
import { formatDate, getDate } from "./Date"
|
||||||
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import readingTime from "reading-time"
|
import readingTime from "reading-time"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
@ -30,7 +30,7 @@ export default ((opts?: Partial<ContentMetaOptions>) => {
|
|||||||
const segments: (string | JSX.Element)[] = []
|
const segments: (string | JSX.Element)[] = []
|
||||||
|
|
||||||
if (fileData.dates) {
|
if (fileData.dates) {
|
||||||
segments.push(<Date date={getDate(cfg, fileData)!} locale={cfg.locale} />)
|
segments.push(formatDate(getDate(cfg, fileData)!))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display reading time if enabled
|
// Display reading time if enabled
|
||||||
|
@ -27,5 +27,5 @@ export function formatDate(d: Date, locale: ValidLocale = "en-US"): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Date({ date, locale }: Props) {
|
export function Date({ date, locale }: Props) {
|
||||||
return <time datetime={date.toISOString()}>{formatDate(date, locale)}</time>
|
return <>{formatDate(date, locale)}</>
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import explorerStyle from "./styles/explorer.scss"
|
import style from "./styles/explorer.scss"
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import script from "./scripts/explorer.inline"
|
import script from "./scripts/explorer.inline"
|
||||||
@ -83,18 +83,46 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
lastBuildId = ctx.buildId
|
lastBuildId = ctx.buildId
|
||||||
constructFileTree(allFiles)
|
constructFileTree(allFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={classNames(displayClass, "explorer")}>
|
<div class={classNames(displayClass, "explorer")}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
id="explorer"
|
id="mobile-explorer"
|
||||||
|
class="collapsed hide-until-loaded"
|
||||||
data-behavior={opts.folderClickBehavior}
|
data-behavior={opts.folderClickBehavior}
|
||||||
data-collapsed={opts.folderDefaultState}
|
data-collapsed={opts.folderDefaultState}
|
||||||
data-savestate={opts.useSavedState}
|
data-savestate={opts.useSavedState}
|
||||||
data-tree={jsonTree}
|
data-tree={jsonTree}
|
||||||
|
data-mobile={true}
|
||||||
aria-controls="explorer-content"
|
aria-controls="explorer-content"
|
||||||
aria-expanded={opts.folderDefaultState === "open"}
|
aria-expanded={false}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="lucide lucide-menu"
|
||||||
|
>
|
||||||
|
<line x1="4" x2="20" y1="12" y2="12" />
|
||||||
|
<line x1="4" x2="20" y1="6" y2="6" />
|
||||||
|
<line x1="4" x2="20" y1="18" y2="18" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
id="desktop-explorer"
|
||||||
|
class="title-button"
|
||||||
|
data-behavior={opts.folderClickBehavior}
|
||||||
|
data-collapsed={opts.folderDefaultState}
|
||||||
|
data-savestate={opts.useSavedState}
|
||||||
|
data-tree={jsonTree}
|
||||||
|
data-mobile={false}
|
||||||
|
aria-controls="explorer-content"
|
||||||
|
aria-expanded={true}
|
||||||
>
|
>
|
||||||
<h2>{opts.title ?? i18n(cfg.locale).components.explorer.title}</h2>
|
<h2>{opts.title ?? i18n(cfg.locale).components.explorer.title}</h2>
|
||||||
<svg
|
<svg
|
||||||
@ -113,16 +141,16 @@ export default ((userOpts?: Partial<Options>) => {
|
|||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<div id="explorer-content">
|
<div id="explorer-content">
|
||||||
<ul class="overflow" id="explorer-ul">
|
<menu class="overflow" id="explorer-ul">
|
||||||
<ExplorerNode node={fileTree} opts={opts} fileData={fileData} />
|
<ExplorerNode node={fileTree} opts={opts} fileData={fileData} />
|
||||||
<li id="explorer-end" />
|
<li id="explorer-end" />
|
||||||
</ul>
|
</menu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Explorer.css = explorerStyle
|
Explorer.css = style
|
||||||
Explorer.afterDOMLoaded = script
|
Explorer.afterDOMLoaded = script
|
||||||
return Explorer
|
return Explorer
|
||||||
}) satisfies QuartzComponentConstructor
|
}) satisfies QuartzComponentConstructor
|
||||||
|
@ -216,7 +216,7 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
|
|||||||
)}
|
)}
|
||||||
{/* Recursively render children of folder */}
|
{/* Recursively render children of folder */}
|
||||||
<div class={`folder-outer ${node.depth === 0 || isDefaultOpen ? "open" : ""}`}>
|
<div class={`folder-outer ${node.depth === 0 || isDefaultOpen ? "open" : ""}`}>
|
||||||
<ul
|
<menu
|
||||||
// Inline style for left folder paddings
|
// Inline style for left folder paddings
|
||||||
style={{
|
style={{
|
||||||
paddingLeft: node.name !== "" ? "1.4rem" : "0",
|
paddingLeft: node.name !== "" ? "1.4rem" : "0",
|
||||||
@ -233,7 +233,7 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro
|
|||||||
fileData={fileData}
|
fileData={fileData}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</menu>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
|
@ -18,6 +18,7 @@ export interface D3Config {
|
|||||||
removeTags: string[]
|
removeTags: string[]
|
||||||
showTags: boolean
|
showTags: boolean
|
||||||
focusOnHover?: boolean
|
focusOnHover?: boolean
|
||||||
|
enableRadial?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GraphOptions {
|
interface GraphOptions {
|
||||||
@ -39,6 +40,7 @@ const defaultOptions: GraphOptions = {
|
|||||||
showTags: true,
|
showTags: true,
|
||||||
removeTags: [],
|
removeTags: [],
|
||||||
focusOnHover: false,
|
focusOnHover: false,
|
||||||
|
enableRadial: false,
|
||||||
},
|
},
|
||||||
globalGraph: {
|
globalGraph: {
|
||||||
drag: true,
|
drag: true,
|
||||||
@ -53,10 +55,11 @@ const defaultOptions: GraphOptions = {
|
|||||||
showTags: true,
|
showTags: true,
|
||||||
removeTags: [],
|
removeTags: [],
|
||||||
focusOnHover: true,
|
focusOnHover: true,
|
||||||
|
enableRadial: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ((opts?: GraphOptions) => {
|
export default ((opts?: Partial<GraphOptions>) => {
|
||||||
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
const Graph: QuartzComponent = ({ displayClass, cfg }: QuartzComponentProps) => {
|
||||||
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
|
const localGraph = { ...defaultOptions.localGraph, ...opts?.localGraph }
|
||||||
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
|
const globalGraph = { ...defaultOptions.globalGraph, ...opts?.globalGraph }
|
||||||
|
@ -9,7 +9,7 @@ header {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin: 2rem 0;
|
padding: 1rem 2rem;
|
||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export default ((userOpts?: Partial<SearchOptions>) => {
|
|||||||
const opts = { ...defaultOptions, ...userOpts }
|
const opts = { ...defaultOptions, ...userOpts }
|
||||||
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
const searchPlaceholder = i18n(cfg.locale).components.search.searchBarPlaceholder
|
||||||
return (
|
return (
|
||||||
<div class={classNames(displayClass, "search")}>
|
<search class={classNames(displayClass, "search")}>
|
||||||
<button class="search-button" id="search-button">
|
<button class="search-button" id="search-button">
|
||||||
<p>{i18n(cfg.locale).components.search.title}</p>
|
<p>{i18n(cfg.locale).components.search.title}</p>
|
||||||
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19.9 19.7">
|
||||||
@ -42,7 +42,7 @@ export default ((userOpts?: Partial<SearchOptions>) => {
|
|||||||
<div id="search-layout" data-preview={opts.enablePreview}></div>
|
<div id="search-layout" data-preview={opts.enablePreview}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</search>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,19 +221,19 @@ export function renderPage(
|
|||||||
const Body = BodyConstructor()
|
const Body = BodyConstructor()
|
||||||
|
|
||||||
const LeftComponent = (
|
const LeftComponent = (
|
||||||
<div class="left sidebar">
|
<aside class="left sidebar">
|
||||||
{left.map((BodyComponent) => (
|
{left.map((BodyComponent) => (
|
||||||
<BodyComponent {...componentData} />
|
<BodyComponent {...componentData} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</aside>
|
||||||
)
|
)
|
||||||
|
|
||||||
const RightComponent = (
|
const RightComponent = (
|
||||||
<div class="right sidebar">
|
<aside class="right sidebar">
|
||||||
{right.map((BodyComponent) => (
|
{right.map((BodyComponent) => (
|
||||||
<BodyComponent {...componentData} />
|
<BodyComponent {...componentData} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</aside>
|
||||||
)
|
)
|
||||||
|
|
||||||
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
|
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
|
||||||
@ -242,29 +242,31 @@ export function renderPage(
|
|||||||
<Head {...componentData} />
|
<Head {...componentData} />
|
||||||
<body data-slug={slug}>
|
<body data-slug={slug}>
|
||||||
<div id="quartz-root" class="page">
|
<div id="quartz-root" class="page">
|
||||||
<Body {...componentData}>
|
|
||||||
{LeftComponent}
|
|
||||||
<div class="center">
|
|
||||||
<div class="page-header">
|
|
||||||
<Header {...componentData}>
|
<Header {...componentData}>
|
||||||
{header.map((HeaderComponent) => (
|
{header.map((HeaderComponent) => (
|
||||||
<HeaderComponent {...componentData} />
|
<HeaderComponent {...componentData} />
|
||||||
))}
|
))}
|
||||||
</Header>
|
</Header>
|
||||||
|
<Body {...componentData}>
|
||||||
|
{LeftComponent}
|
||||||
|
<section class="center">
|
||||||
|
<div class="page-header">
|
||||||
<div class="popover-hint">
|
<div class="popover-hint">
|
||||||
{beforeBody.map((BodyComponent) => (
|
{beforeBody.map((BodyComponent) => (
|
||||||
<BodyComponent {...componentData} />
|
<BodyComponent {...componentData} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<main>
|
||||||
<Content {...componentData} />
|
<Content {...componentData} />
|
||||||
|
</main>
|
||||||
<hr />
|
<hr />
|
||||||
<div class="page-footer">
|
<div class="page-footer">
|
||||||
{afterBody.map((BodyComponent) => (
|
{afterBody.map((BodyComponent) => (
|
||||||
<BodyComponent {...componentData} />
|
<BodyComponent {...componentData} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
{RightComponent}
|
{RightComponent}
|
||||||
<Footer {...componentData} />
|
<Footer {...componentData} />
|
||||||
</Body>
|
</Body>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import { FolderState } from "../ExplorerNode"
|
import { FolderState } from "../ExplorerNode"
|
||||||
|
|
||||||
|
// Current state of folders
|
||||||
type MaybeHTMLElement = HTMLElement | undefined
|
type MaybeHTMLElement = HTMLElement | undefined
|
||||||
let currentExplorerState: FolderState[]
|
let currentExplorerState: FolderState[]
|
||||||
|
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
// If last element is observed, remove gradient of "overflow" class so element is visible
|
// If last element is observed, remove gradient of "overflow" class so element is visible
|
||||||
const explorerUl = document.getElementById("explorer-ul")
|
const explorerUl = document.getElementById("explorer-ul")
|
||||||
@ -16,23 +18,43 @@ const observer = new IntersectionObserver((entries) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function toggleExplorer(this: HTMLElement) {
|
function toggleExplorer(this: HTMLElement) {
|
||||||
|
// Toggle collapsed state of entire explorer
|
||||||
this.classList.toggle("collapsed")
|
this.classList.toggle("collapsed")
|
||||||
|
|
||||||
|
// Toggle collapsed aria state of entire explorer
|
||||||
this.setAttribute(
|
this.setAttribute(
|
||||||
"aria-expanded",
|
"aria-expanded",
|
||||||
this.getAttribute("aria-expanded") === "true" ? "false" : "true",
|
this.getAttribute("aria-expanded") === "true" ? "false" : "true",
|
||||||
)
|
)
|
||||||
const content = this.nextElementSibling as MaybeHTMLElement
|
|
||||||
if (!content) return
|
|
||||||
|
|
||||||
|
const content = (
|
||||||
|
this.nextElementSibling?.nextElementSibling
|
||||||
|
? this.nextElementSibling.nextElementSibling
|
||||||
|
: this.nextElementSibling
|
||||||
|
) as MaybeHTMLElement
|
||||||
|
if (!content) return
|
||||||
content.classList.toggle("collapsed")
|
content.classList.toggle("collapsed")
|
||||||
|
content.classList.toggle("explorer-viewmode")
|
||||||
|
|
||||||
|
// Prevent scroll under
|
||||||
|
if (document.querySelector("#mobile-explorer")) {
|
||||||
|
// Disable scrolling on the page when the explorer is opened on mobile
|
||||||
|
const bodySelector = document.querySelector("#quartz-body")
|
||||||
|
if (bodySelector) bodySelector.classList.toggle("lock-scroll")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleFolder(evt: MouseEvent) {
|
function toggleFolder(evt: MouseEvent) {
|
||||||
evt.stopPropagation()
|
evt.stopPropagation()
|
||||||
|
|
||||||
|
// Element that was clicked
|
||||||
const target = evt.target as MaybeHTMLElement
|
const target = evt.target as MaybeHTMLElement
|
||||||
if (!target) return
|
if (!target) return
|
||||||
|
|
||||||
|
// Check if target was svg icon or button
|
||||||
const isSvg = target.nodeName === "svg"
|
const isSvg = target.nodeName === "svg"
|
||||||
|
|
||||||
|
// corresponding <ul> element relative to clicked button/folder
|
||||||
const childFolderContainer = (
|
const childFolderContainer = (
|
||||||
isSvg
|
isSvg
|
||||||
? target.parentElement?.nextSibling
|
? target.parentElement?.nextSibling
|
||||||
@ -42,10 +64,14 @@ function toggleFolder(evt: MouseEvent) {
|
|||||||
isSvg ? target.nextElementSibling : target.parentElement
|
isSvg ? target.nextElementSibling : target.parentElement
|
||||||
) as MaybeHTMLElement
|
) as MaybeHTMLElement
|
||||||
if (!(childFolderContainer && currentFolderParent)) return
|
if (!(childFolderContainer && currentFolderParent)) return
|
||||||
|
// <li> element of folder (stores folder-path dataset)
|
||||||
childFolderContainer.classList.toggle("open")
|
childFolderContainer.classList.toggle("open")
|
||||||
|
|
||||||
|
// Collapse folder container
|
||||||
const isCollapsed = childFolderContainer.classList.contains("open")
|
const isCollapsed = childFolderContainer.classList.contains("open")
|
||||||
setFolderState(childFolderContainer, !isCollapsed)
|
setFolderState(childFolderContainer, !isCollapsed)
|
||||||
|
|
||||||
|
// Save folder state to localStorage
|
||||||
const fullFolderPath = currentFolderParent.dataset.folderpath as string
|
const fullFolderPath = currentFolderParent.dataset.folderpath as string
|
||||||
toggleCollapsedByPath(currentExplorerState, fullFolderPath)
|
toggleCollapsedByPath(currentExplorerState, fullFolderPath)
|
||||||
const stringifiedFileTree = JSON.stringify(currentExplorerState)
|
const stringifiedFileTree = JSON.stringify(currentExplorerState)
|
||||||
@ -53,20 +79,34 @@ function toggleFolder(evt: MouseEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupExplorer() {
|
function setupExplorer() {
|
||||||
const explorer = document.getElementById("explorer")
|
// Set click handler for collapsing entire explorer
|
||||||
if (!explorer) return
|
const allExplorers = document.querySelectorAll(".explorer > button") as NodeListOf<HTMLElement>
|
||||||
|
|
||||||
if (explorer.dataset.behavior === "collapse") {
|
for (const explorer of allExplorers) {
|
||||||
|
// Get folder state from local storage
|
||||||
|
const storageTree = localStorage.getItem("fileTree")
|
||||||
|
|
||||||
|
// Convert to bool
|
||||||
|
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
||||||
|
|
||||||
|
if (explorer) {
|
||||||
|
// Get config
|
||||||
|
const collapseBehavior = explorer.dataset.behavior
|
||||||
|
|
||||||
|
// Add click handlers for all folders (click handler on folder "label")
|
||||||
|
if (collapseBehavior === "collapse") {
|
||||||
for (const item of document.getElementsByClassName(
|
for (const item of document.getElementsByClassName(
|
||||||
"folder-button",
|
"folder-button",
|
||||||
) as HTMLCollectionOf<HTMLElement>) {
|
) as HTMLCollectionOf<HTMLElement>) {
|
||||||
|
window.addCleanup(() => explorer.removeEventListener("click", toggleExplorer))
|
||||||
item.addEventListener("click", toggleFolder)
|
item.addEventListener("click", toggleFolder)
|
||||||
window.addCleanup(() => item.removeEventListener("click", toggleFolder))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
explorer.addEventListener("click", toggleExplorer)
|
// Add click handler to main explorer
|
||||||
window.addCleanup(() => explorer.removeEventListener("click", toggleExplorer))
|
window.addCleanup(() => explorer.removeEventListener("click", toggleExplorer))
|
||||||
|
explorer.addEventListener("click", toggleExplorer)
|
||||||
|
}
|
||||||
|
|
||||||
// Set up click handlers for each folder (click handler on folder "icon")
|
// Set up click handlers for each folder (click handler on folder "icon")
|
||||||
for (const item of document.getElementsByClassName(
|
for (const item of document.getElementsByClassName(
|
||||||
@ -77,8 +117,6 @@ function setupExplorer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get folder state from local storage
|
// Get folder state from local storage
|
||||||
const storageTree = localStorage.getItem("fileTree")
|
|
||||||
const useSavedFolderState = explorer?.dataset.savestate === "true"
|
|
||||||
const oldExplorerState: FolderState[] =
|
const oldExplorerState: FolderState[] =
|
||||||
storageTree && useSavedFolderState ? JSON.parse(storageTree) : []
|
storageTree && useSavedFolderState ? JSON.parse(storageTree) : []
|
||||||
const oldIndex = new Map(oldExplorerState.map((entry) => [entry.path, entry.collapsed]))
|
const oldIndex = new Map(oldExplorerState.map((entry) => [entry.path, entry.collapsed]))
|
||||||
@ -86,24 +124,61 @@ function setupExplorer() {
|
|||||||
? JSON.parse(explorer.dataset.tree)
|
? JSON.parse(explorer.dataset.tree)
|
||||||
: []
|
: []
|
||||||
currentExplorerState = []
|
currentExplorerState = []
|
||||||
|
|
||||||
for (const { path, collapsed } of newExplorerState) {
|
for (const { path, collapsed } of newExplorerState) {
|
||||||
currentExplorerState.push({ path, collapsed: oldIndex.get(path) ?? collapsed })
|
currentExplorerState.push({
|
||||||
|
path,
|
||||||
|
collapsed: oldIndex.get(path) ?? collapsed,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
currentExplorerState.map((folderState) => {
|
currentExplorerState.map((folderState) => {
|
||||||
const folderLi = document.querySelector(
|
const folderLi = document.querySelector(
|
||||||
`[data-folderpath='${folderState.path}']`,
|
`[data-folderpath='${folderState.path.replace("'", "-")}']`,
|
||||||
) as MaybeHTMLElement
|
) as MaybeHTMLElement
|
||||||
const folderUl = folderLi?.parentElement?.nextElementSibling as MaybeHTMLElement
|
const folderUl = folderLi?.parentElement?.nextElementSibling as MaybeHTMLElement
|
||||||
if (folderUl) {
|
if (folderUl) {
|
||||||
setFolderState(folderUl, folderState.collapsed)
|
setFolderState(folderUl, folderState.collapsed)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleExplorerFolders() {
|
||||||
|
const currentFile = (document.querySelector("body")?.getAttribute("data-slug") ?? "").replace(
|
||||||
|
/\/index$/g,
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
const allFolders = document.querySelectorAll(".folder-outer")
|
||||||
|
|
||||||
|
allFolders.forEach((element) => {
|
||||||
|
const folderUl = Array.from(element.children).find((child) =>
|
||||||
|
child.matches("ul[data-folderul]"),
|
||||||
|
)
|
||||||
|
if (folderUl) {
|
||||||
|
if (currentFile.includes(folderUl.getAttribute("data-folderul") ?? "")) {
|
||||||
|
if (!element.classList.contains("open")) {
|
||||||
|
element.classList.add("open")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", setupExplorer)
|
window.addEventListener("resize", setupExplorer)
|
||||||
|
|
||||||
document.addEventListener("nav", () => {
|
document.addEventListener("nav", () => {
|
||||||
|
const explorer = document.querySelector("#mobile-explorer")
|
||||||
|
if (explorer) {
|
||||||
|
explorer.classList.add("collapsed")
|
||||||
|
const content = explorer.nextElementSibling?.nextElementSibling as HTMLElement
|
||||||
|
if (content) {
|
||||||
|
content.classList.add("collapsed")
|
||||||
|
content.classList.toggle("explorer-viewmode")
|
||||||
|
}
|
||||||
|
}
|
||||||
setupExplorer()
|
setupExplorer()
|
||||||
|
|
||||||
observer.disconnect()
|
observer.disconnect()
|
||||||
|
|
||||||
// select pseudo element at end of list
|
// select pseudo element at end of list
|
||||||
@ -111,6 +186,12 @@ document.addEventListener("nav", () => {
|
|||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
observer.observe(lastItem)
|
observer.observe(lastItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hide explorer on mobile until it is requested
|
||||||
|
const hiddenUntilDoneLoading = document.querySelector("#mobile-explorer")
|
||||||
|
hiddenUntilDoneLoading?.classList.remove("hide-until-loaded")
|
||||||
|
|
||||||
|
toggleExplorerFolders()
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
forceCenter,
|
forceCenter,
|
||||||
forceLink,
|
forceLink,
|
||||||
forceCollide,
|
forceCollide,
|
||||||
|
forceRadial,
|
||||||
zoomIdentity,
|
zoomIdentity,
|
||||||
select,
|
select,
|
||||||
drag,
|
drag,
|
||||||
@ -87,6 +88,7 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
removeTags,
|
removeTags,
|
||||||
showTags,
|
showTags,
|
||||||
focusOnHover,
|
focusOnHover,
|
||||||
|
enableRadial,
|
||||||
} = JSON.parse(graph.dataset["cfg"]!) as D3Config
|
} = JSON.parse(graph.dataset["cfg"]!) as D3Config
|
||||||
|
|
||||||
const data: Map<SimpleSlug, ContentDetails> = new Map(
|
const data: Map<SimpleSlug, ContentDetails> = new Map(
|
||||||
@ -161,15 +163,20 @@ async function renderGraph(container: string, fullSlug: FullSlug) {
|
|||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const width = graph.offsetWidth
|
||||||
|
const height = Math.max(graph.offsetHeight, 250)
|
||||||
|
|
||||||
// we virtualize the simulation and use pixi to actually render it
|
// we virtualize the simulation and use pixi to actually render it
|
||||||
|
// Calculate the radius of the container circle
|
||||||
|
const radius = Math.min(width, height) / 2 - 40 // 40px padding
|
||||||
const simulation: Simulation<NodeData, LinkData> = forceSimulation<NodeData>(graphData.nodes)
|
const simulation: Simulation<NodeData, LinkData> = forceSimulation<NodeData>(graphData.nodes)
|
||||||
.force("charge", forceManyBody().strength(-100 * repelForce))
|
.force("charge", forceManyBody().strength(-100 * repelForce))
|
||||||
.force("center", forceCenter().strength(centerForce))
|
.force("center", forceCenter().strength(centerForce))
|
||||||
.force("link", forceLink(graphData.links).distance(linkDistance))
|
.force("link", forceLink(graphData.links).distance(linkDistance))
|
||||||
.force("collide", forceCollide<NodeData>((n) => nodeRadius(n)).iterations(3))
|
.force("collide", forceCollide<NodeData>((n) => nodeRadius(n)).iterations(3))
|
||||||
|
|
||||||
const width = graph.offsetWidth
|
if (enableRadial)
|
||||||
const height = Math.max(graph.offsetHeight, 250)
|
simulation.force("radial", forceRadial(radius * 0.8, width / 2, height / 2).strength(0.3))
|
||||||
|
|
||||||
// precompute style prop strings as pixi doesn't support css variables
|
// precompute style prop strings as pixi doesn't support css variables
|
||||||
const cssVars = [
|
const cssVars = [
|
||||||
|
@ -1,14 +1,70 @@
|
|||||||
@use "../../styles/variables.scss" as *;
|
@use "../../styles/variables.scss" as *;
|
||||||
|
|
||||||
|
@media all and ($mobile) {
|
||||||
|
.page > #quartz-body {
|
||||||
|
// Shift page position when toggling Explorer on mobile.
|
||||||
|
& > :not(.sidebar.left:has(.explorer)) {
|
||||||
|
transform: translateX(0);
|
||||||
|
transition: transform 300ms ease-in-out;
|
||||||
|
}
|
||||||
|
&.lock-scroll > :not(.sidebar.left:has(.explorer)) {
|
||||||
|
transform: translateX(100dvw);
|
||||||
|
transition: transform 300ms ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sticky top bar (stays in place when scrolling down on mobile).
|
||||||
|
.sidebar.left:has(.explorer) {
|
||||||
|
box-sizing: border-box;
|
||||||
|
position: sticky;
|
||||||
|
background-color: var(--light);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide Explorer on mobile until done loading.
|
||||||
|
// Prevents ugly animation on page load.
|
||||||
|
.hide-until-loaded ~ #explorer-content {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.explorer {
|
.explorer {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
|
||||||
|
@media all and ($mobile) {
|
||||||
|
order: -1;
|
||||||
|
height: initial;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
align-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
button#mobile-explorer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
button#desktop-explorer {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and ($mobile) {
|
||||||
|
button#mobile-explorer {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
button#desktop-explorer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.desktop-only {
|
&.desktop-only {
|
||||||
@media all and not ($mobile) {
|
@media all and not ($mobile) {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*&:after {
|
/*&:after {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
content: "";
|
content: "";
|
||||||
@ -23,7 +79,8 @@
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
button#explorer {
|
button#mobile-explorer,
|
||||||
|
button#desktop-explorer {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
@ -60,7 +117,7 @@ button#explorer {
|
|||||||
grid-template-rows: 1fr;
|
grid-template-rows: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.folder-outer > ul {
|
.folder-outer > menu {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,22 +125,22 @@ button#explorer {
|
|||||||
list-style: none;
|
list-style: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
max-height: 0px;
|
||||||
|
transition:
|
||||||
|
max-height 0.35s ease,
|
||||||
|
visibility 0s linear 0.35s;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
visibility: hidden;
|
||||||
|
|
||||||
|
&.collapsed {
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
transition:
|
transition:
|
||||||
max-height 0.35s ease,
|
max-height 0.35s ease,
|
||||||
visibility 0s linear 0s;
|
visibility 0s linear 0s;
|
||||||
margin-top: 0.5rem;
|
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
|
|
||||||
&.collapsed {
|
|
||||||
max-height: 0;
|
|
||||||
transition:
|
|
||||||
max-height 0.35s ease,
|
|
||||||
visibility 0s linear 0.35s;
|
|
||||||
visibility: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
& ul {
|
& menu {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0.08rem 0;
|
margin: 0.08rem 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@ -91,12 +148,14 @@ button#explorer {
|
|||||||
max-height 0.35s ease,
|
max-height 0.35s ease,
|
||||||
transform 0.35s ease,
|
transform 0.35s ease,
|
||||||
opacity 0.2s ease;
|
opacity 0.2s ease;
|
||||||
|
|
||||||
& li > a {
|
& li > a {
|
||||||
color: var(--dark);
|
color: var(--dark);
|
||||||
opacity: 0.75;
|
opacity: 0.75;
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
> #explorer-ul {
|
> #explorer-ul {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
@ -179,3 +238,80 @@ li:has(> .folder-outer:not(.open)) > .folder-container > svg {
|
|||||||
// remove default margin from li
|
// remove default margin from li
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.explorer {
|
||||||
|
@media all and ($mobile) {
|
||||||
|
#explorer-content {
|
||||||
|
box-sizing: border-box;
|
||||||
|
overscroll-behavior: none;
|
||||||
|
z-index: 100;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
background-color: var(--light);
|
||||||
|
max-width: 100dvw;
|
||||||
|
left: -100dvw;
|
||||||
|
width: 100%;
|
||||||
|
transition: transform 300ms ease-in-out;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: $topSpacing 2rem 2rem;
|
||||||
|
height: 100dvh;
|
||||||
|
max-height: 100dvh;
|
||||||
|
margin-top: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
|
||||||
|
&:not(.collapsed) {
|
||||||
|
transform: translateX(100dvw);
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.overflow {
|
||||||
|
max-height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.collapsed {
|
||||||
|
transform: translateX(0);
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#mobile-explorer {
|
||||||
|
margin: 5px;
|
||||||
|
z-index: 101;
|
||||||
|
|
||||||
|
&:not(.collapsed) .lucide-menu {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
transition: transform 200ms ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lucide-menu {
|
||||||
|
stroke: var(--darkgray);
|
||||||
|
transition: transform 200ms ease;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
stroke: var(--dark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-scroll {
|
||||||
|
opacity: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
html:has(.no-scroll) {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and not ($mobile) {
|
||||||
|
.no-scroll {
|
||||||
|
opacity: 1 !important;
|
||||||
|
overflow: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html:has(.no-scroll) {
|
||||||
|
overflow: auto !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -125,6 +125,7 @@ a {
|
|||||||
.page {
|
.page {
|
||||||
max-width: calc(#{map.get($breakpoints, desktop)} + 300px);
|
max-width: calc(#{map.get($breakpoints, desktop)} + 300px);
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
||||||
& article {
|
& article {
|
||||||
& > h1 {
|
& > h1 {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
@ -235,7 +236,7 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
& .page-header {
|
& .page-header {
|
||||||
grid-area: grid-header;
|
grid-area: grid-page-header;
|
||||||
margin: $topSpacing 0 0 0;
|
margin: $topSpacing 0 0 0;
|
||||||
@media all and ($mobile) {
|
@media all and ($mobile) {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
@ -30,7 +30,7 @@ $mobileGrid: (
|
|||||||
columnGap: "5px",
|
columnGap: "5px",
|
||||||
templateAreas:
|
templateAreas:
|
||||||
'"grid-sidebar-left"\
|
'"grid-sidebar-left"\
|
||||||
"grid-header"\
|
"grid-page-header"\
|
||||||
"grid-center"\
|
"grid-center"\
|
||||||
"grid-sidebar-right"\
|
"grid-sidebar-right"\
|
||||||
"grid-footer"',
|
"grid-footer"',
|
||||||
@ -41,7 +41,7 @@ $tabletGrid: (
|
|||||||
rowGap: "5px",
|
rowGap: "5px",
|
||||||
columnGap: "5px",
|
columnGap: "5px",
|
||||||
templateAreas:
|
templateAreas:
|
||||||
'"grid-sidebar-left grid-header"\
|
'"grid-sidebar-left grid-page-header"\
|
||||||
"grid-sidebar-left grid-center"\
|
"grid-sidebar-left grid-center"\
|
||||||
"grid-sidebar-left grid-sidebar-right"\
|
"grid-sidebar-left grid-sidebar-right"\
|
||||||
"grid-sidebar-left grid-footer"',
|
"grid-sidebar-left grid-footer"',
|
||||||
@ -52,7 +52,7 @@ $desktopGrid: (
|
|||||||
rowGap: "5px",
|
rowGap: "5px",
|
||||||
columnGap: "5px",
|
columnGap: "5px",
|
||||||
templateAreas:
|
templateAreas:
|
||||||
'"grid-sidebar-left grid-header grid-sidebar-right"\
|
'"grid-sidebar-left grid-page-header grid-sidebar-right"\
|
||||||
"grid-sidebar-left grid-center grid-sidebar-right"\
|
"grid-sidebar-left grid-center grid-sidebar-right"\
|
||||||
"grid-sidebar-left grid-footer grid-sidebar-right"',
|
"grid-sidebar-left grid-footer grid-sidebar-right"',
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user