From 54a4d6dbc378c39707d0fe8a509b7cca584db2a2 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 16 Dec 2023 22:10:50 +0100 Subject: [PATCH] Detect duplicate ids --- Sources/Generator/Content/Element.swift | 7 +++++-- Sources/Generator/run.swift | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/Generator/Content/Element.swift b/Sources/Generator/Content/Element.swift index 7314dab..92b4bfe 100644 --- a/Sources/Generator/Content/Element.swift +++ b/Sources/Generator/Content/Element.swift @@ -319,7 +319,7 @@ struct Element { } } - func getExternalPageMap(language: String) -> [String : String] { + func getExternalPageMap(language: String, log: MetadataInfoLogger) -> [String : String] { var result = [String : String]() if let ext = getExternalLink(for: language) { result[id] = ext @@ -327,7 +327,10 @@ struct Element { result[id] = path + Element.htmlPagePathAddition(for: language) } elements.forEach { element in - element.getExternalPageMap(language: language).forEach { key, value in + element.getExternalPageMap(language: language, log: log).forEach { key, value in + if result[key] != nil { + log.error("Page id '\(key)' is used twice", source: value) + } result[key] = value } } diff --git a/Sources/Generator/run.swift b/Sources/Generator/run.swift index f413496..0f4bd23 100644 --- a/Sources/Generator/run.swift +++ b/Sources/Generator/run.swift @@ -53,7 +53,10 @@ private func loadSiteData(in folder: URL, runFolder: URL) throws -> (root: Eleme print(" Error: No site root loaded, aborting generation") return nil } - let pageMap = root.languages.map { (language: $0.language, pages: root.getExternalPageMap(language: $0.language)) } + let pageMap = root.languages.map { language in + (language: language.language, + pages: root.getExternalPageMap(language: language.language, log: log)) + } log.printMetadataScanOverview(languages: root.languages.count) return (root, pageMap) }