Add 3d model short command
This commit is contained in:
parent
81fa5c38de
commit
1d97560c40
@ -104,6 +104,7 @@ struct PageContentGenerator {
|
||||
// For svg with custom area: 
|
||||
// For downloads: ; ...)
|
||||
// For a simple box: 
|
||||
// For 3D models: 
|
||||
// A fancy page link: 
|
||||
// External pages: 
|
||||
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 """
|
||||
<model-viewer alt="\(description)" src="\(file)" ar shadow-intensity="1" camera-controls touch-action="pan-y"></model-viewer>
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user