mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 19:46:23 +00:00
fix(breadcrumbs): calculate trailing slash for tag hierarchies (closes #873)
This commit is contained in:
parent
a6690c6503
commit
aa24a62ae7
1 changed files with 12 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
||||||
import breadcrumbsStyle from "./styles/breadcrumbs.scss"
|
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 { QuartzPluginData } from "../plugins/vfile"
|
||||||
import { classNames } from "../util/lang"
|
import { classNames } from "../util/lang"
|
||||||
|
|
||||||
|
@ -82,8 +82,12 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||||
// Split slug into hierarchy/parts
|
// Split slug into hierarchy/parts
|
||||||
const slugParts = fileData.slug?.split("/")
|
const slugParts = fileData.slug?.split("/")
|
||||||
if (slugParts) {
|
if (slugParts) {
|
||||||
|
// is tag breadcrumb?
|
||||||
|
const isTagPath = slugParts[0] === "tags"
|
||||||
|
|
||||||
// full path until current part
|
// full path until current part
|
||||||
let currentPath = ""
|
let currentPath = ""
|
||||||
|
|
||||||
for (let i = 0; i < slugParts.length - 1; i++) {
|
for (let i = 0; i < slugParts.length - 1; i++) {
|
||||||
let curPathSegment = slugParts[i]
|
let curPathSegment = slugParts[i]
|
||||||
|
|
||||||
|
@ -97,10 +101,15 @@ export default ((opts?: Partial<BreadcrumbOptions>) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add current slug to full path
|
// Add current slug to full path
|
||||||
currentPath += slugParts[i] + "/"
|
currentPath = joinSegments(currentPath, slugParts[i])
|
||||||
|
const includeTrailingSlash = !isTagPath || i < 1
|
||||||
|
|
||||||
// Format and add current crumb
|
// 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)
|
crumbs.push(crumb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue