TokamakPublish
1.0.0
在主题中使用 Tokamak 来发布静态生成器。
您可以使用 Tokamak 编写整个主题,也可以将其与现有的Plot
HTML 集成。
.foundation
主题的托卡马克实现以.tokamakFoundation
名称提供。
TokamakHTMLFactory
要制作您自己的托卡马克主题,请遵守TokamakHTMLFactory
协议。这需要以下功能:
struct MyThemeFactory < Site : Website > : TokamakHTMLFactory {
func makeIndexView ( for index : Index , context : PublishingContext < Self . Site > ) throws -> IndexView
func makeSectionView (
for section : Publish . Section < Self . Site > ,
context : PublishingContext < Self . Site >
) throws -> SectionView
func makeItemView ( for item : Item < Self . Site > , context : PublishingContext < Self . Site > ) throws -> ItemView
func makePageView ( for page : Page , context : PublishingContext < Self . Site > ) throws -> PageView
func makeTagListView ( for page : TagListPage , context : PublishingContext < Self . Site > ) throws -> TagListView
func makeTagDetailsView ( for page : TagDetailsPage , context : PublishingContext < Self . Site > ) throws -> TagDetailsView
}
在这些函数中,您可以使用 SwiftUI 兼容语法构建View
:
struct MyThemeFactory < Site : Website > : TokamakHTMLFactory {
func makePageView ( for page : Page , context : PublishingContext < Self . Site > ) throws -> PageView {
Text ( " Welcome to my website " )
. font ( . largeTitle )
VStack ( alignment : . leading ) {
page . body
}
. frame ( idealWidth : 820 , maxWidth : 820 )
. padding ( . vertical , 40 )
Text ( " 2020 © Tokamak Contributors " )
. font ( . caption )
}
...
}
您可以使用view
节点将托卡马克视图包含在绘图 HTML 中:
let myHTML = Plot . HTML (
. body (
. h1 ( . text ( " My Website " ) ) ,
. view {
Text ( " This is a Tokamak " ) + Text ( " View " )
. font ( . system ( . body , design : . monospaced ) )
} ,
. view ( MyTokamakView ( ) )
)
)
您可以轻松地将绘图节点包含在托卡马克视图中:
struct ContentView : View {
var body : some View {
Text ( " My Website " )
. font ( . largeTitle )
Node . p (
. span ( " This is a Plot " ) ,
. span ( . text ( " Node " ) , . style ( " font-family: monospace " ) )
)
}
}