From a8001e9554a319782d8557acb8f19358996b5828 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Mon, 10 Mar 2025 15:13:04 -0700 Subject: [PATCH] feat: support non-singleton explorer --- quartz/build.ts | 11 +- quartz/components/Backlinks.tsx | 7 +- quartz/components/Explorer.tsx | 16 +-- quartz/components/OverflowList.tsx | 19 ++- quartz/components/TableOfContents.tsx | 133 +++++++++--------- quartz/components/pages/FolderContent.tsx | 3 +- quartz/components/pages/TagContent.tsx | 3 +- quartz/components/scripts/explorer.inline.ts | 46 +++--- quartz/components/styles/explorer.scss | 26 ++-- quartz/components/styles/toc.scss | 1 + quartz/components/types.ts | 8 +- quartz/plugins/emitters/componentResources.ts | 22 +-- quartz/styles/base.scss | 9 +- quartz/util/random.ts | 3 + quartz/util/resources.tsx | 7 + 15 files changed, 168 insertions(+), 146 deletions(-) create mode 100644 quartz/util/random.ts diff --git a/quartz/build.ts b/quartz/build.ts index 64c462b..81558f9 100644 --- a/quartz/build.ts +++ b/quartz/build.ts @@ -19,6 +19,7 @@ import { options } from "./util/sourcemap" import { Mutex } from "async-mutex" import DepGraph from "./depgraph" import { getStaticResourcesFromPlugins } from "./plugins" +import { randomIdNonSecure } from "./util/random" type Dependencies = Record | null> @@ -38,13 +39,9 @@ type BuildData = { type FileEvent = "add" | "change" | "delete" -function newBuildId() { - return Math.random().toString(36).substring(2, 8) -} - async function buildQuartz(argv: Argv, mut: Mutex, clientRefresh: () => void) { const ctx: BuildCtx = { - buildId: newBuildId(), + buildId: randomIdNonSecure(), argv, cfg, allSlugs: [], @@ -162,7 +159,7 @@ async function partialRebuildFromEntrypoint( return } - const buildId = newBuildId() + const buildId = randomIdNonSecure() ctx.buildId = buildId buildData.lastBuildMs = new Date().getTime() const release = await mut.acquire() @@ -359,7 +356,7 @@ async function rebuildFromEntrypoint( toRemove.add(filePath) } - const buildId = newBuildId() + const buildId = randomIdNonSecure() ctx.buildId = buildId buildData.lastBuildMs = new Date().getTime() const release = await mut.acquire() diff --git a/quartz/components/Backlinks.tsx b/quartz/components/Backlinks.tsx index 735afe7..0d34457 100644 --- a/quartz/components/Backlinks.tsx +++ b/quartz/components/Backlinks.tsx @@ -3,7 +3,7 @@ import style from "./styles/backlinks.scss" import { resolveRelative, simplifySlug } from "../util/path" import { i18n } from "../i18n" import { classNames } from "../util/lang" -import OverflowList from "./OverflowList" +import OverflowListFactory from "./OverflowList" interface BacklinksOptions { hideWhenEmpty: boolean @@ -15,6 +15,7 @@ const defaultOptions: BacklinksOptions = { export default ((opts?: Partial) => { const options: BacklinksOptions = { ...defaultOptions, ...opts } + const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory() const Backlinks: QuartzComponent = ({ fileData, @@ -30,7 +31,7 @@ export default ((opts?: Partial) => { return (

{i18n(cfg.locale).components.backlinks.title}

- + {backlinkFiles.length > 0 ? ( backlinkFiles.map((f) => (
  • @@ -48,7 +49,7 @@ export default ((opts?: Partial) => { } Backlinks.css = style - Backlinks.afterDOMLoaded = OverflowList.afterDOMLoaded("backlinks-ul") + Backlinks.afterDOMLoaded = overflowListAfterDOMLoaded return Backlinks }) satisfies QuartzComponentConstructor diff --git a/quartz/components/Explorer.tsx b/quartz/components/Explorer.tsx index 9c6319a..56784f1 100644 --- a/quartz/components/Explorer.tsx +++ b/quartz/components/Explorer.tsx @@ -6,7 +6,8 @@ import script from "./scripts/explorer.inline" import { classNames } from "../util/lang" import { i18n } from "../i18n" import { FileTrieNode } from "../util/fileTrie" -import OverflowList from "./OverflowList" +import OverflowListFactory from "./OverflowList" +import { concatenateResources } from "../util/resources" type OrderEntries = "sort" | "filter" | "map" @@ -56,6 +57,7 @@ export type FolderState = { export default ((userOpts?: Partial) => { const opts: Options = { ...defaultOptions, ...userOpts } + const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory() const Explorer: QuartzComponent = ({ cfg, displayClass }: QuartzComponentProps) => { return ( @@ -73,8 +75,7 @@ export default ((userOpts?: Partial) => { > -
    - +
    +