From 1d97560c40516062321f55887b06ae5aea29bc1a Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 16 Dec 2023 10:55:36 +0100 Subject: [PATCH] Add 3d model short command --- .../Generators/PageContentGenerator.swift | 25 +++++++++++++++++++ .../Generators/ShorthandMarkdownKey.swift | 5 ++++ 2 files changed, 30 insertions(+) diff --git a/Sources/Generator/Generators/PageContentGenerator.swift b/Sources/Generator/Generators/PageContentGenerator.swift index ba8b825..82dc891 100644 --- a/Sources/Generator/Generators/PageContentGenerator.swift +++ b/Sources/Generator/Generators/PageContentGenerator.swift @@ -104,6 +104,7 @@ struct PageContentGenerator { // For svg with custom area: ![x,y,width,height](file.svg) // For downloads: ![download](file1, text1; file2, text2, (download-name); ...) // For a simple box: ![box](title;body) + // For 3D models: ![3d](file;Description) // A fancy page link: ![page](page_id) // External pages: ![external](url1, text1; url2, text2, ...) guard let fileAndTitle = markdown.between(first: "](", andLast: ")").removingPercentEncoding else { @@ -147,6 +148,8 @@ struct PageContentGenerator { return handleSimpleBox(page: page, content: content) case .pageLink: return handlePageLink(page: page, language: language, pageId: content) + case .model3d: + return handle3dModel(page: page, content: content) } } @@ -399,4 +402,26 @@ struct PageContentGenerator { // We assume that the thumbnail images are already required by overview pages. return factory.pageLink.generate(content) } + + private func handle3dModel(page: Element, content: String) -> String { + let parts = content.components(separatedBy: ";") + guard parts.count > 1 else { + results.warning("Invalid 3d model specification", source: page.path) + return "" + } + let file = parts[0] + guard file.hasSuffix(".glb") else { + results.warning("Invalid 3d model file \(file) (must be .glb)", source: page.path) + return "" + } + + // Ensure that file is available + let filePath = page.pathRelativeToRootForContainedInputFile(file) + results.require(file: filePath, source: page.path) + + let description = parts.dropFirst().joined(separator: ";") + return """ + + """ + } } diff --git a/Sources/Generator/Generators/ShorthandMarkdownKey.swift b/Sources/Generator/Generators/ShorthandMarkdownKey.swift index 349ca68..a947bf0 100644 --- a/Sources/Generator/Generators/ShorthandMarkdownKey.swift +++ b/Sources/Generator/Generators/ShorthandMarkdownKey.swift @@ -26,4 +26,9 @@ enum ShorthandMarkdownKey: String { A pretty link to another page on the site. */ case pageLink = "page" + + /** + A 3D model to display + */ + case model3d = "3d" }