Jacky Zhao
2024-02-17 aa24a62ae77ed1bd3edd4b617cd76d7a056c7f1c
fix(breadcrumbs): calculate trailing slash for tag hierarchies (closes #873)
1 files modified
15 ■■■■ changed files
quartz/components/Breadcrumbs.tsx 15 ●●●● patch | view | raw | blame | history
quartz/components/Breadcrumbs.tsx
@@ -1,6 +1,6 @@
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
import breadcrumbsStyle from "./styles/breadcrumbs.scss"
import { FullSlug, SimpleSlug, resolveRelative } from "../util/path"
import { FullSlug, SimpleSlug, joinSegments, resolveRelative } from "../util/path"
import { QuartzPluginData } from "../plugins/vfile"
import { classNames } from "../util/lang"
@@ -82,8 +82,12 @@
    // Split slug into hierarchy/parts
    const slugParts = fileData.slug?.split("/")
    if (slugParts) {
      // is tag breadcrumb?
      const isTagPath = slugParts[0] === "tags"
      // full path until current part
      let currentPath = ""
      for (let i = 0; i < slugParts.length - 1; i++) {
        let curPathSegment = slugParts[i]
@@ -97,10 +101,15 @@
        }
        // Add current slug to full path
        currentPath += slugParts[i] + "/"
        currentPath = joinSegments(currentPath, slugParts[i])
        const includeTrailingSlash = !isTagPath || i < 1
        // Format and add current crumb
        const crumb = formatCrumb(curPathSegment, fileData.slug!, currentPath as SimpleSlug)
        const crumb = formatCrumb(
          curPathSegment,
          fileData.slug!,
          (currentPath + (includeTrailingSlash ? "/" : "")) as SimpleSlug,
        )
        crumbs.push(crumb)
      }