Skip to content

Commit

Permalink
fix(breadcrumbs): calculate trailing slash for tag hierarchies (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 authored and qazxcdswe123 committed Apr 18, 2024
1 parent ea45c4d commit 1ec4b0d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions quartz/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -82,8 +82,12 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
// 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]

Expand All @@ -97,10 +101,15 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
}

// 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)
}

Expand Down

0 comments on commit 1ec4b0d

Please sign in to comment.