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 " ) )
)
}
}