Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tokamakui/tokamakpublish
Use Tokamak in your Publish themes.
https://github.com/tokamakui/tokamakpublish
publish static-site static-site-generator swiftui
Last synced: about 2 months ago
JSON representation
Use Tokamak in your Publish themes.
- Host: GitHub
- URL: https://github.com/tokamakui/tokamakpublish
- Owner: TokamakUI
- License: apache-2.0
- Created: 2020-11-01T00:29:29.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-09T08:29:27.000Z (about 3 years ago)
- Last Synced: 2023-03-04T17:03:08.632Z (almost 2 years ago)
- Topics: publish, static-site, static-site-generator, swiftui
- Language: Swift
- Homepage:
- Size: 23.4 KB
- Stars: 21
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# TokamakPublish
Use Tokamak in your themes for [the Publish static generator](https://github.com/johnsundell/Publish).
You can either write your entire theme with Tokamak, or integrate it with your existing `Plot` HTML.
A Tokamak implementation of the `.foundation` theme is provided under the name `.tokamakFoundation`.
## `TokamakHTMLFactory`
To make your own Tokamak theme, conform to the `TokamakHTMLFactory` protocol. That requires the following functions:
```swift
struct MyThemeFactory: TokamakHTMLFactory {
func makeIndexView(for index: Index, context: PublishingContext) throws -> IndexView
func makeSectionView(
for section: Publish.Section,
context: PublishingContext
) throws -> SectionView
func makeItemView(for item: Item, context: PublishingContext) throws -> ItemView
func makePageView(for page: Page, context: PublishingContext) throws -> PageView
func makeTagListView(for page: TagListPage, context: PublishingContext) throws -> TagListView
func makeTagDetailsView(for page: TagDetailsPage, context: PublishingContext) throws -> TagDetailsView
}
```In these functions, you can build a `View` with SwiftUI-compatible syntax:
```swift
struct MyThemeFactory: TokamakHTMLFactory {
func makePageView(for page: Page, context: PublishingContext) 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)
}
...
}
```## Plot integration
You can include Tokamak views in your Plot HTML with the `view` Node:
```swift
let myHTML = Plot.HTML(
.body(
.h1(.text("My Website")),
.view {
Text("This is a Tokamak ") + Text("View")
.font(.system(.body, design: .monospaced))
},
.view(MyTokamakView())
)
)
```You can include Plot nodes in your Tokamak views just as easily:
```swift
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"))
)
}
}
```