-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Breadcrumps.swift | ||
// | ||
// | ||
// Created by Klaus Kneupner on 19/07/2023. | ||
// | ||
|
||
import Foundation | ||
import Publish | ||
import Plot | ||
|
||
|
||
public struct Breadcrumps<Site: Website>: Component where Site.ItemMetadata : HasShortTitle { | ||
var originalPath: Path | ||
var _body: ComponentGroup | ||
|
||
public var body: Component { | ||
// debugPrint("breadcrump for \(self.originalPath) : \(items.count)") | ||
return _body.members.count > 0 ? Div { | ||
_body | ||
}.class("breadcrumps") as Component | ||
: EmptyComponent() as Component | ||
} | ||
|
||
public init(section: Section<Site>, item: any TableOfContentEntry) { | ||
self.originalPath = item.path | ||
var converted = section.items | ||
.filter({return item.path.hasAncestor($0.path)}) | ||
.sorted(by: {return $0.path ~< $1.path}) | ||
.map({Link($0.title, url: $0.path.absoluteString).class("breadcrump")}) | ||
for i in stride (from: converted.count-1, through: 1, by: -1) { | ||
converted.insert(Image(url: "/images/socialmedia-icons/chevron.svg", description: "breadcrump separator"), at: i) | ||
} | ||
_body = ComponentGroup(members: converted) | ||
} | ||
} |