A renderer for Saga that uses Swim to turn a RenderingContext into a String.
It comes with a free function named swim which takes a function that goes from RenderingContext to Node, and turns it into a function that goes from RenderingContext to String, which can then be plugged into Saga’s writers — which take functions of signature (RenderingContext) -> String.
import Saga
import SagaParsleyMarkdownReader
import SagaSwimRenderer
@main
struct Run {
static func main() async throws {
try await Saga(input: "content", output: "deploy", siteMetadata: siteMetadata)
.register(
metadata: EmptyMetadata.self,
readers: [.parsleyMarkdownReader()],
itemWriteMode: .keepAsFile,
writers: [
.itemWriter(swim(renderItem))
]
)
// Run the steps we registered above
.run()
// All the remaining files that were not parsed to markdown, so for example images, raw html files and css,
// are copied as-is to the output folder.
.staticFiles()
}
}
SagaSwimRenderer
A renderer for Saga that uses Swim to turn a RenderingContext into a String.
It comes with a free function named
swim
which takes a function that goes fromRenderingContext
toNode
, and turns it into a function that goes fromRenderingContext
toString
, which can then be plugged into Saga’s writers — which take functions of signature(RenderingContext) -> String
.Example
The best example is Saga’s Example project, although a simplified example app is included in this repo.
TLDR;
Package.swift
main.swift:
And your
renderItem
template: