Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
Vithanco committed Jul 19, 2023
1 parent edaec48 commit 66b948e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Sources/Publish_TableOfContent/Breadcrumbs.swift
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)
}
}

0 comments on commit 66b948e

Please sign in to comment.