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: ![x,y,width,height](file.svg)
|
// For svg with custom area: ![x,y,width,height](file.svg)
|
||||||
// For downloads: ![download](file1, text1; file2, text2, (download-name); ...)
|
// For downloads: ![download](file1, text1; file2, text2, (download-name); ...)
|
||||||
// For a simple box: ![box](title;body)
|
// For a simple box: ![box](title;body)
|
||||||
|
// For 3D models: ![3d](file;Description)
|
||||||
// A fancy page link: ![page](page_id)
|
// A fancy page link: ![page](page_id)
|
||||||
// External pages: ![external](url1, text1; url2, text2, ...)
|
// External pages: ![external](url1, text1; url2, text2, ...)
|
||||||
guard let fileAndTitle = markdown.between(first: "](", andLast: ")").removingPercentEncoding else {
|
guard let fileAndTitle = markdown.between(first: "](", andLast: ")").removingPercentEncoding else {
|
||||||
@ -147,6 +148,8 @@ struct PageContentGenerator {
|
|||||||
return handleSimpleBox(page: page, content: content)
|
return handleSimpleBox(page: page, content: content)
|
||||||
case .pageLink:
|
case .pageLink:
|
||||||
return handlePageLink(page: page, language: language, pageId: content)
|
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.
|
// We assume that the thumbnail images are already required by overview pages.
|
||||||
return factory.pageLink.generate(content)
|
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.
|
A pretty link to another page on the site.
|
||||||
*/
|
*/
|
||||||
case pageLink = "page"
|
case pageLink = "page"
|
||||||
|
|
||||||
|
/**
|
||||||
|
A 3D model to display
|
||||||
|
*/
|
||||||
|
case model3d = "3d"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user