From fdd4c0e4d92bebeae0dd6bd258b2f2164646b955 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 23 Sep 2022 09:22:00 +0200 Subject: [PATCH] Find element by id --- Sources/Generator/Content/Element.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/Generator/Content/Element.swift b/Sources/Generator/Content/Element.swift index 03ac19a..4af296e 100644 --- a/Sources/Generator/Content/Element.swift +++ b/Sources/Generator/Content/Element.swift @@ -594,3 +594,21 @@ extension Element { } } } + +extension Element { + + /** + Find a page by its page ID within the tree of the element. + */ + func find(_ pageId: String) -> Element? { + if self.id == pageId { + return self + } + for child in elements { + if let found = child.find(pageId) { + return found + } + } + return nil + } +}