From 66b948ed7ef7c407849e8d9e9dd53baab133ee30 Mon Sep 17 00:00:00 2001 From: Vithanco Date: Wed, 19 Jul 2023 05:55:03 +0200 Subject: [PATCH] first version --- .../Publish_TableOfContent/Breadcrumbs.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Sources/Publish_TableOfContent/Breadcrumbs.swift diff --git a/Sources/Publish_TableOfContent/Breadcrumbs.swift b/Sources/Publish_TableOfContent/Breadcrumbs.swift new file mode 100644 index 0000000..0e2c313 --- /dev/null +++ b/Sources/Publish_TableOfContent/Breadcrumbs.swift @@ -0,0 +1,36 @@ +// +// Breadcrumps.swift +// +// +// Created by Klaus Kneupner on 19/07/2023. +// + +import Foundation +import Publish +import Plot + + +public struct Breadcrumps: 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, 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) + } +}